MD5 is one of those algorithms every developer bumps into eventually. You'll see it in file checksums, cache keys, old database schemas, and the occasional legacy auth system that should have been retired years ago. It's fast, it's simple, and it's also been broken for the better part of two decades. Knowing the difference between a reasonable use and a dangerous one saves you a lot of grief.
What MD5 actually is
MD5 (Message-Digest Algorithm 5) is a cryptographic hash function that takes input of any length and produces a fixed 128-bit output, usually written as a 32-character hexadecimal string. The same input always produces the same hash. Change a single byte and the output looks completely different.
Here's what that looks like in practice:
md5("hello") = 5d41402abc4b2a76b9719d911017c592
md5("hello.") = 251364b961a83dd78b6d0a85ac66b76e
md5("") = d41d8cd98f00b204e9800998ecf8427e
Note that last one: the empty string has a hash too. A hash is always 32 hex characters regardless of whether you fed it one byte or a gigabyte.
Where MD5 is still fine
MD5 is broken for anything requiring collision resistance, but plenty of tasks don't need that. Treat it as a fast fingerprint, not a security primitive.
- Non-security checksums. Verifying a file downloaded intact against accidental corruption. If an attacker could tamper with the file, MD5 won't protect you — but for catching a flaky network transfer, it's fine.
- Cache keys and deduplication. Hashing a request URL or a normalized config blob to produce a stable key. Collisions are astronomically unlikely in random data, and the stakes are low if one happens.
- Change detection. Storing the MD5 of a record to quickly tell whether something changed without a full field-by-field comparison.
- Sharding and bucketing. Using a hash to distribute keys across partitions evenly.
For quick one-off checks — pasting a string and seeing what it hashes to — you can use our MD5 Hash Generator instead of spinning up a REPL. Handy when you're debugging why two systems disagree on a checksum.
Where MD5 will get you in trouble
Passwords
Never store passwords as MD5 hashes, salted or not. MD5 is designed to be fast, and fast is exactly wrong for password storage. An attacker with a modern GPU can try billions of MD5 guesses per second. Use a purpose-built password hash: bcrypt, scrypt, or Argon2. These are deliberately slow and memory-hard.
Anything an attacker can influence
MD5 is not collision resistant. Researchers have produced two different inputs with the same MD5 hash, and it's cheap to do now. If you use MD5 to sign, verify, or authenticate content that someone else can craft, assume they can forge a matching hash. This is why MD5 was removed from TLS certificates and code-signing years ago.
Treating a hash as encryption
Hashing is one-way. You can't "decrypt" an MD5. The so-called MD5 decrypters online are just lookup tables of precomputed hashes for common strings. If your string is password123, it'll be in those tables. If it's a 40-character random token, it won't.
A short worked example
Say you're building a simple cache and want a stable key from a request. Here's how you'd do it in a few languages.
Node.js:
const crypto = require('crypto');
function cacheKey(url) {
return crypto.createHash('md5').update(url).digest('hex');
}
cacheKey('https://api.example.com/users?page=2');
// => '3c6c...'
Python:
import hashlib
def cache_key(url: str) -> str:
return hashlib.md5(url.encode('utf-8')).hexdigest()
cache_key('https://api.example.com/users?page=2')
PHP:
$key = md5('https://api.example.com/users?page=2');
Three things worth noticing here. First, encoding matters: in Python you must encode the string to bytes before hashing, and the choice of encoding changes the result. UTF-8 and UTF-16 of the same text produce different hashes. Second, if the URL's query parameters can arrive in different orders (?a=1&b=2 vs ?b=2&a=1), normalize them first or you'll get cache misses for identical requests. Third, this is a non-security use, which is exactly why MD5 is acceptable here.
Common gotchas
- Encoding mismatches. The number one cause of "why don't these hashes match?" is two systems encoding the input differently — trailing whitespace, line endings (
\nvs\r\n), or BOM markers. Normalize before you hash. - Uppercase vs lowercase hex. Most libraries output lowercase, but some output uppercase. Compare case-insensitively or normalize.
- Hashing the wrong thing. On files, make sure you're hashing raw bytes, not a decoded-then-reencoded version. Reading a binary as text can silently corrupt it.
- FIPS mode. Some locked-down environments disable MD5 entirely at the crypto-library level. Your code will throw at runtime, not compile time. Worth knowing before you ship to a regulated environment.
- Assuming uniqueness. MD5 collisions are rare for random data but trivially forgeable by an attacker. Don't build a uniqueness constraint on MD5 if hostile input is possible.
The one-line decision
Ask yourself a single question: does a bad actor benefit from producing a collision or reversing this hash? If yes, MD5 is the wrong tool — reach for SHA-256 for integrity, HMAC for authentication, or Argon2 for passwords. If no, MD5 is a perfectly reasonable, fast fingerprint that'll serve you well.
MD5 isn't evil. It's just old, fast, and frequently pointed at problems it was never meant to solve. Use it where speed and simplicity matter and security doesn't, and you'll never be bitten by it.
Photo by Chris Ried on Unsplash