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.

0Guests
0Pairs
0%Chance of a match
An empty room. Invite someone.
Tap any day to mark your own birthday. Drag along the curve to resize the room. Real birthdays are assumed equally likely and 29 February is left out.

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.