Calculate the probability of shared birthdays in a group
Have you ever been in a room with about 20 or 30 people and discovered that two of them share the exact same birthday? It feels like an incredible, mind-blowing coincidence. If you ask most people how many individuals need to be in a room before the chances of a shared birthday hit 50%, they usually guess a pretty high number—maybe around 180, since there are 365 days in a year. In reality, the answer is just 23 people! Because the actual answer is so much lower than our intuition expects, this mathematical quirk is famously known as the Birthday Paradox.
To understand why this happens, we have to look at how our brains process probability. When we are in a room, we naturally think about the chances of someone else sharing our specific birthday. The odds of another person matching you are indeed quite low (1/365). But the paradox doesn't ask if someone shares your birthday; it asks if any two people in the room share a birthday with each other. This shifts the focus from a single person to the total number of pairs you can create within the group.
Think about how fast pairs grow as a crowd gets larger. If you have just 5 people, you can make 10 different pairs. If you have 23 people, you can pair them up in a staggering 253 different ways! Every single one of those 253 pairs is a brand-new opportunity for a birthday match to happen. When you realize that you are checking 253 unique combinations instead of just looking at 23 separate individuals, it makes total sense that a match becomes highly likely.
Mathematically, it is actually much easier to calculate the probability that everyone has a different birthday, and then subtract that from 100%. Imagine the first person enters the room; they can have any birthday. The second person enters, and to keep things unique, they only have 364 available days out of 365. The third person only has 363 days left, and so on. If you multiply all these shrinking fractions together for 23 people, the probability that everyone is completely unique drops to about 49.3%. That means the remaining chance—the probability that at least two people share a day—climbs to 50.7%.
The code in your simulator uses a brilliant shortcut to test this math called a Monte Carlo simulation. Instead of writing out complex formulas, the computer essentially plays a game of pretend. It generates a group of 23 random "birthdays" (numbers from 1 to 365), checks if there is a duplicate, and writes down the result. By running this digital experiment 1,000 times, it counts how many times a match popped up naturally. It is a powerful, real-world way to prove that the crazy math behind the Birthday Paradox works exactly the way scientists predict!