How many people do you need to have in a room before it’s more likely than not that at least two of them share the same birthday? As today is my 23rd birthday it’s particularly suitable for a post on this interesting mathematical puzzle – because the answer just happens to be 23.

“Surely not?” is most people’s response, because 23 just seems too low. As there are 365 days in the year, common sense would suggest that you’d need a much higher number of people to give a 50% probability of a shared birthday. The birthday “paradox” isn’t really a paradox, but rather a great illustration of how common sense can let us down.

It works like this. If I’m in a room with 22 other people, that means there are 22 chances that one of them shares my birthday and is also celebrating today. Here’s the catch: the same thing goes for everyone else in the room. That means there are 253 chances in total, because we have (23 x 22)/2 = 253 pairs in the room. The division by two is to avoid counting each pair twice, if you were wondering.

What are the odds that I have a different birthday to just one person? In other words, if I meet someone at random in the street, how likely is it they won’t have been born on 6th April, but some other day instead. If we ignore leap years, and assume that all birthdays are equally likely, there are 364 other days they could have been born on. That means there is a 364/365 chance they don’t share my birthday, which works out around 99.7%. Sounds about right – after all, it’s pretty likely we have different birthdays.

A handy trick often used in these type of calculations is to work out the probability that the opposite of what ever you are interested in happens, and use that to work out the probability that it does.

In this case, we can work out the likelihood that no-one shares a birthday. We already know this figure for one pair, it’s 364/365 as discussed above. To calculate the probability for 253 pairs, we simply multiply this number by itself 253 times.

Reaching for a calculator, we find that (354/365)253 = 0.4995, roughly. That’s the probability that no-one shares a birthday. To find the probability that at least two people do (it could be more) we just subtract this from 1 to get 0.5005, or just over a 50% chance.

You might be wondering how many people you need in a room for a 100% chance of two shared birthdays. That’s more intuitive – with a massive room containing 366 people, you’re guaranteed a match because there are only 365 birthdays! We can however get a 99% chance of a match with only 57 people, using the same method I’ve just described.

With the rise of social networks like Facebook, we can conduct experiments into the birthday paradox quite easily. If you’re logged in, this link should take you to a list of your friend’s birthdays. I’ve got 113 Facebook friends, which means there is a 99.9999996% chance at least two of them share a birthday. Indeed, there are nine shared birthdays, including a four-way share one month ago on 6th March! Not bad. I’m off to eat some cake to celebrate.