Side by side
| MD5 | SHA-256 | |
|---|---|---|
| Published | 1992, RFC 1321 | 2001, FIPS 180-4 |
| Output | 128 bits | 256 bits |
| Hex length | 32 characters | 64 characters |
| Block size | 512 bits | 512 bits |
| Collision resistance | Broken (seconds) | Intact |
| Preimage resistance | Intact | Intact |
| Relative speed | Faster in plain software | Comparable with hardware acceleration |
| Typical use in 2026 | Legacy APIs, non-adversarial integrity checks | Default for everything new |
Both are Merkle–Damgård constructions: pad the input, split into blocks, run a compression function, chain the state forward. That shared design is why both eventually became vulnerable to the same class of attack — a collision in the compression function can be extended into a collision in the whole message.
How MD5 broke, in order
- 1996. A collision in the compression function is found. Not yet a full-message collision, but a warning.
- 2004. Xiaoyun Wang's team presents the first full MD5 collision, computed in about an hour on a standard cluster. The technique is refined quickly; by 2006 a laptop can do it in under a minute.
- 2007. Chosen-prefix collisions: two arbitrary messages, each with attacker-chosen content, can be made to collide. This is the dangerous form, because it lets an attacker keep a benign-looking document and swap in a malicious one.
- 2008. A rogue certificate authority is created using a cluster of 200 PlayStation 3 consoles, exploiting an MD5 collision in a real CA's certificate chain. The attack was practical, not theoretical.
- 2012. The Flame malware uses an MD5 chosen-prefix collision to forge a Microsoft code-signing certificate.
- 2017. SHA-1 falls too: the SHAttered attack produces two different PDFs with the same SHA-1 digest.
- 2020. SHA-1 chosen-prefix collisions become cheap enough to threaten PGP web of trust. Nothing relies on SHA-1 collision resistance today.
SHA-256 has been analysed hard for twenty-five years without a practical attack. That is not a proof of security, but it is a much stronger position than "broken and still deployed".
What the speed difference actually is
In pure software, MD5 processes roughly twice as many bytes per second as SHA-256, because it does 64 rounds of 32-bit arithmetic per block against SHA-256's 64 rounds with more work per round. On a modern x86 or ARM CPU with SHA extensions, SHA-256 is often faster than a naive MD5 implementation.
For the sizes people usually hash — a text string, a 50 MB installer — the difference is milliseconds either way and should not influence the decision. For a pipeline hashing terabytes a day, it might. That is the only scenario where MD5's speed advantage is worth defending, and even then the right answer is usually "use SHA-256 with hardware acceleration", not "use MD5".
Deciding for your case
| Situation | Choice | Reason |
|---|---|---|
| Downloading a file and comparing to a published checksum | Whichever the publisher used | Comparing the wrong algorithm is useless. Verify the digest you were given. |
| Publishing a checksum for your own release | SHA-256 | Universal tool support, no credible attack. Optionally also publish SHA-512. |
| Signing a document or certificate | SHA-256 or SHA-384 | MD5 signatures are forgeable by collision. This is the case where MD5 is genuinely dangerous. |
| An API specification that says "md5" | MD5 | Interoperability wins. Implement to spec, and note the weakness if you control the spec's future. |
| Detecting accidental corruption on disk or in transit | Either | No adversary involved. MD5 is adequate and slightly cheaper. |
| Storing passwords | Neither | Both are far too fast. Use Argon2id, scrypt or bcrypt. |
| Cache keys, hash tables, deduplication | Either, or xxHash / BLAKE3 | Collision resistance against an attacker is not part of the threat model; speed is what matters. |
Migrating from MD5 to SHA-256
The hard part is never the hashing call. It is every stored value and every counterparty. A workable sequence:
- Inventory. Find every place an MD5 is produced or consumed: checksum files, database columns, API signatures, cache keys, test fixtures.
- Extend the storage first. A column sized for 32 characters will silently truncate a 64-character digest. Widen it before you generate anything.
- Write both. For a transition period, compute and store both digests. Nothing breaks, and you can compare old and new for the same input.
- Dual-read with a preference. Verification accepts SHA-256 if present, falls back to MD5, and records which one matched. Watch the fallback count drop to zero.
- Cut over. After the fallback count has been zero for a full cycle, stop generating MD5, then drop the column or the field.
- Say so publicly. If you publish checksums, announce the change and keep publishing both for at least one release. Users who verify by script will break otherwise.
The trap in "just switch the algorithm". If MD5 is used inside a signature that a third party verifies, changing it unilaterally means every request fails. Establish which side controls the algorithm before you touch the code.
Doing the comparison now
The MD5 generator shows MD5 and SHA-256 for the same input side by side, which makes the length difference obvious. To check a value you were given, use the checksum verifier — it works out the algorithm from the length so you do not have to.