The Birthday Paradox and Your IDs: How Likely Is a Collision?
Why collisions among random IDs and hashes happen sooner than expected, how to calculate the risk with the birthday bound, and how long IDs should be.

The Birthday Paradox and Your IDs: How Likely Is a Collision?
How many people must be in a room before two probably share a birthday? Most people guess over a hundred. The answer is 23. This surprising result, the birthday paradox, governs every system that relies on random identifiers or hashes: short links, session tokens, file fingerprints, database keys and caches. The free Hash Collision Probability Calculator applies the same maths to your IDs.
Why collisions come so soon
With 23 people there are 253 possible pairs, and each pair has a 1 in 365 chance of sharing a birthday. All those small chances add up quickly. In general, with N possible values, collisions become likely after about the square root of N items, not after N.
That square root is what catches people out. A 32-bit hash has about 4.3 billion possible values, which sounds plenty. Its square root is only 65,536, and a 50% chance of a collision arrives after about 77,000 items.
The formula
For k items drawn at random from N values, the probability of at least one collision is approximately:
p ≈ 1 − e^(−k(k−1) / 2N)
Turned around, the number of items you can create before reaching a chosen risk p is about √(2N × ln(1/(1−p))). The calculator does both directions and handles the huge numbers involved.
How long is long enough?
- 32 bits (CRC-32, short hashes): good for detecting corruption, not for unique identifiers beyond a few thousand items.
- 64 bits: a 50% collision chance after about 5 billion items, adequate for many internal caches.
- 122 bits (random UUID v4): you would need about a billion per second for roughly 86 years to reach a 50% chance of one duplicate.
- 256 bits (SHA-256): collisions are not a practical concern.
Human-friendly codes are much shorter. A 6-digit code has only a million values: with just 1,178 codes issued, there is already a 50% chance two are the same. If codes must be unique, check the database before issuing one.
Choosing an ID
- Estimate how many items you will ever create.
- Choose an acceptable risk: one in a million or one in a billion are common choices.
- Pick a format whose capacity comfortably exceeds the item count at that risk.
- If a duplicate would cause harm, add a uniqueness constraint in the database as a safety net.
Generating at a known rate? The calculator also shows how many days or years it would take to reach the risk level, which turns abstract numbers into something you can judge.
Random versus deliberate collisions
The birthday bound assumes values are truly random and uniform. Weak random generators, truncated hashes and IDs that embed timestamps or counters behave differently. And the calculation covers accidents only. MD5 and SHA-1 can be made to collide on purpose by attackers, so they must not be used for signatures, certificates or anything an attacker can influence.
A worked example
A URL shortener issuing 7-character codes from 62 letters and digits has about 3.5 trillion possible codes. After 2 million links, the chance that two random codes have collided is already about 43%, so the service must check each new code against existing ones. The calculator shows this instantly once you convert the alphabet to bits.
Step by step
- Choose a common ID or hash, or enter the number of random bits.
- Enter the number of items.
- Enter how many you create per second.
- Pick an acceptable collision risk.
- Read the probability, the safe item count and the comparison table.
Privacy
All calculations run in your browser.



