A birthday attack on a hash function finds two inputs with the same output after roughly 2n/2 attempts for an n-bit hash, not 2n. That is why a 256-bit hash such as SHA-256 gives only 128 bits of collision security, even though finding an input that matches one specific output still takes about 2256 work.
The same arithmetic explains a classroom puzzle: why 23 people are enough for a shared birthday to be more likely than not. Below we go from that puzzle to the formulas, then to a 1994 design for a collision machine, a forged certificate authority in 2008, and the debate over what quantum computers change.
The birthday paradox: why 23 people are enough
In a group of 23 people, the chance that at least two share a birthday is 50.7297%, or about 50.7%. With 70 people it rises to 99.9%. Most people expect a much larger group, because they picture someone matching their own birthday. The question is about any pair, though, and 23 people form 253 pairs.
The exact calculation looks at the opposite event. The probability that n birthdays are all different is 365 × 364 × … × (365 − n + 1) / 365n, which can also be written 365! / ((365 − n)! · 365n). A good approximation for the chance of a match is p(n) ≈ 1 − e−n(n−1)/730.
The problem is generally credited to Harold Davenport around 1927. He did not publish it then and did not claim to have discovered it. Richard von Mises published a version in 1939.
Why is collision resistance half the hash length?
Replace 365 days with H possible hash outputs and the same logic holds. For n random draws from H equally likely values, the probability of at least one collision is about 1 − e−n(n−1)/(2H), or roughly 1 − e−n²/(2H).
Solving for n tells you how many hashes you need to reach a given probability p: n ≈ √(2H · ln(1/(1−p))). For p = 0.5 that comes to about 1.1774√H. The expected number of draws before the first collision is about √(πH/2), or roughly 1.25√H. For small probabilities a simpler rule of thumb, p ≈ n²/(2H), “works well for probabilities less than or equal to 0.5.”
The key term is √H. For an n-bit hash, H = 2n, so √H = 2n/2. That is the birthday bound, and it is why collision security is half the output length.
Hash collision probability in numbers
| Hash output | p = 10−6 | p = 0.5 | p = 0.75 |
|---|---|---|---|
| 64 bits | ≈ 6.1 × 106 hashes | ≈ 5.1 × 109 | ≈ 7.2 × 109 |
| 128 bits | ≈ 2.6 × 1016 hashes | ≈ 2.2 × 1019 | ≈ 3.1 × 1019 |
Figures from the Wikipedia birthday attack article. A 64-bit identifier reaches a coin-flip chance of collision after about five billion values. Modern hardware gets through that quickly.
What NIST’s security-strength table says
NIST states the rule directly: “The collision resistance strength in bits is equal to half of the output size of the hash function.” Preimage strength, meaning the work to find an input for a given output, equals the full output size.
| Hash | Collision strength (bits) | Preimage strength (bits) |
|---|---|---|
| SHA-1 | <80 | 160 |
| SHA-224 | 112 | 224 |
| SHA-256 | 128 | 256 |
| SHA-384 | 192 | 384 |
| SHA-512 | 256 | 512 |
| SHA3-256 | 128 | 256 |
SHA-1 is the exception. Its collision strength is listed below the generic 80 bits because cryptanalysis found shortcuts faster than the birthday bound. NIST deprecated SHA-1 in 2011, disallowed it for digital signatures at the end of 2013, and in December 2022 published a plan to move away from its remaining limited use. For the full story, see our article on how SHA-1 collisions went from 2^69 on paper to a $45,000 attack.
How a birthday attack on a signed contract works
The birthday attack has been part of the cryptographic literature for a long time. One early reference is Gideon Yuval’s “How to Swindle Rabin,” Cryptologia vol. 3, pp. 187–189, July 1979, which MathWorld lists in its entry on birthday attacks. That entry describes the general idea: if a function returns one of k equally likely values, you expect a repeated output after about 1.2√k evaluations. The Rabin in the title is Michael O. Rabin, who in 1978 invented the Rabin signature algorithm, the first asymmetric cryptosystem whose security was proved equivalent to the difficulty of integer factorization.
The classic signature scenario goes like this, as described in the Wikipedia birthday attack article:
- Mallory writes a fair contract and a fraudulent one.
- She makes many versions of each with changes that don’t affect the meaning: “inserting commas, empty lines, one versus two spaces after a sentence, replacing synonyms”.
- She hashes the versions until one fair version and one fraudulent version have the same hash.
- Bob signs the fair version. Because the signature covers the hash, it is also valid for the fraudulent version, and Mallory attaches it there.
Mallory doesn’t need a collision with any particular document, just any match between her two sets. For an l-bit hash she needs about 2(l/2)+1 hashes for a 50% chance, which is “twice the number required for a simple collision under the classical birthday problem.” Against a 2l preimage search, that is a huge shortcut.
There are two standard defences. One is an output long enough to make the attack infeasible, “about twice as many bits as are needed to prevent an ordinary brute-force attack.” The other works on the signer’s side: before signing, make small random edits that don’t change the meaning, and keep a copy of the exact text you signed. Mallory can’t prepare a matching fraudulent version for text she hasn’t seen.
Birthday attacks in practice: from a 1994 design to a 2008 rogue CA
Parallel collision search (1994)
Simple collision search stores every hash it computes, so memory becomes the bottleneck long before compute does. In July 1994, Paul C. van Oorschot and Michael J. Wiener published Carleton University technical report TR-249, “Parallel Collision Search with Application to Hash Functions and Discrete Logarithms.” It presents “a simple new method of parallelizing collision searches” that extends what practical attacks can reach.
Their estimate for MD5 made the threat concrete. For finding altered versions of two messages with the same hash, “a $10 million custom machine for applying parallel collision search to the MD5 hash function could complete an attack with an expected run time of 24 days.” The same method also applies to discrete logarithms: a $10 million machine for an elliptic-curve cryptosystem over GF(2155) could compute one in an expected 36 days.
The 2008 MD5 rogue CA certificate
On 30 December 2008, at the 25th Chaos Communication Congress (25C3) in Berlin, Alexander Sotirov, Marc Stevens, Jacob Appelbaum, Arjen Lenstra, David Molnar, Dag Arne Osvik and Benne de Weger presented a rogue certificate authority certificate built with an MD5 chosen-prefix collision.
The attack had two stages, and the birthday stage was the expensive one. In the authors’ words, “the computational bottleneck is the birthday search,” and “the first stage consisting of the birthday search is computationally the most expensive.” Key details:
- Hardware: more than 200 PlayStation 3 consoles in the PlayStation Lab at Arjen Lenstra’s laboratory at EPFL in Lausanne.
- Birthday stage: about 18 hours on the 200 PS3s, using 30 GB of memory.
- Near-collision stage: about 3 to 10 hours in total on a high-end quad-core PC.
- Parameters: 72 birthday bits and 3 near-collision blocks, for an estimated 251.x MD5 compression function calls with 30 GB of memory available.
- Cost of certificates: RapidSSL charged USD 45 each, and each could be reissued up to 20 times for free, so each request effectively cost USD 2.25. The team spent USD 657 in total.
Fourteen years after the van Oorschot–Wiener estimate, a team of researchers with a lab of game consoles had turned a birthday search into a working forgery against the web’s trust infrastructure.
Quantum collision attacks: the BHT cube-root bound and the dispute
On 1 May 1997, Gilles Brassard, Peter Høyer and Alain Tapp submitted “Quantum Algorithm for the Collision Problem” (arXiv:quant-ph/9705002). Their algorithm, known as BHT, finds collisions in any r-to-one function using O((N/r)1/3) expected evaluations of the function. That beats the best classical algorithm in the black-box setting. It uses Grover’s search algorithm in a new way.
For an n-bit hash this works out to roughly 2n/3 evaluations instead of 2n/2. Plugging in SHA-256 gives about 285, compared with the classical 2128.
That count is not the end of the debate. The Wikipedia birthday attack article says quantum computers can break collision resistance in about 2l/3 operations, “though disputed,” and cites Daniel J. Bernstein’s paper on the cost of hash collisions for the dispute. A smaller number of queries doesn’t settle what an attack would actually cost to run. We cover this in more detail in what Grover and BHT really do to SHA-256.
Practical takeaways: output lengths, UUIDs and signatures
- Size outputs for collisions, not preimages. If collisions matter in your system, as they do for signatures, content addressing and deduplication, you get half the output length in security. A 128-bit target means a 256-bit hash.
- Check identifier space against volume. RFC 9562 (May 2024, which obsoletes RFC 4122) gives UUIDv4 122 random bits. Using the formula above with H = 2122, a 50% chance of a collision needs about 1.1774 × 261 ≈ 2.7 × 1018 UUIDs. The RFC still warns that “as the total number of UUID generating nodes increases, so does the likelihood of a collision,” and that “implementations should weigh the consequences of UUID collisions within their application.”
- Truncated hashes lose security fast. A 64-bit truncation reaches 50% collision odds at about 5.1 × 109 values.
- Don’t sign what someone else prepared word for word. Small random edits by the signer, plus an archived copy of the exact text signed, break the two-sided contract attack.
- Retire MD5 and SHA-1 anywhere collision resistance matters. Both have fallen below their generic birthday bound.
These questions matter for post-quantum system design too. BB84, the Ethereum Layer 2 built by Hadamard, replaces ECDSA keys with one-time addresses based on hash commitments. Security therefore rests on the collision and preimage properties of the hash rather than on elliptic curves. To see how other systems are handling the move, check our post-quantum migration tracker.
FAQ
Why does a 256-bit hash give only 128 bits of collision security?
A collision can be any pair of inputs, and the number of pairs grows with the square of the number of hashes. Among 2256 possible outputs, a match becomes likely after about √(2256) = 2128 hashes. NIST lists SHA-256 at 128 bits of collision strength and 256 bits of preimage strength.
How many hashes do you need before a collision is likely?
For a 50% chance, about 1.1774√H, where H is the number of possible outputs. On average the first collision comes after about 1.25√H hashes. For a 128-bit hash that is roughly 2.2 × 1019 hashes for 50% odds.
Do quantum computers make birthday attacks on SHA-256 practical?
The Brassard–Høyer–Tapp algorithm cuts the number of function evaluations to roughly 2n/3, which is about 285 for SHA-256. Whether that is a real cost advantage is disputed. Bernstein’s analysis of the cost of hash collisions is the main reference on that side.
Is the birthday attack the same as a preimage attack?
No. A birthday attack looks for any two inputs with the same hash, and costs about 2n/2. A preimage attack needs an input that matches one fixed output, which costs about 2n for an ideal n-bit hash.
Sources
- Birthday problem, Wikipedia (accessed 29 November 2026)
- Birthday attack, Wikipedia (accessed 29 November 2026)
- Birthday Attack, MathWorld (Eric W. Weisstein), MSU archive, 26 May 1999
- Michael O. Rabin, Wikipedia (accessed 29 November 2026)
- Parallel Collision Search with Application to Hash Functions and Discrete Logarithms, TR-249, van Oorschot and Wiener, Carleton University, July 1994
- MD5 considered harmful today: creating a rogue CA certificate, Sotirov, Stevens et al., December 2008
- Hash Functions project, NIST Computer Security Resource Center (accessed 29 November 2026)
- Quantum Algorithm for the Collision Problem, Brassard, Høyer and Tapp, arXiv, 1 May 1997
- RFC 9562: Universally Unique IDentifiers (UUIDs), RFC Editor / IETF, May 2024
