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
365233
1 178142
37 0004 500
77 0009 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

SituationConsequence
String hashing with a small modulusfalse equality
Hash tablesdegraded performance
Random IDs / tokensduplicates
Zobrist hashing with too few bitswrong game analysis

As a tool

The same threshold makes several algorithms work:

AlgorithmUses the collision
Pollard’s rhoa random walk mod repeats after steps → factorisation in
Pollard’s kangarootwo 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.

QuantityValue
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 hashedMinimum 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