Draw items uniformly from possibilities. The probability that some two coincide is
A collision becomes likely once
The “paradox”: with days, only 23 people are needed for a 50% chance of a shared birthday, and 70 for 99.9%.
The threshold — the useful form
| for 50% collision | for 1% collision | |
|---|---|---|
| 365 | 23 | 3 |
| 1 178 | 142 | |
| 37 000 | 4 500 | |
| 77 000 | 9 300 | |
Read this table before choosing a hash modulus. collides with probability near 1 once you hash distinct strings — which is why or double hashing is the right default. See Polynomial Hashing.
Where it appears
As a hazard
| Situation | Consequence |
|---|---|
| String hashing with a small modulus | false equality |
| Hash tables | degraded performance |
| Random IDs / tokens | duplicates |
| Zobrist hashing with too few bits | wrong game analysis |
As a tool
The same threshold makes several algorithms work:
| Algorithm | Uses the collision |
|---|---|
| Pollard’s rho | a random walk mod repeats after steps → factorisation in |
| Pollard’s kangaroo | two walks meet after steps |
| Meet in the middle | from each half, matched by collision |
| Baby-step giant-step | from each side |
| Cryptographic collision attacks | work to break an -bit hash |
Pollard’s rho is the cleanest example: the whole bound is the birthday paradox applied to a walk modulo an unknown prime factor.
Related expectations
| Quantity | Value |
|---|---|
| First collision after | draws |
| All $n$ values seen | draws |
| Expected distinct values after draws | |
| Expected collisions among draws | |
| for at least one specific value | draws expected |
The contrast between (some collision) and (all values seen) is worth internalising — they are the two ends of the same process and differ enormously.
The generalised birthday problem
For a collision among items rather than 2, the threshold is
So a triple collision needs draws — much later than a pair. Wagner’s generalised birthday algorithm exploits this for -sum problems.
Choosing hash parameters
| Distinct items hashed | Minimum safe modulus |
|---|---|
| , want error | → or double hashing |
Combined with a randomised base (against precomputed anti-tests), gives a collision probability of about over comparisons — safely below for any contest input.
The lower bound it implies
Because any algorithm distinguishing possibilities by random sampling needs samples to find a collision, the birthday bound is also a lower bound on generic attacks — which is why an -bit cryptographic hash offers only bits of collision resistance.
See also: Polynomial Hashing · Pollard’s Rho · Probability