Security
MD5 vs SHA-256: A Plain-English Guide to Hashing
You have probably seen a long string of random-looking letters and numbers next to a file download, labelled something like "MD5" or "SHA-256." That string is a hash, and it is one of the most useful ideas in computing. This guide explains what a hash actually is, why the old favourite MD5 should no longer be trusted, and when SHA-256 is the right tool for the job.
What a hash actually is
A hash function takes any input — a word, a password, a 4 GB video file — and turns it into a fixed-length string called a "digest" or "fingerprint." No matter how big the input is, the output is always the same size.
Two properties make hashes special:
- Same input, same output. Hash the word
turtlea thousand times and you get the identical result every time. - Tiny change, totally different output. Change one letter —
turtletoTurtle— and the entire digest changes beyond recognition. This is called the avalanche effect.
Crucially, a hash is a one-way trip. You cannot take a digest and work backwards to recover the original input. That is what makes hashing different from encryption, which is designed to be reversed with the right key.
The properties that matter
- Deterministic — the same input always produces the same digest.
- Fast — a good general-purpose hash computes quickly even on large files.
- One-way (preimage resistance) — given a digest, it is infeasible to find an input that produced it.
- Collision resistance — it should be infeasible to find two different inputs that produce the same digest.
That last property is exactly where MD5 falls apart.
MD5: fast, familiar, and broken
MD5 produces a 128-bit digest and has been around since the early 1990s. It is fast and still shows up everywhere, which is precisely the problem: it is cryptographically broken. Researchers can now produce collisions — two different inputs with the same MD5 digest — cheaply and on demand.
That means you should never use MD5 for anything security-related: digital signatures, certificates, or verifying that a file has not been tampered with by an attacker. A motivated adversary can craft a malicious file that matches the "expected" MD5 of a legitimate one.
MD5 only survives in non-security contexts — for example, a quick checksum to catch accidental corruption during a download or a disk copy. Even there, SHA-256 is the better default, so there is rarely a good reason to reach for MD5 in new code.
SHA-256: the modern default
SHA-256 is part of the SHA-2 family and produces a 256-bit digest. It is currently considered secure, with no practical collision or preimage attacks known. That is why it underpins so much of the modern internet: TLS certificates, blockchain networks, software signing, and file-integrity checks all rely on it.
Side by side
| Algorithm | Output size | Status | Safe for security? |
|---|---|---|---|
| MD5 | 128-bit | Broken (practical collisions) | No |
| SHA-256 | 256-bit | Considered secure | Yes |
One important warning about passwords
Here is a mistake even experienced developers make: hashing a password with plain MD5 or plain SHA-256 is not enough. These are fast, general-purpose hashes — and "fast" is exactly what you do not want for passwords, because it lets attackers test billions of guesses per second.
For storing passwords, use a deliberately slow password-hashing function such as bcrypt, scrypt, or Argon2, each combined with a unique salt. Reserve fast hashes like SHA-256 for integrity checks, not for password storage.
When to reach for a hash
- Verify a download. Compare the published SHA-256 against the file you received to confirm it was not corrupted or tampered with.
- Deduplicate files. Identical files produce identical digests, so hashing is a cheap way to spot duplicates.
- Index and look up data. Hashes give you a compact, fixed-length key for large or variable-length values.
The takeaway
A hash turns any input into a fixed-length fingerprint you can trust to be consistent — but only if the algorithm behind it still holds up. MD5 no longer does, so treat it as a relic for accidental-corruption checks at most. For anything that matters, reach for SHA-256 — and remember that passwords need a slow, salted hash of their own.