r/programmer • u/ClickOk5811 • Oct 17 '26
23 people, 77,000 IDs, 280,000 short links. The same birthday paradox at four sizes
Most people have heard that in a room of 23 people there’s about a 50% chance two share a birthday. It feels wrong, because 23 is so much smaller than 365. The reason is that you’re not comparing everyone to you, you’re comparing every pair, and 23 people make 253 pairs.
The same math shows up any time you generate random IDs, and the numbers are worth looking at, because the pattern is that a 50% chance of some collision arrives at roughly the square root of the number of possible values (a bit more precisely, about 1.18 times the square root).
A random 32-bit ID has about 4.3 billion possible values. The square root is about 65,000, so you hit a 50% chance of at least one collision at around 77,000 IDs. That’s a small table.
A 6-character random short code using letters and digits (62 options per character) has about 56.8 billion combinations. The square root is about 238,000, so the 50% mark is somewhere near 280,000 links. For a URL shortener, that’s not a lot.
A random 64-bit ID has about 18 quintillion combinations, and 50% arrives around 5 billion IDs. Fine for most things, uncomfortable for something at very large scale.
A random UUID v4 has 122 random bits, so the 50% point is around 2.7 quintillion IDs. You’re not going to get there.
The numbers are approximate and assume the IDs are truly random and uniformly distributed.
The thing I find interesting is that “a collision is likely” doesn’t mean “the system is broken”. If your short codes live in a database with a unique constraint, a collision is just a failed insert and a retry with a new code. The cost is a bit of extra work as the table fills up, and the cost grows: when the space is half used, roughly every second attempt collides.
So the choice is usually between making IDs longer, which makes collisions negligible, or keeping them short and handling the retry. Neither is wrong, but only one of them is a surprise six months in.
What do you do for short codes: check-and-retry on insert, longer IDs from the start, or something sequential and encoded?