On 23 February 2017, researchers at CWI Amsterdam and Google published two different PDF files with the same SHA-1 digest. The SHAttered team reported that the collision took roughly nine quintillion SHA-1 computations, which is about 6,500 CPU-years and 110 GPU-years of work. That is far less than a blind search would need, and it was within reach of a well-funded team. Cryptographers had already called SHA-1 "broken" in theory years earlier, once collision attacks cheaper than a blind search were published. SHAttered made the break practical, yet nobody can take a SHA-1 digest and recover the input behind it. Both statements hold because a hash function makes three separate promises, and the attacks broke only one of them.

The hash tool on this site computes four algorithms side by side: MD5, SHA-1, SHA-256 and SHA-512. All four make the same three promises. Below is how they keep them, and where the two older ones stopped.

Reading the legacy tag: three promises, one broken

A digest is a short, fixed-size fingerprint of any number of bytes. A 3-byte string and a 4 GB disk image both produce 160 bits under SHA-1. A cryptographic hash function is expected to resist three kinds of search:

  • Preimage resistance: given a digest, you cannot find any input that produces it.
  • Second-preimage resistance: given one input, you cannot find a different input with the same digest.
  • Collision resistance: you cannot find any two inputs that share a digest, even if you choose both.

Collisions have to exist. There are infinitely many possible inputs and only 2^128 possible MD5 outputs, so many inputs share each digest. The promise is only that finding them is infeasible.

Collision resistance is the easiest promise to attack, because the attacker controls both inputs. The birthday paradox sets a generic ceiling. For an n-bit digest, a random search finds some colliding pair after roughly 2^(n/2) attempts, not 2^n. This follows from the output size alone, whatever the algorithm:

Algorithm Digest bits Generic collision cost Generic preimage cost
MD5 128 about 2^64 about 2^128
SHA-1 160 about 2^80 about 2^160
SHA-256 256 about 2^128 about 2^256
SHA-512 512 about 2^256 about 2^512

The MD5 and SHA-1 cards in the tool carry a legacy tag. In the literature on these two algorithms, "broken" means that someone found a way to produce collisions far more cheaply than the birthday bound. It does not mean that a digest can be reversed. The preimage column is a different problem, and no published attack has made it practical for either algorithm.

Why "decrypt MD5" websites seem to work

Three operations are often confused:

  • Encoding changes how bytes are written, and no secret is involved. Anyone can undo Base64, as the Base64 encoder shows in both directions.
  • Encryption hides data under a key, and whoever holds the key can reverse it. A Caesar shift is a toy example: shift by three, then shift back by three.
  • Hashing has no key and no inverse. Information is thrown away, so there is nothing to "decrypt".

Yet websites offering to "decrypt MD5" exist, and they do return answers for short inputs. They do not reverse the function. They guess: they hash common words, leaked passwords and short strings, then look up your digest among the results. If the input was "password123", the guess succeeds. If it was a random 30-character string, it does not.

This is why the tool carries a Not for passwords note. The reason is not that MD5 or SHA-1 are broken: none of these digests, SHA-256 included, was ever meant for passwords. MD5, SHA-1 and SHA-2 are designed to be fast, and speed is exactly what an attacker guessing billions of passwords wants. The OWASP Password Storage Cheat Sheet states that fast algorithms such as SHA-256 are not suitable for password storage. It recommends Argon2id first, then scrypt, PBKDF2 where FIPS-140 compliance is required, and bcrypt for legacy systems. These functions are deliberately slow, and Argon2id and scrypt are also memory-hard.

The other half of password safety is how much guessing a password can withstand. That is covered in how password entropy is measured and where randomness comes from.

Following "abc" through the machine

MD5, SHA-1 and SHA-2 share one design, known as the Merkle–Damgård construction. Ivan Damgård and Ralph Merkle each described it, working independently, at CRYPTO '89 (Damgård's paper). It works in four steps:

  1. Pad the message so its length is a multiple of the block size.
  2. Split it into fixed-size blocks.
  3. Start from a fixed initial state. Feed each block and the current state into a compression function, which outputs a new state.
  4. After the last block, the state is the digest.

