A Fingerprint Machine for Data
A hash function is a machine with one job: feed it any data (a password, a photo, a 4 GB movie) and it outputs a short, fixed-length string called a hash or digest. Feed it the same data again, and you get the identical hash, every time, on any computer. Change one bit of the input, and the hash changes completely and unpredictably.
SHA-256("hello") = 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824
SHA-256("hello!") = ce06092fb948d9ffac7d1a376e404b26b7575bcc11ee05a4615fef4fec3a308b
One added exclamation mark, and the two outputs share nothing. That's the "avalanche effect", and it's deliberate. Try it yourself with our free hash generator: type, watch the fingerprint change per keystroke.
The Three Properties That Make Hashing Useful
- One way: There is no "unhash". Given a hash, the only path back to the input is guessing inputs and comparing. For a strong function, that's the whole security model.
- Deterministic: Same input, same hash, forever. This is what makes hashes comparable across time and machines.
- Collision resistant: Finding two different inputs with the same hash should be computationally hopeless. SHA-256 has 2 to the 256th power possible outputs: more than atoms in the observable universe, squared for good measure.
Important distinction: hashing is not encryption (reversible with a key) and not encoding (reversible by anyone: see our Base64 guide for that one). Hashing is the only one of the three with no way back at all.
A Closer Look at the Avalanche Effect
The avalanche effect isn't a side benefit of hashing, it's a required property, and it's worth seeing at the bit level to understand why. Under the hood, SHA-256 processes input in blocks and repeatedly mixes bits together through rotations, XOR operations, and modular addition across 64 rounds. Because each round feeds its output into the next round's input, a single flipped bit near the start of the message gets copied, rotated, and combined with other bits so many times that by the final round, roughly half of the 256 output bits have flipped compared to the unmodified input, and there's no way to predict in advance which half.
Compare "hello" and "hello!" again: the inputs differ by exactly one character (one byte, eight bits) at the very end of the string, yet the two SHA-256 outputs shown above share no meaningful visual pattern at all, not even in early characters, even though intuitively you might expect the first several output characters to "start the same" since the first several input characters were identical. They don't, and that's the whole point: if hashes of similar inputs looked even slightly similar, an attacker could narrow down a search by testing near-misses and watching which one nudges the output closer to a target. Avalanche behaviour makes that entire strategy worthless, because there is no such thing as "closer."
Where Hashing Runs Your Life
1. Password Storage
Websites should never store your actual password. They store its hash. At login, they hash what you typed and compare hashes. A database thief gets fingerprints, not passwords, and must crack them by mass guessing: how fast that goes depends entirely on the algorithm (details in our brute force explainer).
Here's why hashing is the right tool for this job and encryption is the wrong one: encryption is designed to be reversed, by design, whenever someone holds the correct key. That means an encrypted password database is only as safe as that one key, and if the key is ever exposed (stolen from the same server, leaked in a config file, guessed), every password in the database instantly becomes readable plaintext again. But no legitimate system ever needs to see your original password again after you set it: it only ever needs to check "does this match," which is precisely what a one-way hash comparison does without ever storing anything reversible. There's no key to steal, because there's no lock, only a fingerprint scanner that can confirm a match without ever holding the original.
Password storage adds two crucial refinements on top of a bare hash:
- Salt: a random value mixed into each user's hash, so identical passwords hash differently and precomputed tables become useless.
- Slow hashing: bcrypt and Argon2 are deliberately expensive, turning "billions of guesses per second" into "thousands". Fast hashes like MD5 or plain SHA-256 are the wrong tool here: our SHA-256 vs MD5 comparison shows why this matters in breaches.
2. File and Download Verification
Software sites publish the SHA-256 of their installers. Hash your downloaded file, compare, and a single matching string proves the file is bit-for-bit intact: no tampering, no corruption. Git uses the same trick to identify every commit; backup tools use it to detect changed files.
3. Your 2FA Codes (Yes, Really)
Every six digit TOTP code is hashing at work. The algorithm: take your secret key and the current 30 second time window, run them through HMAC (a keyed variant of hashing: HMAC-SHA1 classically), and derive six digits from the result. Your phone and the server compute the same hash independently and compare: no code ever needs to travel in advance. See it live in our free TOTP generator, and the full mechanics in our TOTP explainer.
4. Blockchains, Dedup, and Hash Tables
Bitcoin's mining is a hash guessing contest; cloud storage dedupes identical files by hash; the hash table in every programming language uses cheap non-cryptographic hashes for instant lookups. Fingerprinting data turns out to be one of computing's most reusable ideas.
One mental model covers all of it: a hash lets two parties agree "we have the same data" without sending the data itself. Password checks, file verification, and TOTP codes are all that one sentence in different outfits.
Meet the Algorithms
| Algorithm | Output | Status | Proper use today |
|---|---|---|---|
| MD5 | 128 bit | Broken (collisions trivial) | Non-security checksums only |
| SHA-1 | 160 bit | Broken for collisions | Legacy compatibility (HMAC-SHA1 in TOTP remains OK) |
| SHA-256 | 256 bit | Strong | General purpose: files, signatures, certificates |
| SHA-512, SHA-3 | 512/variable | Strong | General purpose, newer designs |
| bcrypt, Argon2 | n/a | Strong | Passwords (deliberately slow, salted) |
Generate and compare MD5, SHA-1, SHA-256, and SHA-512 side by side in our hash generator: everything runs in your browser, nothing is uploaded.
Frequently Asked Questions
If hashes can't be reversed, how do sites check my password?
They re-run the machine: hash your login attempt with the same algorithm and salt, then compare the result to the stored hash. Matching outputs imply matching inputs. Your password itself is never compared, and ideally never stored anywhere in readable form.
Why does my whole file get the same size hash as one word?
Fixed output length is by design: SHA-256 always emits 256 bits regardless of input size. The hash is a fingerprint, not a container: it identifies data without holding it, which is also why reversal is impossible (infinitely many inputs share each output in principle, yet finding even one is computationally hopeless).
What is a collision, and should I worry?
Two different inputs producing the same hash. For MD5, researchers can manufacture collisions on demand, which is why it's retired from security work. For SHA-256, no collision has ever been found. Practical worry level: choose modern algorithms and it's zero.
Is hashing enough to store passwords safely?
Hashing with the right algorithm (Argon2 or bcrypt, salted) is the standard. But even perfect storage can't rescue a weak or reused password: cracking guesses "password123" instantly regardless of algorithm. Unique strong passwords (our generator) plus 2FA complete the picture.
Why does TOTP still use SHA-1 if SHA-1 is broken?
The break is about collisions (crafting two colliding documents), which doesn't apply to HMAC's keyed construction. HMAC-SHA1 remains cryptographically sound for TOTP, and the 30 second code lifetime shrinks the attack surface further. Newer deployments can use HMAC-SHA256, and the standard supports it.