Two contracts look exactly the same. In one of them, a single digit has been changed. How could a computer tell them apart instantly, without comparing them word by word?
A fingerprint for data
A hash function takes any piece of data, whether a single word, a contract or an entire film, and turns it into a short value of fixed size. That value is called the hash, or sometimes the digest.
A fingerprint is a good way to think about it. A fingerprint is tiny compared with the person it belongs to, yet it’s a reliable way to tell people apart. A hash is a compact fingerprint for data in the same way. Because a hash is shorter than most inputs, different inputs can share one, but with SHA-256 it’s extremely hard to find two different inputs that do. A hash doesn’t keep the data secret, though: anyone who suspects what the input was can hash their guess and compare.
Unlike the methods you'll meet in the next lessons, a hash function uses no key. Anyone can compute the hash of anything, and everyone gets the same answer.
What a hash looks like
The most widely used hash function today is called SHA-256. Its hashes are always 256 bits long, written as 64 hexadecimal characters. Here's the hash of the word hello:
2cf24dba 5fb0a30e 26e83b2a c5b9e29e
1b161e5c 1fa7425e 73043362 938b9824
SHA-256 of “hello”
185f8db3 2271fe25 f561a6fc 938b2e26
4306ec30 4eda5180 07d17648 26381969
SHA-256 of “Hello”
Notice that capitalising one letter didn't change one character of the hash. It changed 61 of the 64. Each hexadecimal character stands for 4 bits, so a character only stays the same if all 4 of its bits happen to stay the same. When about half the bits change, almost every character does. There's no visible pattern linking the two hashes.
The four rules of a good hash
A cryptographic hash function has to follow four rules. Together, they're what make a hash useful as a fingerprint.
- Same in, same out. The same data always produces the same hash, on any computer, every time. That's what lets two people check they hold identical data.
- One way only. It's quick to compute a hash from data, but there's no way to work backwards from a hash to the data. The only option is to guess inputs and compare.
- Small change, big difference. Changing even one bit of the input changes, on average, about half of the bits in the hash, with no way to predict which ones. This is called the avalanche effect.
- No two alike. It must be practically impossible to find two different inputs with the same hash, even though such pairs must exist. Two inputs with the same hash are called a collision.
Try it: change one character
Both lines start the same, so their hashes match. Now change one character in Text B, for example $100 to $900, and watch its hash change. Your browser computes each SHA-256 hash as you type; nothing is sent or stored.
ab95d3cd12811726731fa05f8ee55d4ae3c113b0a1a4b5c0bcff14c4434af031
ab95d3cd12811726731fa05f8ee55d4ae3c113b0a1a4b5c0bcff14c4434af031
- Bits that differ between the two hashes
- Calculating…
- Hash length
- 256 bits, whatever you type
Each hash comes only from its own line: editing Text A never changes the hash of Text B. The highlighted characters compare the two hashes and mark where they differ, so the highlighting shifts in both boxes as you type. Make the two lines identical and the hashes match exactly.
Hashing is not encryption
People often mix the two up, but they do different jobs. Encryption scrambles data so it can be unscrambled again by someone who holds the right key. It's designed to be reversed. Hashing has no key and no way back. Its job isn't to hide data and reveal it later, but to give the data a fingerprint that anyone can check.
You'll meet encryption properly in lesson 1.3.
Where hashes are used
Hashes quietly hold much of digital security together. A few examples:
- Checking that nothing changed. Software publishers list the SHA-256 hash of each download. If your file’s hash matches one you obtained from the publisher through a trusted channel, you have strong evidence that you received the same bytes. The trusted channel matters: someone who can replace both the file and the published hash can make them match.
- Storing passwords. A well-built service never stores your password. It stores a random value called a salt, together with a password hash computed with a deliberately expensive function such as Argon2id. When you log in, it uses the stored salt and settings to hash what you typed and checks whether the result matches.
- Digital signatures and certificates. A digital signature binds a signing key to the exact data that was signed, and hash functions are built into how it works. Changing the data causes verification to fail with overwhelming probability. A certificate works the same way: the verifier checks the issuer’s signature over the certificate’s contents. You’ll see how signatures work in lesson 1.5, and certificates in Module 2.
When a hash function breaks
Hash functions are public methods, so experts around the world keep testing them, just as lesson 1.1 described. Sometimes they find a weakness. Two once-popular hash functions, MD5 and SHA-1, were broken this way: researchers learned how to create collisions, two different files with the same hash. For MD5 that happened in 2004, and for SHA-1 a practical collision was demonstrated in 2017.
Collisions don’t let anyone work backwards from a hash, but they do undermine trust in it: if two different documents share a hash, a signature on one could be passed off as a signature on the other. So MD5 and SHA-1 should be avoided in new designs, and their collision weaknesses make them unsuitable for creating digital signatures. Today’s systems use SHA-256 and its larger relatives in the SHA-2 family, or the newer SHA-3 family.
Go deeperOptional technical detail for readers who want more
How SHA-256 works, in outline
SHA-256 pads the input and splits it into blocks of 512 bits. It keeps a 256-bit internal state, and for each block it runs 64 rounds of simple operations (additions, bit rotations and logical functions) that mix the block into the state. After the last block, the state is the hash. Each round spreads every input bit's influence further, which is where the avalanche effect comes from. The full specification is in FIPS 180-4.
Why collisions are harder to prevent than you'd think
Finding an input that matches one specific 256-bit hash would take about 2256 guesses. Finding any two inputs that collide takes far fewer, about 2128, because of the birthday paradox: in a room of just 23 people, there's already a better-than-even chance that two share a birthday. That's why a hash's collision strength is rated at half its length. For SHA-256, 2128 is still far beyond reach, as lesson 1.1 showed for 128-bit keys.
Why passwords need salt and expensive hashing
SHA-256 is designed to be fast, so an attacker with stolen password hashes could try billions of guesses a second against them. The salt makes every user’s hash different even when two people pick the same password, so attackers can’t use precomputed tables or crack many accounts at once. The expensive function makes each guess slow. Argon2id and scrypt are designed to need substantial memory as well as time, which makes large-scale guessing on specialised hardware costly. PBKDF2 mainly adds computation by repeating a hash many times, and bcrypt uses a small, fixed amount of memory. The cost settings are stored with the hash, so they can be raised over time.
Try it yourself
On macOS or Linux, either of these commands prints the SHA-256 hash of the word hello:
$ printf 'hello' | shasum -a 256 $ printf 'hello' | openssl dgst -sha256
Both should print 2cf24dba…938b9824. Note that echo hello would add an invisible line break, and that gives a different hash.
Sources
Draft lesson, awaiting technical review · Last updated 19 November 2026