The Birthday Paradox
An entire family of attacks on cryptographic hash functions hides inside a parlour-trick about shared birthdays.
Pick people from a crowd, one at a time, and after each arrival ask: do any two people in the room share a birthday? The intuitive guess is something like one hundred and eighty-three, half of three hundred and sixty-five. The actual number is twenty-three.
This is the birthday paradox: not a paradox in the logical sense, just a violation of intuition. It is also the foundation of an entire family of attacks on cryptographic hash functions, and the reason a 256-bit hash gives only 128 bits of collision security.
How many people do you need in a room before two of them share a birthday, with better than even odds?
The intuitive guess is huge, because your birthday only matches each other person with probability . But the question isn’t about you. It’s about any match in the entire room.
Imagine the room filling up. With five people in it, the chance of any two sharing a birthday is about 2.7%.
At ten, it’s around 11.7%. The probability is rising faster than you’d guess: each new person adds a collision opportunity with everyone already in the room. Match candidates grow as , not .
At twenty-three, the probability crosses one half. From a pool of 365 possible birthdays, twenty-three people are enough to make a match more likely than not.
By fifty, the chance is 97%. Past sixty, you’d be unlucky to not find a match. The collisions, once they start, are everywhere.
The first person has any birthday. The second person must avoid the first: probability . The third must avoid two: . And so on. Multiply, then subtract from one: that’s the chance of at least one match.
The same calculation applies whenever you’re throwing samples into a finite space. A hash function maps inputs to one of outputs. An attacker hashing random inputs is filling a room with people; the “birthday” is the hash output; a “match” is a collision.
The calculation, in full
Order the people . The first has any birthday. The second must avoid the first’s birthday: probability . The third must avoid the two existing birthdays: . Continuing, the probability that no two people share a birthday is
The probability of at least one match is the complement:
Plug in and you get . Plug in and you get .
A cleaner approximation
For small , . So
The probability of at least one match crosses when , or .
The general rule: in a uniform space of possibilities, expect a collision after roughly samples, not .
Why cryptographers care
A hash function maps arbitrary inputs to one of outputs. If is well-designed, finding two distinct inputs with , a collision, should be hard. The birthday bound tells us how hard.
After random hash queries, an attacker expects to have seen a collision by pure coincidence. So an -bit hash function offers only bits of collision security, not .
This is why SHA-256 is the standard for “128 bits of security”: its 256-bit output gives birthday-attack resistance against collisions. It is also why SHA-1 (160 bits → 80 bits of collision security) was retired ahead of schedule when SHAttered showed an -cost attack was practical.
The same square-root rule shows up in Pollard’s for discrete logarithms, in distinguishability bounds for keyed PRFs under random sampling, and in the design of Merkle-tree commit schemes. Once you see the birthday in a crowd, you start seeing it everywhere.