MD5 vs SHA1 vs SHA256
In-Depth Technical Comparison & Architecture Guide
MD5 and SHA-1 are both cryptographically broken — not theoretically weak, but practically broken, with real, demonstrated attacks — while SHA-256 remains secure with no known practical attack. This comparison is less about a tradeoff between three roughly-equivalent options and more about understanding exactly why two of them were retired and what, if anything, they're still safe to use for.
Quick Reference Matrix
| Feature | MD5 | SHA-1 | SHA-256 |
|---|---|---|---|
| Year Published | 1992 | 1995 | 2001 |
| Standard | RFC 1321 | FIPS 180 | FIPS 180-4 (SHA-2 family) |
| Digest Size | 128 bits | 160 bits | 256 bits |
| First Practical Collision | 2008-2009 (chosen-prefix) | 2017 ("SHAttered") | None known |
| Formal Deprecation | Widely deprecated since ~2010 | NIST-recommended against since 2013 | Currently the recommended baseline |
| Safe for Digital Signatures/Certificates | No | No | Yes |
| Safe for Non-Adversarial Checksums | Yes | Yes | Yes |
Technology Overview
MD5, designed by Ronald Rivest in 1992 and specified in RFC 1321, produces a 128-bit digest and was for years the default choice for checksums and (mistakenly) for password storage. Its downfall came in 2004, when researchers led by Xiaoyun Wang demonstrated the first practical collision attack — finding two different inputs that produce the identical MD5 hash — and by 2008-2009, chosen-prefix collision techniques had advanced far enough that attackers could craft two meaningfully different documents (not just meaningless garbage) sharing a hash. This wasn't just academic: the Flame malware, discovered in 2012, exploited an MD5 collision to forge a valid Microsoft digital certificate.
SHA-1, published by NIST in 1995 (FIPS 180) as a successor to an earlier, withdrawn SHA-0, produces a 160-bit digest. Wang's team found theoretical weaknesses in SHA-1's collision resistance as early as 2005, and NIST began formally recommending against SHA-1 for digital signatures by 2013 — years before a practical attack existed, based purely on the trajectory of the theoretical weakening. The practical attack arrived in February 2017, when Google and CWI Amsterdam published the 'SHAttered' attack, producing two distinct PDF files with an identical SHA-1 hash. Major browsers had already begun distrusting SHA-1 certificates before this, and the practical demonstration confirmed the deprecation had been correctly timed, not premature.
SHA-256, part of the SHA-2 family specified in NIST FIPS 180-4, produces a 256-bit digest and remains fully secure today — no practical collision or preimage attack exists against it. SHA-2's design deliberately differs enough from SHA-1's that the same class of attack that broke SHA-1 doesn't transfer over, and it remains NIST's and the industry's baseline recommendation for anywhere cryptographic hash security actually matters.
The Collision Attack Timeline: Theory to Practical Exploit
Both MD5 and SHA-1 followed the same pattern: a theoretical weakness in collision resistance was published first, followed years later by a fully practical, demonstrated attack, followed by formal industry deprecation. For MD5: Wang's team's 2004 collision-finding technique, refined chosen-prefix collisions by 2008-2009, and real-world exploitation (Flame malware) by 2012. For SHA-1: Wang's 2005 theoretical weakening, NIST's 2013 formal deprecation recommendation (ahead of a practical attack existing), and the 2017 'SHAttered' practical collision from Google/CWI.
This timeline matters practically: a hash function doesn't need a demonstrated practical attack to be worth abandoning — SHA-1's deprecation began years before SHAttered, based on the trajectory of published cryptanalysis. Waiting for a practical attack before migrating away from a theoretically-weakening hash function means migrating under pressure rather than on your own schedule.
SHA-256 has no equivalent timeline entry — no theoretical collision weakness of the kind that preceded both MD5's and SHA-1's breaks has been published against it, which is exactly why it remains the current baseline recommendation rather than a function on a similar deprecation trajectory.
What 'Cryptographically Broken' Actually Means Here
Being 'broken' specifically means collision resistance has failed: an attacker can find two different inputs producing the same hash, in practical time, using real hardware. It does not mean the hash can be reversed (none of these three functions are reversible in the sense of computing the original input from the digest alone) — preimage resistance and collision resistance are different properties, and MD5/SHA-1's breaks are specifically collision breaks.
This distinction matters for scoping the actual risk: a broken collision-resistance property is a serious problem for anything relying on two parties being unable to produce matching hashes for different content (digital signatures, certificate issuance, deduplication systems that trust hash equality as identity) — exactly the property Flame and SHAttered exploited. It's a non-issue for a use case that never needed collision resistance in the first place, like detecting accidental (not adversarial) file corruption during a download.
Where MD5 and SHA-1 Remain Legitimate to Use
Non-adversarial integrity checks — confirming a downloaded file wasn't corrupted in transit, verifying two local copies of a file match — don't require collision resistance against a deliberate attacker, only against accidental bit-flips, which MD5 and SHA-1 still detect reliably and quickly. This is why MD5 checksums still appear alongside many software downloads today: nobody is trying to forge a matching-hash malicious file in that specific context (and where they might, SHA-256 checksums are increasingly offered alongside for exactly that reason).
A genuinely interesting real-world case: Git uses SHA-1 internally as its object content-addressing scheme (the ID that identifies every commit, tree, and blob). This is a well-known, actively-discussed tension in the Git project — SHA-1's collision break is a real theoretical concern for Git's content-addressing model, which is precisely why Git has an ongoing, in-progress transition path to SHA-256 as an alternative object format, rather than treating the issue as irrelevant.
Digest Size and Performance Tradeoffs
MD5's 128-bit digest is the smallest and fastest to compute of the three; SHA-1's 160-bit digest is a modest step up in both size and computation cost; SHA-256's 256-bit digest is the largest and costs somewhat more CPU time to compute than either predecessor. For virtually all modern applications, this performance difference is negligible in absolute terms (all three hash typical payloads in microseconds to low milliseconds) — security properties, not raw speed, should drive the choice whenever the hash is protecting anything against a deliberate adversary.
MD5 Advantages & Disadvantages
Advantages / Pros
- Fastest computation and smallest digest of the three.
- Still fine for detecting accidental (non-adversarial) file corruption.
Disadvantages / Cons
- Practically broken for collision resistance since 2008-2009.
- Actively exploited in the wild (Flame malware, 2012).
- Must never be used for passwords, signatures, or certificates.
SHA-256 Advantages & Disadvantages
Advantages / Pros
- No known practical collision or preimage attack.
- Current NIST and industry baseline recommendation.
- Appropriate for digital signatures, certificates, and any adversarial-integrity use case.
Disadvantages / Cons
- Marginally slower to compute than MD5 or SHA-1 (rarely significant in practice).
- Larger digest size than MD5/SHA-1 (rarely significant in practice).
Real-World Use Cases
MD5 (and SHA-1)
Accidental corruption detection
Verifying a downloaded file matches its published checksum when no adversary is trying to forge a matching hash.
Legacy content-addressing systems
Existing systems (like Git's current object model) built on SHA-1 before its collision weakness was known, now navigating a deliberate migration path.
SHA-256
Digital signatures and certificate issuance
Any context where an adversary could benefit from forging two different documents with the same hash.
Blockchain and distributed ledger systems
Securing block hashes where collision resistance is foundational to the system's integrity guarantees.
Developer Recommendation
Never use MD5 or SHA-1 anywhere collision resistance actually matters — digital signatures, certificate issuance, password storage (which needs a dedicated slow hash like Argon2id anyway, not a general-purpose function at all — see Bcrypt vs Argon2), or any system where an adversary could benefit from forging a matching hash.
Use SHA-256 (or SHA-512, see SHA-256 vs SHA-512 for that specific tradeoff) as your default for any new system requiring cryptographic hash security. There is no currently-known reason to prefer MD5 or SHA-1 over SHA-256 for a new adversarial-integrity use case.
It remains fine to use MD5 or SHA-1 specifically for non-adversarial integrity checks (confirming a file wasn't accidentally corrupted) where you understand and accept that no protection against a deliberate forgery exists — just don't let that legitimate narrow use case justify using either function anywhere security actually depends on collision resistance.
Frequently Asked Questions
- Is MD5 secure for passwords?
- No — and not primarily because of its collision weakness. MD5 is fast, which is exactly the wrong property for password hashing: a fast general-purpose hash lets an attacker with a stolen database try billions of guesses per second. Use a dedicated slow, memory-hard function like Argon2id instead, regardless of MD5's collision status.
- What's the actual difference between a 'theoretical' and 'practical' collision attack?
- A theoretical attack shows collision resistance is mathematically weaker than expected, often requiring more compute than is realistically available. A practical attack actually demonstrates two real, colliding inputs computed with real hardware in feasible time — SHA-1's theoretical weakness was published in 2005, but the practical 'SHAttered' collision wasn't demonstrated until 2017.
- Why does Git still use SHA-1 if it's broken?
- Git's use of SHA-1 for content-addressing is a well-known, actively-discussed concern in the Git project, and Git has an in-progress, official transition path to SHA-256 as an alternative object format. It hasn't been treated as irrelevant — it's a real, acknowledged migration in progress.
- Can I still use MD5 for file checksums?
- Yes, for detecting accidental corruption where no adversary is trying to forge a matching file. It's not appropriate anywhere someone might deliberately want two different files to share a checksum.
- Should I use SHA-256 or SHA-512 for a new system?
- Both are secure with no known practical attack; the choice is mostly about performance characteristics on your specific hardware rather than security. See SHA-256 vs SHA-512 for that direct comparison.
- What made the Flame malware attack on MD5 significant?
- Discovered in 2012, Flame exploited an MD5 collision to forge a Microsoft digital certificate, allowing malicious code to appear validly signed by Microsoft. It was one of the clearest real-world demonstrations that MD5's collision weakness wasn't merely academic.
Part of the Hashing & Integrity Developer Hub
This comparison is part of our Hashing & Integrity topic guide, covering related tools, standards, and decision guidance.
Related Comparisons
Other technology decisions in the same topic area as Hashing & Integrity:
SHA256 vs SHA512
Cryptographic hash functions are designed to ingest arbitrary binary inputs and return a fixed-size, deterministic byte sequence called a digest. These functions must be one-way (infeasible to reverse-engineer) and collision-resistant (highly unlikely that two distinct inputs produce the same hash). In modern cryptography, the SHA-2 (Secure Hash Algorithm 2) family is the default choice for data integrity, SSL/TLS certificates, and blockchain networks. Within this family, SHA-256 and SHA-512 are the two most prominent algorithms. Surprisingly, their differences extend beyond digest length to internal block sizes, math architectures, and hardware parsing performance. This guide compares SHA-256 and SHA-512 in detail.
Bcrypt vs Scrypt
Bcrypt and Scrypt both slow down password verification deliberately, but they do it in fundamentally different ways: Bcrypt spends CPU cycles alone, while Scrypt deliberately consumes large amounts of memory alongside CPU time. That single architectural difference — memory-hardness — is the whole reason Scrypt exists, and it's the lens this comparison uses throughout.
HMAC vs Digital Signatures
Both HMAC and digital signatures let a recipient verify a message wasn't tampered with, but they answer a different second question: HMAC only proves the message came from someone who holds a shared secret, while a digital signature proves it came from the one specific party holding a private key — and only the second property, non-repudiation, actually holds up if the sender later denies sending it.
Argon2 vs Scrypt
Argon2 and Scrypt are both memory-hard — the defining property that separates them from Bcrypt (see Bcrypt vs Scrypt) — but Argon2 refines the idea with a hybrid access pattern specifically designed to resist both GPU cracking and side-channel timing attacks simultaneously, something plain Scrypt's single access pattern can't do at once.
Launch Interactive Developer Tools
Put these concepts into practice. Test, format, serialize, or analyze your inputs locally with these secure, browser-only utilities: