A Surprising Question
How many people need to be in a room before there’s a 50% chance that two share a birthday?
Take a guess.
The Wrong Answer
Most people guess 183 (half of 365).
But that answers a different question: “How many people until someone shares my birthday?”
The Right Question
We’re asking: “Do any two people share a birthday?”
This is much easier to achieve.
Why? Let’s Count Comparisons
With 3 people (Alice, Bob, Carol):
- Does Alice match Bob?
- Does Alice match Carol?
- Does Bob match Carol?
That’s 3 comparisons.
With 4 people:
- Person 1 vs 2, 3, 4 → 3 comparisons
- Person 2 vs 3, 4 → 2 comparisons
- Person 3 vs 4 → 1 comparison
Total: 6 comparisons.
With 5 people: 10 comparisons.
With 10 people: 45 comparisons.
With 23 people: 253 comparisons.
Each comparison is a chance for a match!
The Formula
With people, the number of comparisons is:
Why? Each person compares with everyone who came after them.
- Person 1 compares with others
- Person 2 compares with others
- And so on…
Add them up:
For 23 people: comparisons.
The Answer
With 23 people, you make 253 comparisons.
Each comparison has a small chance of matching (1 in 365).
But with 253 chances, the probability adds up to over 50%.
The Exact Math
We calculate the chance of no match, then subtract from 1.
- Person 1: any birthday →
- Person 2: avoid 1 birthday →
- Person 3: avoid 2 birthdays →
- … and so on
Multiply all these:
So
That’s the birthday paradox. It takes surprisingly few people because comparisons grow so fast.
What This Means for Hashing
Replace “people” with “hash inputs” and “birthdays” with “hash outputs.”
Finding a collision:
- Generate random inputs
- Hash each one
- Compare all pairs of outputs
The birthday paradox means you find a collision much sooner than expected.
The Security Impact
For a hash with -bit output:
| Attack | Work Required |
|---|---|
| Find input for specific hash | |
| Find any collision |
The square root! That’s the birthday attack.
Real Numbers
| Hash | Output | Collision Security |
|---|---|---|
| MD5 | 128-bit | (broken) |
| SHA-256 | 256-bit | (secure) |
operations is achievable. That’s why MD5 is broken.
is still impossible. That’s why SHA-256 is secure.
To resist birthday attacks, use hashes with at least 256 bits.