Probability · interview puzzles

The birthday problem: collisions, pairs, and approximations

How can only 23 people have a better than even chance of sharing a birthday? The question asks whether any pair matches, and 23 people create 253 pairs. Counting the complement gives an exact answer; counting pairs explains the scale and leads to a useful approximation.

How fast does a shared birthday appear?

Chance of at least one shared birthday (%)

Independent uniform birthdays across 365 dates; leap day ignored.

Count no collisions first

Assume birthdays are independent and uniformly distributed across d=365d=365 days. With n≤dn\le d people, the first birthday can be anything, the second must avoid one occupied day, the third must avoid two, and so on. Thus

Pr⁡(no match)=∏k=0n−1(1−kd),Pr⁡(at least one match)=1−Pr⁡(no match).\Pr(\text{no match})=\prod_{k=0}^{n-1}\left(1-\frac{k}{d}\right), \qquad \Pr(\text{at least one match})=1-\Pr(\text{no match}).

For n=23n=23, the no-match probability is approximately 0.4927, so the chance of at least one shared birthday is 50.73%. With more than dd people, a match is certain by the pigeonhole principle. These are model results: real birthday frequencies are not exactly uniform, and birthdays within some groups need not be independent.

Why the square root appears

Let CC be the number of matching pairs, including all pairs in a group of three or more. Each pair matches with probability 1/d1/d, and linearity of expectation gives

E[C]=(n2)1d=n(n−1)2d.\mathbb E[C]=\binom n2\frac1d=\frac{n(n-1)}{2d}.

The expected number of matches becomes order one when nn is order d\sqrt d, well before nn approaches dd. For 23 people it is about 0.693. This is not the probability of at least one match: a single outcome can contain several matching pairs.

Taking logs of the exact product and using log⁡(1−x)≈−x\log(1-x)\approx-x for small xx yields

Pr⁡(C≥1)≈1−exp⁡ ⁣[−n(n−1)2d].\Pr(C\ge1)\approx1-\exp\!\left[-\frac{n(n-1)}{2d}\right].

At n=23n=23 this gives approximately 50.0%. Solving the approximation for a 50% collision chance gives n≈2dlog⁡2n\approx\sqrt{2d\log2}, about 22.5 for 365 days. The omitted terms matter more as n/dn/d grows; use the exact product when high precision matters.

A fixed birthday is a different question

Suppose instead that you choose one person’s birthday in advance and ask whether at least one of the other n−1n-1 people shares it. The probability is

1−(1−1d)n−1.1-\left(1-\frac1d\right)^{n-1}.

For 23 people this is about 5.9%, much smaller than 50.7%. The first question allows any pair to match; the second only counts pairs involving the chosen person.

Unequal categories

If independent draws land in category ii with probability pip_i, a particular pair matches with probability ∑ipi2\sum_i p_i^2. Therefore E[C]=(n2)∑ipi2\mathbb E[C]=\binom n2\sum_i p_i^2. Uneven probabilities increase this pairwise collision probability relative to a uniform distribution over the same number of categories. The simple uniform product no longer applies, and substituting an effective category count into the exponential is only an approximation whose accuracy depends on the distribution.

Common mistakes

  • Confusing the expected count of matching pairs with the probability of any match.
  • Multiplying pairwise no-match probabilities as if all pair events were independent.
  • Counting one three-person birthday group as one matching pair: it contains three pairs.
  • Applying the uniform formula to dependent draws or heavily unequal category probabilities without checking the model.

Practice

PairsHow many distinct pairs can be formed from 10 people, and how many matching pairs are created by three people sharing one birthday?
Show answer

There are (102)=45\binom{10}{2}=45 possible pairs. The three-person matching group creates (32)=3\binom32=3 matching pairs.

ScaleIf the number of equally likely categories increases by a factor of 100, about how does the sample size needed for a fixed collision probability change?
Show answer

It grows by roughly a factor of 10, because the threshold scales as the square root of the number of categories.

ExpectationFour independent draws are uniform over 10 categories. What is the expected number of matching pairs?
Show answer

(42)/10=0.6\binom42/10=0.6. This is an expectation, not the probability of at least one collision.

Further reading: MIT OpenCourseWare, The Birthday Principle; Diaconis and Mosteller, Methods for Studying Coincidences.

Related: First-step analysis and the max trick.