In a room of 23 people, why is a shared birthday about 50% likely?
answer
- count pairs, not people
- 23 people make 253 pairs
- complement: all birthdays distinct
- 365/365 x 364/365 x ... x 343/365
- the count grows like n squared
basics
~20 sBecause 23 people form C(23,2) = 253 pairs, not 23 comparisons. The probability that all 23 birthdays differ is (365 x 364 x ... x 343)/365^23, about 0.493, so at least one shared birthday has probability about 0.507.
solid answer
~40 sThe intuition that fails is comparing 23 against 365. What matters is the number of *pairs* who could match, and 23 people form `C(23, 2) = 253` pairs - each with roughly a 1/365 chance of agreeing. Compute the complement: seat people one at a time and require each new birthday to avoid all earlier ones, giving `P(all distinct) = (365/365) x (364/365) x ... x (343/365) = 0.4927`. So `P(at least one match) = 0.5073`, just over half. A good approximation is `1 - exp(-n(n-1)/(2 x 365))`, which makes the `n^2` growth explicit: 50 people reach about 97 percent, 70 people exceed 99.9 percent. Note the contrast with the different question "does anyone share *my* birthday", which needs 253 people for 50 percent.
code
python · 18 linesimport random
def any_shared(n):
seen = set()
for _ in range(n):
b = random.randrange(365)
if b in seen:
return True
seen.add(b)
return False
random.seed(0)
trials = 100000
for n in (10, 23, 40, 50):
hits = sum(any_shared(n) for _ in range(trials))
print(n, round(hits / trials, 3))
# converges on the exact values 0.117, 0.507, 0.891, 0.970go deeper
Be ready to say the number is about 50 percent at 23 people and to explain that matches happen between pairs, so 23 people give 253 chances. Setting up the all-distinct product matters more than finishing the arithmetic.
Derive the falling product 365/365 x 364/365 x ... yourself and explain why complementing is easier than counting matches. Expect the interviewer to immediately ask the 'shares my birthday' variant to see whether you distinguish them.
Show the quadratic scaling and the approximation that produces it, and state the assumptions - uniform, independent days - along with which direction reality pushes the answer. Connecting the result to collision risk in real systems lands well here.
Own the generalisation: whenever items are drawn at random from a finite space, trouble arrives near the square root of that space, not near the space itself. Be ready to say what that implies for sizing identifier spaces and for how much headroom is worth paying for.
## The question being asked "In a room of `n` people, what is the probability that at least two of them share a birthday?" Assume 365 equally likely birthdays, independent across people, and ignore leap days and twins for now. The answer surprises people because they silently substitute a different question - "does someone share *my* birthday?" - which has a completely different answer. ## Why 23 and not 183 The naive instinct is to compare 23 people against 365 days and conclude the chance is small. But a match is a property of a **pair**, and the number of pairs grows quadratically: ``` C(23, 2) = (23 x 22)/2 = 253 pairs ``` 253 opportunities against 365 possible days is no longer a long shot. That single reframing - count pairs, not people - is the whole insight, and it is what an interviewer is listening for. ## The exact computation Directly counting "at least one match" means summing over one match, two matches, triples, and so on. Take the complement instead: **all birthdays distinct**. Seat people one at a time. The first person can have any birthday: `365/365`. The second must avoid one taken day: `364/365`. The third must avoid two: `363/365`. Continuing to the 23rd, who must avoid 22 taken days: `343/365`. ``` P(all 23 distinct) = (365 x 364 x ... x 343)/365^23 = 0.4927 P(at least one match) = 1 - 0.4927 = 0.5073 ``` In the notation of ordered selection this is `P(365, n)/365^n` - the ordered without-replacement count over the ordered with-replacement count. ## A clean approximation Each of the `C(n,2)` pairs matches with probability `1/365`, and the pair events are *nearly* independent. Using `1 - x` is approximately `exp(-x)` for small `x`: ``` P(at least one match) is approximately 1 - exp(-n(n-1)/(2 x 365)) ``` For `n = 23` the exponent is `253/365 = 0.693`, and `exp(-0.693) = 0.500` - which is why 23 is the crossover. The coincidence that `253/365` is almost exactly `ln 2` is the reason the answer lands so close to one half. The same approximation tells you the shape of the curve: the number of people needed for a 50 percent chance scales like `1.18 x sqrt(365)`, roughly the square root of the number of possible values. Doubling the group size roughly quadruples the exponent, so the probability climbs steeply: about 11.7 percent at 10 people, 41.1 percent at 20, 89.1 percent at 40, 97.0 percent at 50, over 99.9 percent at 70. ## The other question "How many people before someone shares *your* birthday with probability 50 percent?" Now only the `n` pairs involving you count, not all `C(n,2)` pairs: ``` 1 - (364/365)^n >= 0.5 => n >= ln(0.5)/ln(364/365) = 252.7 => 253 people ``` The factor of roughly eleven between 23 and 253 is exactly the difference between quadratic and linear growth in the number of relevant pairs. Interviewers frequently ask both in sequence to see whether you noticed they are different questions. ## The assumptions, and what breaks them - **Uniform birthdays.** Real birth dates are not uniform - there are seasonal and day-of-week effects. The important result is directional: **any** departure from uniformity *increases* the probability of a match, because clustering makes collisions more likely. So 0.507 is a lower bound for real populations. - **Independence.** Twins and siblings in the room violate it. - **365 days.** Including 29 February changes the answer only in the fourth decimal place. ## Verifying by simulation This is one of the few probability results where a short simulation is genuinely convincing: draw `n` uniform days, check for a repeat, repeat many times, and watch the frequency converge on the exact value. Running it across several group sizes reproduces the whole curve and makes the quadratic climb visible in a way the formula does not. ## Common mistakes 1. **Reasoning from 23/365** or from "half of 365 is 183". 2. **Answering the "shares my birthday" question** when asked the "any two people" question. 3. **Trying to count matches directly** instead of complementing, then losing track of double-counted multi-match outcomes. 4. **Claiming non-uniform birth dates would lower the probability.** They raise it. ## The compact answer Say "253 pairs, not 23 people", write the falling product over `365^23`, get 0.493 for all-distinct, subtract. If you have time, add the `exp(-n(n-1)/730)` approximation to show where the crossover at 23 comes from.
- How many people are needed before someone shares your specific birthday with 50 percent probability?About 253. Only the n pairs that include you can produce that match, so solve 1 - (364/365)^n >= 0.5, giving n >= 252.7. The jump from 23 to 253 is the difference between C(n,2) pairs growing quadratically and the n pairs involving you growing linearly - and it is why the two questions must not be conflated.
- Where does the approximation 1 - exp(-n(n-1)/730) come from?Each of the C(n,2) = n(n-1)/2 pairs matches with probability 1/365, and the pair events are nearly independent, so the chance of no match is roughly (1 - 1/365) raised to the number of pairs. Since 1 - x is approximately exp(-x) for small x, that becomes exp(-n(n-1)/730). At n = 23 the exponent is 0.693, essentially ln 2.
- Real birth dates are not uniform across the year - does that raise or lower the chance of a match?It raises it. Uniformity spreads people as thinly as possible over the days, which minimises collisions; any clustering into popular dates makes two people more likely to land on the same day. So 0.507 for 23 people is a lower bound for a real population, though the effect is small in practice.
- Why is the complement so much easier here than counting matches directly?Because 'at least one match' is a union of many overlapping cases - one pair matching, two pairs, a triple, and so on - which requires inclusion-exclusion to avoid double counting. 'All distinct' is a single chain of conditions that multiplies out cleanly: each new person must avoid the days already taken.
You are not asking whether your key fits one particular lock. You are asking whether any two of 253 keys happen to match each other, and that is a far busier search.
saying these in an interview costs you the question
- Reasons from 23 out of 365 instead of pair counts
- Answers the 'shares my birthday' question instead
- Says roughly 183 people are needed for 50 percent
- Claims non-uniform birth dates lower the match probability
- Tries to sum match cases instead of complementing