Quant Memo
Core

The Birthday Problem

With only 23 people, there's better than even odds two share a birthday — because the number of pairs to check grows much faster than the number of people, and it's far easier to bound the "no match" probability than the match probability directly.

Prerequisites: How to Attack a Brainteaser

Ask most people how many strangers in a room you'd need before it's more likely than not that two share a birthday, and they guess somewhere near 183 (half of 365). The real number is 23, and the reason for the gap is where an interviewer wants to see you look.

Why the direct approach is the wrong direction

Computing "probability at least one pair matches" directly means summing over every possible way a match could occur — one pair matching, or two pairs, or three, all while everyone else differs — which gets complicated fast. The complement, "no two people share a birthday," is a single clean multiplication, so solve for that and subtract from 1.

Working the complement

Assume 365 equally likely birthdays, no leap years, and nn people. Line the people up one at a time.

  • Person 1 can have any birthday: probability 365/365365/365.
  • Person 2 must avoid person 1's birthday: probability 364/365364/365.
  • Person 3 must avoid both already-taken birthdays: probability 363/365363/365.
  • ...continuing, person nn must avoid the n1n-1 birthdays already taken: probability (366n)/365(366-n)/365.

Multiplying these (they're not independent events, but each conditional probability is exactly this, so the product is exact):

P(no match)=365365364365363365366n365P(\text{no match}) = \frac{365}{365}\cdot\frac{364}{365}\cdot\frac{363}{365}\cdots\frac{366-n}{365}

So P(match)=1P(no match)P(\text{match}) = 1 - P(\text{no match}).

Worked example: n = 23

Multiply out the 23 fractions above. Numerically, P(no match)0.4927P(\text{no match}) \approx 0.4927, so P(match)10.4927=0.5073P(\text{match}) \approx 1 - 0.4927 = 0.5073 — just over 50%, with only 23 people. At n=50n=50 the match probability is already about 97%, and at n=70n=70 it's over 99.9%.

Why it's so much smaller than 183. The number of pairs among nn people is (n2)=n(n1)/2\binom{n}{2} = n(n-1)/2, which grows quadratically. At n=23n=23, that's (232)=253\binom{23}{2} = 253 distinct pairs, each an independent-ish chance to collide — you don't need nn close to 365, you need the pair count to be comparable to 365, and 253 pairs among 365 days is already enough chances for a collision to be likely.

50% n=23 match probability rises steeply, driven by pair count not headcount
The curve crosses 50% at 23 people because the number of pairs, $\binom{23}{2}=253$, is already comparable to the 365 available days.

When "at least one match" is hard to compute directly, compute "no match at all" instead — usually a clean product of shrinking fractions — and subtract from 1. The birthday problem feels surprising only because intuition tracks headcount, while the real driver is the number of pairs, which grows quadratically.

"23 people, 365 days, so about 1-in-16 odds each" is the wrong mental model — it treats pairs as if only one comparison happens. The correct comparison is between the number of pairs and the number of days, not between the number of people and the number of days.

The complement-and-pair-counting habit reappears in hash collision analysis: a hash table with mm slots starts seeing collisions with decent probability once roughly m\sqrt{m} items are inserted, for exactly the same quadratic-pair-count reason as the birthday problem.

Related concepts

Practice in interviews

Further reading

  • Feller, An Introduction to Probability Theory and Its Applications (vol. 1)
ShareTwitterLinkedIn