Birthday Problem
calculator.
Find how likely a shared birthday is, or how many people it takes to reach your odds.
- All different
- 49.27%
- Pairs to compare
- 253
- Someone matches you
- 5.86%
23 people make 253 pairs, and each pair has a 1 in 365 chance of matching. Together that gives 50.73%, against 5.86% that someone matches one particular person.
How the chance grows
The chance that any two match passes 50% at 23 people and 99% at 57. The chance that someone matches one particular person grows far more slowly: 5.86% at 23. The tables below give the same figures.
Working
- 1Chance that everyone is different365 × 364 × … × 343365²³= 0.4927
- 2Take it away from 1 for at least one match1 − 0.4927 = 0.5073
- 3Count the pairs23 × 222= 253
- 4Matching pairs you can expect253365= 0.693
- 5Check: multiply the fractions one at a timeProduct 0.4927, and 1 − 0.4927 = 0.5073
Any two, or someone matching you
For even odds that someone matches you, you need 253 others, against 23 people for any match.
The two lines answer different questions. Most guesses about this problem answer the second one.
Chance at each group size
| Group | Exact | Approx. |
|---|---|---|
| 6 | 4.05% | 4.03% |
| 12 | 16.7% | 16.54% |
| 17 | 31.5% | 31.11% |
| 23 | 50.73% | 50% |
| 29 | 68.1% | 67.12% |
| 35 | 81.44% | 80.41% |
| 46 | 94.83% | 94.13% |
| 58 | 99.17% | 98.92% |
| 69 | 99.9% | 99.84% |
| 92 | 99.999652% | 99.998955% |
Group needed for each chance
| Chance | Group size |
|---|---|
| 50% | 23 |
| 75% | 32 |
| 90% | 41 |
| 99% | 57 |
| 99.9% | 70 |
How it's worked out
Work out the chance that nobody matches, then subtract it from 1. The first person can have any birthday. The second must avoid one day, the third must avoid two, and so on. The standard result multiplies those fractions together.
Here n is the size of the group and d is the number of equally likely values, 365 for birthdays. Once n is larger than d, a match is certain, because there are more people than days to go round. This is the pigeonhole principle.
Multiplying thousands of fractions by hand is slow, so a short form is common. It treats the pairs as if they were independent.
For 23 people this gives 50%, a little under the exact 50.73%. The short form gets closer as d grows, so it is nearly exact for hash outputs. The tool adds logarithms of each fraction rather than multiplying, so very large groups do not overflow.
Worked examples
Ms. Okafor bets on her class of 30
Ms. Okafor tells her class of 30 that two of them probably share a birthday. Thirty students form 435 pairs. The chance that all 30 differ is 29.37%, so the chance of a match is 70.63%.
Multiplying the 30 fractions one at a time gives 29.37% for all different, which agrees. If a student asks instead whether someone matches them in particular, the chance falls to 7.65%, because that student is in only 29 of the pairs.
A shop checks its 4-digit PINs
A shop gives each customer a random 4-digit PIN, so there are 10,000 possible values. It takes only 119 customers for even odds that two hold the same one. At 119 the chance is 50.58%, and one customer fewer gives 49.99%.
That assumes the PINs are random. When people choose their own, they pick some numbers far more often, so a real match comes sooner than this.
Dana picks a size for random IDs
Dana hands out random 32-bit IDs. There are 4,294,967,296 possible values, yet 77,164 IDs give 50% odds of a clash. That is close to the square root of the number of values, as the standard result predicts.
Moving to 64 bits pushes even odds out to about 5.06 billion IDs. Each extra 2 bits of ID size only doubles the number of IDs she can hand out at those odds.
Reading your result
Count pairs, not people. A room of 23 sounds small against 365 days, but it holds 253 pairs, and any pair can match. That is why the chance climbs from 47.57% at 22 people to 50.73% at 23, and reaches 99.01% at 57.
Keep the two questions apart. The chance that someone matches you grows far more slowly. At 23 people it is 5.86%, since you take part in only 22 comparisons. Even odds on your own birthday take 253 other people, and 99% takes 1,679.
Treat the answer as a floor for real groups. Berresford's 1980 note gives the proof, after Munford, that the chance of a shared birthday is lowest when every day is equally likely. Any real pattern of births can only raise it, so 23 people are enough however births are spread.
The expected number of matching pairs is a different figure. With 23 people you can expect 0.69 matching pairs. It can pass 1 only when a match is already likely, and it does not stop at 1, because a group can hold several.
Common mistakes
- Dividing by 365 once for the whole group. Taking 23 over 365 gives about 6.3%. That counts people against days, and it leaves out the pairs that do not include you.
- Adding the pair chances. Adding 253 chances of 1 in 365 gives more than the exact answer, and past 365 pairs it would pass 100%. Multiply the "no match" fractions instead.
- Using it on people who are not independent. A room with twins, or a school year where everyone was born within 12 months, breaks the model in the direction of more matches.
- Forgetting the number of values. Birth months and PINs use the same formula with 12 or 10,000 in place of 365. Leaving 365 in gives odds that are far too low.