All four algorithms pad the same way (RFC 1321, FIPS 180-4). They append a single 1 bit (the byte 0x80), add zeros, and end with the original message length in bits. The length field is 64 bits for MD5, SHA-1 and SHA-256, and 128 bits for SHA-512. FIPS 180-4 uses "abc" as its worked example. For SHA-256, the 3 bytes become one 64-byte block:

61 62 63 80 00 00 00 00 ... 00 00 00 00 00 00 00 00 18
└─ "abc" ┘ └ 0x80 ┘ └──── zero fill ────┘ └ length = 24 bits ┘

MD5 writes the length field in little-endian byte order, so the 0x18 sits at the start of those 8 bytes rather than at the end.

One consequence is that even the empty string has a well-defined digest, because padding alone fills one block. The RFC 1321 test suite lists it:

MD5("") = d41d8cd98f00b204e9800998ecf8427e

Damgård proved that if the compression function is collision-resistant, so is the whole hash. This is why attacks on MD5 and SHA-1 go after the compression function. Once it falls, the proof no longer covers the whole hash.

Length extension, and why HMAC exists

In this design, the digest is the full internal state. Suppose someone knows hash(secret ‖ message) and the length of the secret. They can continue the computation from that state, appending padding and new data, without ever seeing the secret. A naive MAC built as hash(key ‖ message) can therefore be extended to cover a longer message.

Message authentication uses HMAC to avoid this. HMAC runs the hash twice with the key mixed into both passes. Extending the published value only gives a hash of something longer, never a valid tag for a different message. Designs that never output their whole state avoid the problem too. FIPS 180-4 defines SHA-384 and SHA-512/256 as truncated outputs of a 512-bit state. SHA-3 (FIPS 202) is a sponge construction that keeps part of its state, the capacity, out of the output.

What changes between the four digests

Ronald Rivest published MD5 in RFC 1321 in April 1992, as an extension of his earlier MD4. Its state is 128 bits, held as four 32-bit words. Each 512-bit block passes through 4 rounds of 16 steps. Each round uses a different auxiliary function (F, G, H or I) that mixes the words with bitwise operations.

The 64 step constants come from a formula anyone can check:

T[i] = floor(2^32 × |sin(i)|),  i = 1 … 64, i in radians

These are "nothing-up-my-sleeve" numbers. Arbitrary hex values could make readers suspect the designer picked them to plant a weakness. A formula based on the sine function leaves no room for that.

SHA-1 and SHA-2 follow the same outline. They differ in state size, word size, number of rounds and the mixing functions inside each round. The figures come from FIPS 180-4, and from RFC 1321 for MD5:

Algorithm Digest bits Block bits Word bits Rounds Length field bits Output byte order
MD5 128 512 32 64 steps (4 × 16) 64 little-endian
SHA-1 160 512 32 80 64 big-endian
SHA-256 256 512 32 64 64 big-endian
SHA-512 512 1024 64 80 128 big-endian

SHA-2 also uses nothing-up-my-sleeve constants. The SHA-256 initial state is the first 32 bits of the fractional parts of the square roots of the first 8 primes. Its 64 round constants come from the cube roots of the first 64 primes. SHA-512 uses 64-bit versions of the same idea, with the cube roots of the first 80 primes.

FIPS 180-4 also defines SHA-224, SHA-384, SHA-512/224 and SHA-512/256, which are truncated variants with different initial values. SHA-3 is a separate design. The tool computes only MD5, SHA-1, SHA-256 and SHA-512.

The mixing produces the avalanche effect, where a small change to the input changes the digest completely. "abc" is a shared reference across the whole family, and the FIPS worked example for SHA-256 matches what the abc example in the tool shows:

MD5     900150983cd24fb0d6963f7d28e17f72
SHA-1   a9993e364706816aba3e25717850c26c9cd0d89d
SHA-256 ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad
SHA-512 ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a
        2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f

The RFC 1321 test suite also lists "a", which is "abc" with the last two letters removed:

MD5("abc") = 900150983cd24fb0d6963f7d28e17f72
MD5("a")   = 0cc175b9c0f1b6a831c399e269772661

The two digests share no visible pattern. To see the avalanche effect without changing the length, type "abc" into the tool, then change only the last letter and watch every card change.

