Lambdia

23 People Make a Shared Birthday a Coin Flip, and 253 Pairs Explain It

The reflex answer is around 180, half the calendar. The real threshold is 23, because a match needs a pair and 23 people carry 253 of them. The same reasoning puts the answer to "does anyone share MY birthday" at 253 people, eleven times the crowd, and the square-root threshold behind both is why a 64-bit random id collides after five billion draws rather than eighteen quintillion.

Put people in a room one at a time and stop when two of them share a birthday. How many do you need before that is more likely than not?

The number almost everyone reaches for is somewhere near 180, on the reasoning that there are 365 days and you want to cover half of them. The answer is 23. Not 23 as a curiosity: 23 people give a shared birthday probability of 0.50730.5073, and 22 people give 0.47570.4757, so 23 is exactly where the bet turns.

You are counting pairs, and pairs grow fast

The reflex answer counts people. The question counts pairs of people, because a match needs two of them, and the number of pairs grows like the square of the headcount.

(232)  =  23×222  =  253.\binom{23}{2} \;=\; \frac{23 \times 22}{2} \;=\; 253.
(1)

Two hundred and fifty three separate chances to collide, in a room of 23. Against 365 days that no longer sounds like a long shot, and it is not.

Fig. 1 — The same 23 people, two questions. Any pair matching draws 253 chords; matching one named person draws 22.

The exact number, with no approximation

Work with the complement, which is the only sane way in. Line the people up and demand that each new birthday miss all the earlier ones. The second person has 364 days available out of 365, the third has 363, and so on:

P(all distinct)  =  i=0k1365i365  =  365!365k(365k)!.P(\text{all distinct}) \;=\; \prod_{i=0}^{k-1}\frac{365-i}{365} \;=\; \frac{365!}{365^{k}\,(365-k)!}.
(2)

At k=23k = 23 that product is 0.49270.4927, so a match has probability 0.50730.5073. Push on and the curve gets steep fast: 57 people reach 99%99\%, and by 70 the chance of everyone being distinct is under one in a thousand.

For a number you can produce without a calculator, take logs and use ln(1x)x\ln(1-x) \approx -x:

lnP(all distinct)    i=1k1i365  =  k(k1)730,P(match)    1ek(k1)/730.\ln P(\text{all distinct}) \;\approx\; -\sum_{i=1}^{k-1}\frac{i}{365} \;=\; -\frac{k(k-1)}{730}, \qquad P(\text{match}) \;\approx\; 1 - e^{-k(k-1)/730}.

At k=23k = 23 the exponent is 506/730=0.693-506/730 = -0.693, which is ln2-\ln 2 to three decimals, so the estimate lands on 1/21/2 on the nose. That is the version to say out loud in an interview, because it shows where the half comes from instead of quoting it.

The threshold sits at the square root

Setting the exponent to ln2-\ln 2 and solving for kk generalises the whole thing. With nn equally likely slots rather than 365:

k1/2    2nln2  =  1.1774n,k_{1/2} \;\approx\; \sqrt{2 n \ln 2} \;=\; 1.1774\,\sqrt{n},
(3)

which gives 22.4922.49 for n=365n = 365, rounding up to the 23 the exact product produced. The useful part is the shape, not the constant. Half a set is never the threshold. The square root of it is.

The rule to remember

Distinctness survives to about n\sqrt{n} draws and collapses shortly after. Anything that has to stay unique across many draws needs a space quadratic in the number of draws, not linear.

Matching me is a different question, and it needs 253 people

Ask instead how many people you need before someone shares your birthday. Now you are the fixed point, and only the 22 chords touching you in the figure count. Each person misses you with probability 364/365364/365:

1(364365)k    12k    ln2ln(364/365)  =  252.65,1 - \left(\tfrac{364}{365}\right)^{k} \;\ge\; \tfrac12 \quad\Longleftrightarrow\quad k \;\ge\; \frac{\ln 2}{-\ln(364/365)} \;=\; 252.65,
(4)

so 253 people. Eleven times the crowd, for a question that sounds like the same one.

The 253 turning up twice is not a coincidence, and spotting why is the mark of someone who understood rather than memorised. Both questions ask for the expected number of favourable pairs to reach ln2\ln 2. For the open question that expectation is (k2)/365\binom{k}{2}/365, which needs (k2)=253\binom{k}{2} = 253 pairs. For the question about you it is k/365k/365, which needs k=365ln2=253k = 365 \ln 2 = 253 people. The same 253 appears once as a count of pairs and once as a count of people, and the factor of eleven between the answers is the distance between those two sentences.

Where this stops being a party trick

The square root shows up wherever identifiers are handed out at random and assumed unique. With NN possible values and kk draws, the chance of a repeat is about k2/2Nk^2/2N, so trouble starts near N\sqrt{N} and not near NN.

A 64-bit random order ID has 1.8×10191.8 \times 10^{19} values, which sounds untouchable, and reaches an even chance of a duplicate at 5.1×1095.1 \times 10^{9} ids. A busy venue can print five billion ids in a few years. A random UUID carries 122 random bits and holds out to 2.7×10182.7 \times 10^{18}, which is why it is the safe choice and the 64-bit shortcut is not.

The same halving is why a hash with a bb-bit output only offers b/2b/2 bits of collision resistance. A 128-bit digest falls to a birthday attack at around 2642^{64} work, which is the reason 128-bit hashes stopped being acceptable for signatures while 128-bit keys stayed fine. The room with 23 people in it is the same calculation, wearing a hat.

Sources and further reading

  1. Birthday problemthe exact product, the approximations, and the tables
  2. Birthday attackthe b/2 rule for hash collision resistance
  3. M. Klamkin and D. Newman, “Extensions of the birthday surprise”, JCTA 3 (1967), 279–282the general square-root threshold and its variants
  4. Universally unique identifierthe 122 random bits behind the UUIDv4 figure

Comments · 0

Be the first to comment.