MD5 shows up everywhere — in old code, in checksums on download pages, in cache keys. And every few years someone declares it dead. The truth is more nuanced. MD5 is cryptographically broken, but it's still genuinely useful for a bunch of non-security tasks. The trick is knowing which bucket you're in.

What MD5 actually is

MD5 (Message-Digest Algorithm 5) takes any input — a string, a file, a byte stream — and produces a fixed 128-bit value, usually written as a 32-character hexadecimal string. The same input always produces the same output, and even a one-character change scrambles the result completely.

md5("hello")  = 5d41402abc4b2a76b9719d911017c592
md5("hellp")  = f8c871fc78e3b05ac9a13db1e1bac19a

That's the whole appeal: a compact, deterministic fingerprint. It's fast, it's available in basically every language and runtime, and 32 hex characters is small enough to shove into a filename, a database column, or a log line.

Where MD5 still makes sense

The honest list of good uses in modern code is shorter than it used to be, but it's not empty:

  • Cache keys and deduplication. Hash a request URL, a set of query params, or a rendered template to get a stable key. Collisions here aren't a security problem, just a (vanishingly rare) cache miss.
  • Non-adversarial integrity checks. Comparing an uploaded file against a known copy, or detecting that a config file changed. If no attacker is trying to forge a match, MD5 is fine and fast.
  • Sharding and partitioning. Take the first few hex chars of an MD5 to bucket data across shards or directories. Lots of CDNs and storage layers still do this.
  • ETags and change detection. A quick way to say "has this blob changed?" without a byte-by-byte diff.

When I need a quick one-off hash while debugging — checking that two values really are identical, or reproducing a cache key by hand — I reach for a browser tool rather than firing up a REPL. Devsly's MD5 Hash Generator does it instantly and doesn't send your input anywhere you have to worry about.

Where MD5 absolutely does not belong

This is the part people get wrong, so it's worth being blunt.

Passwords

Never store passwords as MD5 hashes, salted or not. MD5 is designed to be fast, which is exactly wrong for passwords — attackers can compute billions of hashes per second on commodity GPUs. Use a purpose-built password hash: bcrypt, scrypt, or argon2. These are deliberately slow and memory-hard.

Digital signatures and security tokens

Practical collision attacks against MD5 have existed since 2004. Researchers have produced two different files with the same MD5, and there have been real-world attacks (a rogue CA certificate, the Flame malware) built on MD5 collisions. If an attacker benefits from making two inputs hash the same, MD5 is the wrong tool. Use SHA-256 or better.

Verifying downloads against tampering

A publisher-provided MD5 checksum protects against accidental corruption, not a malicious server that can swap both the file and the checksum. For real tamper resistance you want signatures, not a bare hash.

Common gotchas

Even in the cases where MD5 is appropriate, people trip over the mechanics:

  • Encoding matters. md5("café") gives different results depending on whether the string is UTF-8 or Latin-1. If two systems disagree on encoding, their hashes won't match. Normalise to UTF-8 bytes explicitly.
  • Hex vs base64 vs raw bytes. The same digest can be represented three ways. Mixing representations between producer and consumer is a classic cause of "the hashes should match but don't."
  • Trailing whitespace and newlines. Hashing file contents is sensitive to a final newline. Many a CI check has failed because one file had a trailing \n and the other didn't.
  • Case of the hex output. Some libraries emit uppercase, some lowercase. Compare case-insensitively or normalise before you store.

A short worked example

Say you're building a simple cache for expensive API responses. You want a key derived from the endpoint and its sorted parameters.

import hashlib
import json

def cache_key(endpoint, params):
    # Sort params so {a:1, b:2} and {b:2, a:1} match
    canonical = json.dumps(
        {"endpoint": endpoint, "params": params},
        sort_keys=True,
        separators=(",", ":"),
    )
    digest = hashlib.md5(canonical.encode("utf-8")).hexdigest()
    return f"resp:{digest}"

print(cache_key("/users", {"page": 2, "limit": 50}))
# resp:ab56b4d92b40713acc5af89985d4b786  (example)

Note the deliberate choices: sort_keys=True so parameter order doesn't matter, compact separators so whitespace doesn't leak in, and an explicit utf-8 encode so the key is stable across machines. That's the whole discipline — make the input canonical before you hash it.

Doing the same in Node looks almost identical:

const crypto = require('crypto');

function cacheKey(endpoint, params) {
  const canonical = JSON.stringify({ endpoint, params });
  const digest = crypto.createHash('md5')
    .update(canonical, 'utf8')
    .digest('hex');
  return `resp:${digest}`;
}

The decision rule

Keep it simple. Ask one question: would an attacker benefit from two different inputs producing the same hash?

  • If yes — passwords, signatures, security-critical integrity — don't use MD5. Reach for bcrypt/argon2 for passwords, SHA-256 for integrity and signatures.
  • If no — cache keys, deduplication, sharding, friendly change detection — MD5 is fast, tiny, and perfectly fine.

MD5 isn't dead. It's just been demoted from a security primitive to a humble, fast fingerprinting tool. Use it for what it's good at, keep it well away from anything adversarial, and mind your encodings. Do that and it'll serve you quietly for years.

Photo by Markus Spiske on Unsplash