Most people guess billions, because 4.3 billion slots feels like room for billions of items. The same intuition says you'd need a room of about 180 people before two share a birthday. It takes 23.
Count pairs, not people
A collision isn't about any one person. It's about any pair of people matching, and pairs grow much faster than people do:
| People | Pairs | Chance any pair matches |
|---|---|---|
| 5 | 10 | 3% |
| 23 | 253 | 51% |
| 40 | 780 | 89% |
| 70 | 2,415 | 99.9% |
With 23 people there are 253 pairs, each a 1-in-365 shot. That's plenty of chances for one to land.
Where the square root comes from
Hashing is the same problem: items, possible hash values. The cleanest way to count is the chance that nothing goes wrong. The second item must miss 1 taken slot, the third must miss 2, and so on:
(1) Exact chance that every item gets its own slot.
Take logs, use for small , and the sum is about . Out comes the version worth remembering:
(2) Collision probability for n items over m slots.
The is the pairs from the table above. Set , solve for , and you get : even odds arrive at the square root of the space, not the space itself.
What that means for hash width
| Hash | Possible values | 50% collision at |
|---|---|---|
| 32-bit | 4.3 billion | 77,163 items |
| 64-bit | 1.8 × 10¹⁹ | about 5 billion items |
| 128-bit | 3.4 × 10³⁸ | about 2.2 × 10¹⁹ items |
Doubling the bits squares the safe item count rather than doubling it, which is why 128-bit hashes are treated as collision-free in practice and 32-bit ones are not safe as unique IDs for anything that grows. Once gets anywhere near , switch back to the exact product: the exponential version only tracks it while is small next to .
The formula is also a best case. It assumes a perfectly uniform random hash, and real ones fall short: in Daniel Lemire's experiment, a hash that theory said needed 77,000 items to reach 50% collided on every run with just 1,000.
So when someone says a hash space is "huge", take its square root. That's the number of items you can actually afford.