Identical-prefix and chosen-prefix: the attacks that mattered

Not every collision is equally useful to an attacker:

  • An identical-prefix collision starts from one shared prefix. The attacker computes two different blocks to append so that both messages reach the same internal state, and anything appended afterwards keeps them colliding. The two files can differ in meaningful ways, as the two SHAttered PDFs show, but the attacker does not control where each one starts.
  • A chosen-prefix collision starts from two different prefixes chosen by the attacker, such as two certificate requests with different names. The attacker then computes suffixes that make the digests meet. This is the form that forges certificates and signatures: get an innocent-looking document signed, then reuse the signature on a malicious one.

The main milestones:

  • 2005: Xiaoyun Wang and Hongbo Yu published "How to Break MD5 and Other Hash Functions" at EUROCRYPT 2005. It gave a method for finding MD5 collisions fast enough to run on ordinary computers.
  • December 2008: at the 25th Chaos Communication Congress in Berlin, a team showed a rogue CA certificate built from an MD5 chosen-prefix collision. They computed it on more than 200 PlayStation 3 consoles. As a safety measure, they gave the certificate a validity period in July–September 2004, so it had already expired.
  • 2012: the Flame malware turned out to rely on a previously unknown variant of the MD5 chosen-prefix attack. Marc Stevens identified this variant with his counter-cryptanalysis technique (CRYPTO 2013), which detects collision attacks from a single message of the colliding pair.
  • 2017: SHAttered, the first full SHA-1 collision, was an identical-prefix collision.
  • 2020: Gaëtan Leurent and Thomas Peyrin published "SHA-1 is a Shambles", the first chosen-prefix collision for SHA-1. They built two PGP keys with different identities but colliding SHA-1 certificates. The computation took two months on 900 GPUs. The authors paid about US$75,000, and they estimate about US$45,000 at cheaper GPU rental prices.

None of these is a preimage attack. In every case, the researchers generated both colliding inputs themselves. Nobody can take an existing MD5 or SHA-1 digest and produce an input that matches it.

Standards bodies responded. NIST announced on 15 December 2022 that SHA-1 should be phased out by 31 December 2030 in favour of SHA-2 or SHA-3.

Deciding whether MD5 or SHA-1 is good enough for a job

The answer depends on who could have prepared the input. Three cases give three answers:

  • Accidental change, such as a bad download, a failing disk or a truncated copy. This needs no adversarial resistance at all. Any digest that mixes its input well changes completely when a bit flips, so MD5 and SHA-1 still catch it, whatever their collision status.
  • An attacker who wants to match a digest that was published honestly. They need a second preimage, and that still holds in practice for MD5 and SHA-1. They cannot forge a different file to fit an existing checksum.
  • An attacker who prepares both files. Collisions are now practical, so this is where MD5 and SHA-1 fail. RFC 6151 states that "MD5 is no longer acceptable where collision resistance is required such as digital signatures".

In practice, legacy digests remain reasonable for:

  • detecting corruption in transfers and storage
  • cache keys and change detection on data you control
  • finding duplicate files in your own collection

They are not reasonable for:

  • signatures, certificates and anything else where someone could hand you one of two colliding files
  • any new protocol design, since a stronger digest costs little extra

A checksum protects against tampering only if it reaches you through a channel the attacker does not control. If the file and its digest come from the same compromised server, the attacker can replace both. The practical side of this is covered in what causes a checksum mismatch and what a match proves.

Git: integrity without secrecy

Git names every object by its SHA-1 digest. The goal is integrity, not secrecy: a commit ID must reliably identify one exact tree of content. The Git hash-function-transition document cites SHAttered. It explains that a broken hash would mean "we could not trust that a given hash value represented the known good version of content".

As an immediate measure, Git v2.13.0 and later use a hardened SHA-1 implementation by default, which the document says is not vulnerable to the SHAttered attack. The long-term plan is SHA-256. New repositories can already use it with git init --object-format=sha256, although the git-init documentation notes that they do not yet interoperate with SHA-1 repositories.

Checking a digest in the browser

