MD5 has been around since 1991 and it refuses to die. You'll find it in file checksums, cache keys, Git internals' cousins, database fingerprints, and a depressing amount of old authentication code. It's fast, it's simple, and it produces a tidy 128-bit output. It's also broken for anything security-related. Knowing which of those facts applies to your situation is the whole game.

What MD5 actually is

MD5 (Message-Digest Algorithm 5) is a cryptographic hash function. You feed it any amount of data and it spits out a fixed 128-bit value, usually shown as 32 hexadecimal characters. The same input always produces the same output, and even a one-byte change produces a completely different digest.

echo -n "hello" | md5sum
5d41402abc4b2a76b9719d911017c592  -

echo -n "hellp" | md5sum
6d7b3f9e4d8a... (completely different)

That "same input, same output" property is what makes it useful as a fingerprint. The problem is the "cryptographic" part — MD5 no longer delivers on the guarantees you'd want from a cryptographic hash.

Why MD5 is broken (and what that means)

A good cryptographic hash should be collision resistant: it should be computationally infeasible to find two different inputs that produce the same digest. MD5 fails this. Collisions were demonstrated back in 2004, and today you can generate them on a laptop. Researchers have built colliding PDF files, X.509 certificates, and executables.

What this means in practice:

  • Never use MD5 for digital signatures or certificates. An attacker can craft a benign document and a malicious one with the same hash.
  • Never use MD5 for password storage. It's fast, which is exactly the wrong property — attackers can try billions of guesses per second. Use bcrypt, scrypt, or Argon2.
  • Don't rely on MD5 to prove a file hasn't been tampered with by an adversary. It can detect accidental corruption, not deliberate forgery.

Where MD5 is still perfectly fine

Collision attacks require an attacker who controls the input. For a lot of everyday engineering work, there is no adversary — you just need a cheap, stable fingerprint. In those cases MD5 is fast and good enough.

  • Cache keys. Hashing a normalized request or a set of parameters into a short, deterministic key is a classic use. If someone forces a collision, the worst case is a cache miss or a slightly wrong cache hit in a non-security context.
  • Detecting accidental file corruption. Verifying that a download wasn't mangled in transit, where the source is trusted, is a reasonable fit (though SHA-256 is the modern default for published checksums).
  • Deduplication and change detection. Figuring out whether a blob of content changed between two runs. Hashing it and comparing digests is quick and easy.
  • Sharding and bucketing. Spreading keys evenly across partitions, where distribution matters and security doesn't.

The rule of thumb: if the question is "did this change by accident?" MD5 is fine. If the question is "could someone malicious have tampered with this?" reach for SHA-256 or better.

A short worked example

Say you're building a response cache and want a compact key from a URL plus some query parameters. You sort the params so the key is stable regardless of input order, then hash.

import hashlib

def cache_key(url, params):
    # sort so {a:1, b:2} and {b:2, a:1} produce the same key
    normalized = "&".join(f"{k}={v}" for k, v in sorted(params.items()))
    raw = f"{url}?{normalized}"
    return hashlib.md5(raw.encode("utf-8")).hexdigest()

print(cache_key("/api/users", {"page": 2, "sort": "name"}))
# 32-char hex string, deterministic every time

In Node.js the equivalent is just as short:

const crypto = require("crypto");

function cacheKey(raw) {
  return crypto.createHash("md5").update(raw).digest("hex");
}

When I'm debugging this kind of thing and want to confirm a value by hand, I'll drop a string into an MD5 Hash Generator and compare it against what my code produced. It's a quick sanity check that saves you from chasing an encoding bug that isn't there.

Common gotchas

Encoding mismatches

The hash is computed over bytes, not characters. If one system hashes UTF-8 and another hashes UTF-16 or Latin-1, you'll get different digests for the same visible string. Always be explicit about encoding — raw.encode("utf-8") in Python, Buffer.from(str, "utf8") in Node. Non-ASCII characters are where this usually surfaces.

Trailing whitespace and newlines

A classic one: echo "hello" adds a newline, so its MD5 differs from echo -n "hello". If your hashes don't match across tools, check for an invisible trailing \n before assuming anything deeper is wrong.

Uppercase vs lowercase hex

Most libraries output lowercase hex, but some output uppercase. If you're comparing digests as strings, normalize the case or compare case-insensitively. This bites people doing string equality on hashes from two different sources.

Treating speed as a feature for passwords

Worth repeating because it still happens: MD5's speed makes it great for fingerprinting and terrible for secrets. "We added a salt" doesn't fix it — a salt stops precomputed rainbow tables, but a fast hash still lets attackers brute-force stolen hashes quickly. Use a purpose-built password hash.

Assuming it's reversible

MD5 is a one-way function. You can't "decrypt" a hash. The sites that claim to reverse MD5 are just looking up precomputed dictionaries of common inputs — which, incidentally, is another reason it's unfit for passwords.

The short version

MD5 is a fast, deterministic fingerprint. Use it for cache keys, change detection, bucketing, and catching accidental corruption where no attacker is involved. Keep it far away from passwords, signatures, certificates, and anything where someone could benefit from forging a match. When security matters, SHA-256 is the boring, correct default. When you just need a cheap hash and know the trade-offs, MD5 still earns its keep.

Photo by Jakub Żerdzicki on Unsplash