MathsStatistics & Probability

Birthday Problem
calculator.

Find how likely a shared birthday is, or how many people it takes to reach your odds.

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.

P(all different)\displaystyle P(\text{all different})=dd×d−1d×⋯×d−n+1d\displaystyle {}= \frac{d}{d} \times \frac{d-1}{d} \times \cdots \times \frac{d-n+1}{d}
P(a match)\displaystyle P(\text{a match})=1−P(all different)\displaystyle {}= 1 - P(\text{all different})

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 n(n−1)2\frac{n(n-1)}{2} pairs as if they were independent.

P(a match)\displaystyle P(\text{a match})≈1−e−n(n−1)2d\displaystyle {}\approx 1 - e^{-\frac{n(n-1)}{2d}}

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.

Open this example in the tool

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.

Open this example in the tool

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.

Open this example in the tool

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.

Questions people ask

Because any two people can match, not only someone and you. Twenty-three people make 253 pairs, each with a small chance, and enough small chances add up. Most people guess far higher because they picture matching their own birthday.

Sources