Maths

Why 23 people are enough for two to share a birthday

30seconds
The 30-second version

Put 23 people in a room and there's a better-than-even chance that two of them share a birthday. That sounds wrong, because 23 is tiny next to 365.

The catch is that nobody is being compared with you. Everyone is compared with everyone, and 23 people make 253 pairs. Each pair is a small chance of a match, and those small chances pile up fast. Fill a room yourself and watch the coincidences appear.

Deep dive · 4 min
Deep dive · 4 min

Here's a party trick that works better than it should. At a gathering of 23 people, bet that two of them share a birthday. You'll win slightly more often than you lose. Most people guess you'd need something like 180 guests, about half of 365. The real number is far smaller because of what you're actually counting.

Fill the room

Invite guests one at a time. Each lands on a random day of the year. When two share a day, it lights up.

You're counting the wrong thing

The gut feeling goes like this: my birthday is one day out of 365, so I'd need a huge crowd before someone matches me. That reasoning is right, but it answers a different question. The puzzle doesn't ask whether someone matches you. It asks whether any two people match.

That's a comparison between every possible pair. With 23 guests, the first can be paired with 22 others, the second with 21 new ones, and so on. That adds up to 23 × 22 ÷ 2 = 253 pairs. Each pair has only a 1-in-365 chance of matching, but you get 253 goes at it. The number of pairs grows roughly with the square of the crowd, so doubling the room roughly quadruples the chances for a coincidence. Watch the pairs counter above: it runs away from the guest count almost immediately.

The maths in one line

It's easiest to work out the chance that nobody matches, then flip it. The second guest avoids the first with probability 364/365. The third must avoid two taken days: 363/365. Keep going and multiply:

P(no match) = 365/365 × 364/365 × 363/365 × … × (365 − n + 1)/365

Each factor is close to 1, but there are a lot of them. For 23 people the product dips to about 0.493, so the chance of at least one shared birthday is about 50.7%. From there it climbs quickly:

People in the roomChance two share a birthday
10about 12%
20about 41%
2350.7%
30about 71%
50about 97%
5799%
7099.9%

A school class of 30 has a better than two-in-three chance. At 70 people, a room with no shared birthday would be a genuine surprise.

Your own birthday is a different story

Now ask the question your gut was answering. In that room of 23, what's the chance that someone shares your birthday? Only your 22 pairings count now, not all 253. The chance is 1 − (364/365)22, about 6%. To get even odds that someone matches you, you'd need 253 other people. Tap your birthday on the calendar above and fill the room: you'll see plenty of matches that don't involve you at all.

Real birthdays make it even likelier

The calculation assumes every day is equally likely. Real births aren't spread evenly: some months and weekdays are busier than others. Uneven odds can only make matches more likely, because people crowd onto the popular days. The effect is small, and in practice 23 is still where the odds pass 50%.

Football offered a neat real-world test. The 2014 World Cup had 32 squads of exactly 23 players. Of those, 16 squads had at least one pair of team-mates sharing a birthday, and 5 of them had two pairs. Half the squads, just as the maths predicts.

Why computers care

The same arithmetic haunts computer security. Programs often squeeze files or passwords down to short fingerprints called hashes. If two different inputs ever produce the same fingerprint, that's a collision, and it can be exploited. The birthday effect means collisions show up far sooner than the number of possible fingerprints suggests: with N possible values, you expect a repeat after roughly √N tries. A 64-bit fingerprint has about 18 quintillion values, yet a collision becomes more likely than not after only about 5 billion random inputs. Attacks that exploit this are called birthday attacks, which is why secure hashes are made much longer than you might think they need to be.

Who spotted it

The number theorist Harold Davenport is said to have come up with the puzzle around 1927 but never published it. The first known published version came from the mathematician Richard von Mises in 1939. It has been catching out dinner guests, maths students and security engineers ever since, for the same reason each time: we count the people, when we should be counting the pairs.

More in Maths

View all →
Why a treatment can win in every group and still lose overall: Simpson's paradox Treatment B beats Treatment A overall, yet A wins for small stones and for large stones. That is Simpson's paradox, and it is real data from a kidney-stone… Maths4 min read Why no walk can cross all seven bridges of Königsberg once: Euler's odd-places rule Seven bridges, two islands, two river banks: in 1700s Königsberg nobody could find a walk crossing each bridge exactly once. Euler didn't search harder, he… Maths4 min read Why sunflower seeds never leave gaps: the golden angle and the Fibonacci spirals Sunflower seeds are not placed in spirals on purpose. Each new seed turns a fixed angle from the last, and only one angle, about 137.5 degrees, leaves no bare… Maths4 min read Why random dice rolls draw a perfect fractal: the chaos game and the Sierpiński triangle Pick three dots, then keep jumping halfway towards a randomly chosen one. It sounds like it should leave a grey smudge, but after a few thousand jumps a… Maths3 min read Why a dropped stick can find π: Buffon's needle Drop a stick on a floor of planks and count how often it lands across a seam. The count secretly contains π: for a needle as long as the plank width, the… Maths4 min read Why 23 people are enough for a shared birthday: counting pairs, not people Put 23 people in a room and the chance that two share a birthday is already 51%. It feels far too low a number, because we picture one person matching our… Maths3 min read