Browsers have a built-in hashing API, crypto.subtle.digest(). According to MDN, it supports SHA-1, SHA-256, SHA-384 and SHA-512 but not MD5, and it is available only in secure contexts, such as pages served over HTTPS.

To show all four digests in every context, this tool implements MD5, SHA-1, SHA-256 and SHA-512 in plain JavaScript and computes all four on every input. The Algorithms checkboxes only choose which cards are displayed and which digests the comparison checks.

Every digest is computed over bytes, not characters. Typed text is first encoded as UTF-8, so "é" becomes 2 bytes and "😀" becomes 4:

MD5("😀") = 2a02eac39d716a70ecf37579185927b6

A chosen file is hashed as raw bytes by the same code, with no text decoding. Text that looks identical can still produce different digests if its line endings or encoding differ. The checksum article covers those cases.

Published checksums are often printed in uppercase or copied with stray spaces. Compare with an expected hash ignores letter case and leading or trailing whitespace, and it checks only the algorithms that are currently selected.

Very large files are read fully into memory and hashed in plain JavaScript, so they are slow and use a lot of memory. To see how the four digests of one input compare, paste it or choose it as a file in the hash tool and look across the cards.

Privacy

All hashing runs in the browser, with no network request. Neither text nor files are uploaded or stored, which is what the Runs locally in your browser badge refers to.

FAQ

If MD5 is broken, why do some download pages still publish MD5 checksums?

The main job of a download checksum is catching accidental corruption, and any well-mixing digest does that, whatever its collision status. MD5 also still resists second preimages in practice, so an attacker cannot forge a different file to match a checksum that was published honestly. Collisions matter only when the attacker could have prepared both files, or when the checksum comes from the same server as the file. A SHA-256 checksum delivered over a trusted channel is still the better choice.

Does a longer digest like SHA-512 make a file check safer than SHA-256?

Not in any practical sense. SHA-256 already has a generic collision cost of about 2^128, and no attack comes close to that. SHA-512 raises the bound further, but both are far beyond reach. Use whichever one the publisher provides, since a check only works when you compare like with like.

Why doesn't the browser's built-in Web Crypto API offer MD5?

According to MDN, digest() supports SHA-1, SHA-256, SHA-384 and SHA-512, and MD5 is not among them. MDN also marks SHA-1 as unsuitable for cryptographic use. Separately, RFC 6151 states that MD5 is no longer acceptable where collision resistance is required. Tools that still need MD5 for checksums implement it themselves, as this one does.

What is the difference between an identical-prefix and a chosen-prefix collision?

In an identical-prefix collision, both messages share the same starting content and differ only in computed blocks, as in SHAttered. In a chosen-prefix collision, the attacker picks two unrelated starting documents and computes suffixes that make the digests match. The chosen-prefix form was used to forge a rogue CA certificate in 2008 and colliding PGP certificates in 2020.

Why is Git moving away from SHA-1 if nobody can reverse a SHA-1 hash?

Git does not need secrecy. It needs each object ID to identify exactly one piece of content, and collisions threaten exactly that. Two different objects could share a name, and a signature over one commit ID could cover content the signer never saw. Git hardened its SHA-1 implementation in v2.13.0 and supports SHA-256 repositories as the long-term fix.

Further reading

  • RFC 1321: the MD5 specification, with reference C code and the test suite used in this article.
  • FIPS 180-4: the normative definition of SHA-1 and SHA-2, including padding, constants and worked examples.
  • FIPS 202: the SHA-3 standard, a sponge construction rather than a Merkle–Damgård design.
  • RFC 6151: the IETF's short statement on where MD5 and HMAC-MD5 are no longer acceptable.
  • shattered.io: the SHA-1 collision, with the two PDFs and a plain-language explanation.
  • SHA-1 is a Shambles: the first SHA-1 chosen-prefix collision and the PGP demonstration.
  • Rogue CA certificate: a detailed account of how an MD5 collision became a trusted certificate.
  • NIST SHA-1 retirement notice: the official deadline for phasing out SHA-1.
  • OWASP Password Storage Cheat Sheet: which slow functions to use for passwords instead of a fast digest.
  • Git hash-function transition: how a large project plans a migration away from a weakened hash.