Birthday Paradox Calculator: Shared Birthday Odds and Hash Collisions
By FindMySum · Last reviewed
The birthday paradox is the surprising fact that in a group of just 23 people, the chance that at least two share a birthday is better than even. This calculator gives that probability for any group size, finds how many people you need for any chance of a match, and applies the same maths to anything with a fixed number of equally likely values, such as hash codes. It opens with the classic example: 23 people and a 50% target.
The formula
Counting matches directly is awkward, because a match could be between any two people, or several pairs at once. The opposite event is simple: everybody has a different birthday. Line the group up and give them birthdays one at a time:
- the first person can have any of the 365 days;
- the second must avoid one day, so has 364 of 365 choices;
- the third must avoid two days: 363 of 365;
- and so on, until person n, who has 365 − n + 1 of 365.
Since the birthdays are independent, the chance that all of them are different is the product:
P(all different) = 365/365 × 364/365 × 363/365 × … × (365 − n + 1)/365
and the chance of at least one shared birthday is:
P(shared) = 1 − P(all different)
With d possible values instead of 365, replace 365 by d. Once n is larger than d, a match is certain.
Worked example: 23 people
For 23 people the product has 23 factors, from 365/365 down to 343/365. Multiplying them gives about 0.4927, so the chance that everyone has a different birthday is 49.27%, and the chance of at least one shared birthday is 1 − 0.4927 = 50.73%. With 22 people the chance is 47.57%, so 23 is the smallest group for better than even odds. These are the calculator's opening figures.
The table under the calculator gives the group size for a range of targets: 10% needs 10 people, 25% needs 15, 50% needs 23, 75% needs 32, 90% needs 41, 95% needs 47, 99% needs 57 and 99.9% needs 70.
Why the answer is so small: count the pairs
The intuition that you need around 183 people comes from thinking about your own birthday. The question is about any two people, and a group of n people contains n(n − 1)/2 pairs. Twenty-three people make 253 pairs. Each pair matches with a chance of 1 in 365, so on average a group of 23 contains 253/365 ≈ 0.69 matching pairs, and the chance of at least one is about half.
This also gives a useful approximation. If each pair matched independently, the chance of no match would be (1 − 1/d)^pairs ≈ e^(−pairs/d), so:
P(shared) ≈ 1 − e^(−n(n − 1)/(2d))
For 23 people that gives 50.0%, very close to the exact 50.7%. Setting the approximation to 50% and solving gives n ≈ 1.18√d: about 22.5 for d = 365. The calculator shows both the exact figure and the approximation.
Matching your own birthday
A different question is the chance that someone shares your particular birthday. Only the n − 1 pairs that include you count, so the chance is 1 − (364/365)^(n − 1). In a group of 23 that is about 5.9%, and you would need 253 other people for a 50% chance. Confusing the two questions is the source of the paradox.
29 February
The calculator's second calendar treats 29 February as one day in four years. Over four years there are 1,461 days, so each ordinary date has a weight of 4/1,461 and 29 February a weight of 1/1,461. The probability that everyone has a different birthday then has two parts: nobody born on 29 February, or exactly one person born on it (two people on 29 February would be a match). The effect is tiny: 23 people give 50.69% instead of 50.73%.
Real birthdays are not uniform
The formula assumes all days are equally likely. Real birth dates are not: in Canada and the United States there are more births in late summer and early autumn, and fewer on public holidays and, since planned deliveries became common, on weekends. Any unevenness makes matches more likely, not less, so the uniform figure is a slight underestimate. For everyday groups the difference is small.
Hash collisions and other uses
The same maths applies whenever items are assigned one of d values at random. Choose "My own number of values" and enter d:
- Hash functions. A 32-bit hash has 4,294,967,296 possible values. A collision becomes more likely than not at 77,164 items, close to the approximation 1.18 × √(2^32) ≈ 77,000. This is why cryptographers say an n-bit hash offers only n/2 bits of collision resistance.
- Random IDs. If a system gives users random six-digit codes (1,000,000 values), two users are likely to share a code after about 1,178 sign-ups.
- Lottery and raffle numbers, birth months (d = 12: five people give a 61.8% chance of a shared month), or anything else drawn from a fixed set.
For very large d and n the calculator switches to a series expansion of the logarithm of the product, which keeps the result accurate to about 15 significant digits.
Assumptions
The calculation assumes values are independent and equally likely (except for the 29 February weighting), and it counts a match of two or more. It does not cover three-way matches, near-matches such as birthdays within a week of each other, or groups with related people such as twins.
More questions
In a classroom of 30, how likely is a shared birthday?
About 70.6%, assuming 365 equally likely birthdays. Teachers often run this as a class experiment: with 30 students a match turns up in roughly seven classes out of ten. With a group of 40, such as two classes together, it rises to about 89.1%.
What is the chance that three people share a birthday?
Much lower than for two. A triple match needs about 88 people before it becomes more likely than not, compared with 23 for a pair. The calculator covers pairs only; triples need a more involved count of the ways people can be grouped.
Do two people on a soccer pitch share a birthday?
A soccer match has 23 people on the field when you count the referee (two teams of 11), which is exactly the group size that gives a 50.7% chance. Studies of World Cup squads, which have 23 players each, have found about half of the squads contain a shared birthday, as the maths predicts.
Why does the chance grow so fast with group size?
Because the number of pairs grows with the square of the group size. Ten people make 45 pairs, 23 make 253 and 50 make 1,225. Each new person can match everyone already in the room, so the chance of no match falls faster and faster.
Is the birthday paradox used in computer security?
Yes. A birthday attack looks for any two inputs that give the same hash output, rather than a match with one particular hash. Because of the birthday effect, finding a collision in an n-bit hash takes about 2^(n/2) attempts instead of 2^n, which is why secure hashes such as SHA-256 have long outputs.
Sources
This article explains how the calculator works and is general information, not financial, tax, legal or medical advice. Rules change; check the sources above or a qualified professional before you act.