MD5 has a reputation problem. Say the word in a code review and someone will reflexively tell you it's "broken." They're right — and also missing the point. MD5 is a tool with a narrow set of jobs it still does well, and a much larger set it should never touch. The trick is knowing which is which.
What MD5 actually is
MD5 (Message Digest 5) is a hash function designed by Ron Rivest in 1991. Feed it any input — a string, a file, a byte stream — and it spits out a fixed 128-bit value, almost always written as a 32-character hexadecimal string. The same input always produces the same output. Change a single bit and the output looks completely different.
Here's the classic demonstration:
md5("hello") = 5d41402abc4b2a76b9719d911017c592
md5("hellp") = 6c7dd79f1da61765b9c47ee74c8d9a1cOne character changed, and the digest shares nothing in common with the original. That property — small input changes causing wholesale output changes — is called the avalanche effect, and it's what makes hashes useful for comparing things quickly.
Why MD5 is considered broken
A good cryptographic hash needs to be collision resistant: it should be computationally infeasible to find two different inputs that produce the same digest. MD5 fails this spectacularly. Collisions were demonstrated back in 2004, and today you can generate them on a laptop in seconds. Researchers have produced two different PDFs, two different executables, even two different TLS certificates with identical MD5 digests.
This is why using MD5 for anything security-sensitive is a mistake. If an attacker can craft two files with the same hash, then "the hashes match so the file is untampered" stops being a valid argument.
Never use MD5 for:
- Password storage. Use bcrypt, scrypt, or Argon2. MD5 is fast, which is exactly wrong for passwords — fast means an attacker can brute-force billions of guesses per second.
- Digital signatures or certificates. Collision attacks make these forgeable.
- Verifying downloads against a malicious adversary. If someone can tamper with the file, they can match the hash. Use SHA-256 here.
- Deduplication where collisions would be a security problem. If two "different" files colliding could be exploited, MD5 won't protect you.
Where MD5 is still perfectly fine
The collision weakness only matters when there's an adversary deliberately crafting inputs. For non-adversarial use, accidental collisions are astronomically unlikely, and MD5's speed and short output are genuinely handy.
- Cache keys and ETags. Hashing a request's parameters into a short, stable key is a textbook use. Nobody's attacking your cache.
- Detecting accidental file changes. Checking whether a config file changed between deploys, or whether an upload matches what you expect from a trusted source.
- Content-addressable lookups. Using a digest as a map key or dedup fingerprint for internal data.
- Quick integrity checks during transfers where you only care about corruption, not malice — think a flaky network link rather than a hostile man-in-the-middle.
- Checksums for testing. Comparing expected vs. actual output in a test suite.
In all of these, you're asking "did this change by accident?" not "did someone maliciously tamper with this?" That distinction is everything.
A short worked example
Say you're building a simple cache and you want a compact key from a URL plus some query options. Here it is in Node.js:
const crypto = require('crypto');
function cacheKey(url, options) {
const payload = url + JSON.stringify(options);
return crypto.createHash('md5').update(payload).digest('hex');
}
cacheKey('/api/users', { page: 2, sort: 'name' });
// => '3f1a9c0b...' (a stable 32-char key)And in Python:
import hashlib
def cache_key(url, options):
payload = f"{url}{options}".encode("utf-8")
return hashlib.md5(payload).hexdigest()Same input, same key, every time. If you just want to eyeball a digest or confirm your code is producing the right value, you can paste a string into our MD5 Hash Generator and compare — handy when you're debugging why a cache key isn't matching what you expect.
Common gotchas
Encoding matters
MD5 operates on bytes, not characters. If one system hashes a UTF-8 string and another hashes UTF-16, you'll get different digests for the "same" text. Always be explicit about encoding. The most common source of "the hashes don't match and I don't know why" bugs is a silent encoding mismatch.
Line endings and whitespace
When hashing files, a trailing newline or a Windows CRLF vs. Unix LF will change the digest. If you're comparing a hash generated on one platform against another, normalise line endings first or you'll chase ghosts.
Uppercase vs. lowercase hex
Some libraries emit uppercase hex, others lowercase. The underlying value is identical, but a naive string comparison will fail. Lowercase everything before comparing.
Don't salt and call it secure
Adding a salt to an MD5 password hash does not make it safe. The algorithm is still too fast and the collisions still exist. If you ever find MD5 in an authentication path, it needs replacing, not patching.
The bottom line
MD5 is a fast, compact, deterministic fingerprint function. Treat it like a checksum, not a security primitive. For cache keys, dedup fingerprints, and accidental-corruption checks, it's a reasonable choice that's been battle-tested for decades. For anything involving a motivated attacker — passwords, signatures, integrity against tampering — reach for SHA-256 or a dedicated password hash and don't look back.
Know the difference and MD5 stays a useful tool in the box instead of a liability waiting to show up in a security audit.
Photo by Florian Olivo on Unsplash