MD5, SHA-1 or SHA-256? Choosing a Hash Algorithm

"MD5 and SHA-1 are broken" gets repeated everywhere, often without explanation. Here is what it actually means, and what it means for whatever you're building.

What a hash function promises

A cryptographic hash takes any input and produces a fixed-length fingerprint. Three properties matter:

When someone says an algorithm is "broken", they almost always mean the third property — and how it broke determines what the algorithm is still safe for.

What "broken" actually means

Collisions are found by academics with serious compute. Nobody can reverse your SHA-256 hash. But a practical collision attack means an attacker can craft two files with the same fingerprint — show you the innocent one, then swap in the malicious one.

For MD5, that stopped being theoretical in 2004, when a team led by Xiaoyun Wang demonstrated practical collisions; since then, researchers have generated colliding certificates and files on demand. For SHA-1, Google's 2017 SHAttered attack produced two different PDFs with identical SHA-1 hashes. Both algorithms remain perfectly good checksums against accidental corruption — a flipped bit or a truncated download still changes the hash completely. What they can no longer guarantee is integrity against a motivated attacker.

So which one do you use?

You are hashing…UseWhy
Anything security-relevant (signatures, certs, dedup of untrusted input)SHA-256 or betterNo practical collision attack exists; it's the industry default.
Quick checksums of your own files, download corruption, cache keysSHA-256 still, or MD5 for legacy compatibilityAccidental corruption changes any hash. MD5 is only risky when the input can be attacker-crafted.
PasswordsNone of these. Use bcrypt, scrypt or Argon2Fast hashes are the problem — see below.
Git-style content addressing at scaleSHA-256Git itself is migrating off SHA-1 for exactly these reasons.

The counterintuitive part: passwords want slow hashes

Every hash in this article is designed to be fast. A modern GPU computes billions of SHA-256 hashes per second, which is exactly what you don't want when the input is a password — an attacker who steals your database just tries billions of guesses.

Password storage needs the opposite trade-off: a deliberately slow, memory-hungry construction. That's what bcrypt, scrypt and Argon2 are. Hashing a password with SHA-256 — even salted — is a well-known anti-pattern, because it turns a leaked database into a high-speed guessing machine.

What about SHA-512?

SHA-256 and SHA-512 are both in the SHA-2 family and both stand unbroken. The surprising detail: on 64-bit CPUs, SHA-512 (and its truncated variant SHA-384) can actually be faster than SHA-256 per byte, because it processes 1024-bit blocks in the same number of rounds. The practical reason SHA-256 dominates is compatibility — everything speaks it. If you control both ends, either is a fine choice.

The 30-second summary