What a hash guarantees — and what it does not
A cryptographic hash maps any input to a fixed-size fingerprint. The properties that matter:
- Deterministic: same input, same output, always.
- Avalanche effect: change one bit of input and roughly half the output bits flip.
- Pre-image resistance: you cannot reconstruct the input from the hash.
- Collision resistance: you cannot find two different inputs with the same hash.
A hash is not encryption — there is no key and no way back to the original. And it is not unique: since outputs are fixed-size, collisions must exist; security means they are infeasible to find.
Why MD5 fell
MD5 produces a 128-bit hash. Already in 1996 researchers found weaknesses in its compression function, and by 2004 real collisions could be computed in under a minute on a laptop. Today you can generate two different files with the same MD5 hash in seconds — which means an attacker can craft a malicious file that passes an MD5 integrity check, or two different software packages that share one signature.
SHA-1 followed the same arc more slowly: theoretical breaks in 2005, a practical collision ("SHAttered") in 2017, and free SHA-1 collision services today. Browsers and certificate authorities dropped it; any new design using SHA-1 for security is a bug.
The decision table
| Use case | Right choice | Why |
|---|---|---|
| File checksum against accidental corruption | MD5 or CRC, SHA-256 fine | Accidental corruption does not attack the hash; speed matters |
| File integrity against an adversary | SHA-256 | MD5 collisions are trivial to forge |
| Password storage | bcrypt / scrypt / Argon2 | Any plain hash — even SHA-256 — is far too fast to brute-force |
| Signing / HMAC | SHA-256 or stronger | Signature security rides on the hash's collision resistance |
| Cache keys, content addressing | SHA-256 (MD5 acceptable internally) | Collisions cause wrong-data bugs, not just security issues |
| Git commits | SHA-1 (migrating to SHA-256) | Historical choice; Git is transitioning for exactly this reason |
The password storage exception
The most common real-world mistake: hashing passwords with SHA-256. Even a slow-to-crack-looking password falls fast, because GPUs test billions of SHA-256 candidates per second, and the attacker has the hash file and all the time in the world.
Password hashing needs algorithms that are deliberately slow and salted: bcrypt, scrypt, or Argon2 (the current recommendation). They take a normal hash and run it thousands of times with a unique salt per user, turning one guess per second into millions of guesses per second — per attempt. Hashing is a data-integrity tool; password storage is a cost-manipulation problem. Different problem, different tool.
Checksums: the one place MD5 survives
If your goal is detecting a corrupted download — a flipped bit on the wire, a truncated file — MD5 remains perfectly adequate, because random corruption essentially never produces a hash collision. Plenty of projects still publish MD5 sums for this. The danger is narrower than "MD5 is broken" suggests: it is specifically an adversary who can choose the files. If the publisher is trustworthy and the channel is not, MD5 detects accidents fine; if the publisher itself might be malicious, only SHA-256 helps.
Try it yourself
- Run
hellothrough the hash tool in all four algorithms — notice how different the outputs look despite identical input. - Add a single trailing space and hash again: every bit of every output changes. That is the avalanche effect.
- Check that SHA-256 of the empty string is the well-known constant
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855— a useful sanity test that an implementation is correct.