Updated
In this lesson
Wide tables, equations, and code scroll sideways. Swipe, or Tab to focus them and use the left and right arrow keys.
Birthday problem
You will learn: Count collision opportunities and compare uniform with uneven category probabilities.
Start with: Events and probability
New to the notation? Start with the connected foundation for the underlying definitions and a worked example.
Under independent, uniformly distributed birthdays on 365 calendar days, 23 people are enough for the probability of at least one shared birthday to exceed one half. Leap days, dependence, and unequal day probabilities change the model.
The filled black point is the exact probability; the open blue circle is the simulated frequency at the selected group size. The curve uses the selected day-probability model.
Three different matching questions
| Event or quantity | Value |
|---|---|
| Any pair among n people shares a day | 0.5072972 |
| A designated person matches at least one of the other n−1 | 0.05857133 |
| At least one of n people has calendar day 1 | 0.06115058 |
| Expected number of matching pairs | 0.6931507 |
| Rare-pair approximation: 1 − exp(−expected pairs) | 0.5000018 |
At weight one, all 365 days are equally likely. Larger weights give each of days 1–90 that many times the probability of each remaining day, then normalize all probabilities. This is a synthetic nonuniform model, not measured seasonality. Birthdays remain independent; twins and other dependence are outside this model. An expected pair count is not itself a probability.
Inspect the first simulated group
| Person | Day | People in group with this day |
|---|---|---|
| 1 | 229 | 1 |
| 2 | 1 | 1 |
| 3 | 193 | 1 |
| 4 | 359 | 1 |
| 5 | 354 | 1 |
| 6 | 103 | 1 |
| 7 | 224 | 1 |
| 8 | 264 | 1 |
| 9 | 156 | 1 |
| 10 | 364 | 1 |
| 11 | 167 | 1 |
| 12 | 179 | 2 |
| 13 | 51 | 1 |
| 14 | 148 | 1 |
| 15 | 91 | 1 |
| 16 | 57 | 1 |
| 17 | 179 | 2 |
| 18 | 25 | 1 |
| 19 | 145 | 1 |
| 20 | 280 | 1 |
| 21 | 105 | 1 |
| 22 | 70 | 1 |
| 23 | 16 | 1 |
Why so few
The trick is counting pairs, not people. With n people there are pairs. At n = 23 that’s 253 pairs — 253 chances for a match. Each individual pair has only a 1/365 chance of a collision, but many chances add up fast, although their dependencies mean we cannot multiply 253 independent non-match probabilities.
The formula above just tracks that directly: for each of the n people, the probability their birthday is new given all previous births is . Multiply those together for P(no collision); subtract from 1.
What to notice
- The curve is non-linear — it rises slowly then accelerates. 50% arrives earlier than intuition suggests, 99% by just n = 57.
- The empirical fraction fluctuates across seeded repetitions; its variance is P(1−P)/trials under the simulation model. Raising the trial count reduces Monte Carlo uncertainty.
- This is why hash collisions become likely much sooner than hash-output size implies. For uniform independent 128-bit outputs, the generic collision scale is roughly 2^64 samples. This is a collision-search statement, not a statement that finding a preimage for a specified output takes only 2^64 attempts.
Derive the complement and its approximation
The first person can have any birthday. Conditional on all k previous birthdays being distinct, person k+1 avoids them with probability 1−k/365. Multiplying these conditional probabilities gives the chance that every birthday is distinct. The factors are conditional; they do not assert independence of pair-match events.
For group sizes small relative to 365, using log(1−x) ≈ −x gives:
At n=23, the exact probability is 0.507297 and the approximation is about 0.500002. The expected matching-pair count is 253/365 ≈ 0.693151, which is neither of those probabilities. Groups with three equal birthdays contain three matching pairs but still count as only one group with a collision.
Match anyone, one person, or one day
Among 23 people, the chance that a designated person’s birthday matches any of the other 22 is , far below 0.507297. The chance that at least one of all 23 people was born on a preselected calendar day is . The demo reports these separately.
Make a prediction
With one person, can the any-pair probability be positive?
Explore the answer
No. There is no pair. But the chance of that person having a specified calendar day is 1/365 in the uniform model. At 366 people, a pair is certain under a 365-day model, by the pigeonhole principle.
Unequal birthdays
The weight control creates a synthetic population in which each of days 1–90 is more probable than each remaining day. The weights are normalized, and birthdays remain independent. The exact no-collision probability is n! times the sum of the products of probabilities over every n-day subset. A recurrence evaluates this without enumerating all subsets. The first-group table exposes actual sampled days and multiplicities.
For probabilities p₁,…,p₃₆₅, the expected pair count is . A Poisson-style rare-pair approximation uses that count in 1−exp(−count), but it is not an exact formula for dependent pair indicators. The exact curve is retained to show the approximation’s error.
Make a prediction
Does weighting some days more heavily preserve the famous 23-person threshold?
Explore the answer
Not necessarily. The threshold depends on the complete birthday distribution and independence assumption. Increase the synthetic weight and compare the exact curve at the same group size; the default 23 marker describes only the uniform model.
Reference
Random Services: the birthday problem develops the finite-sampling complement formula. The weighted recurrence, designated-person calculation, and sample table state the specific extensions used here. They do not substitute simulated seasonality for measured birthday data.