Birthday Paradox Calculator
Calculate the birthday paradox: the chance that at least two people in a group share a birthday, or the smallest group that reaches a target chance. Enter the number of people and the number of days, 365 for birthdays or any whole number for other uses, such as a power like 2^64 for the values of a hash. The calculator shows the chance that all birthdays differ, the chance that someone shares yours, the pairs of people and every step, and it says whether the result is exact.
The birthday problem multiplies fractions until the chance of a match builds up. For a single event that can happen at each try, use the probability of at least one calculator. The number of orderings in the formula comes from the permutation calculator, and the number of pairs of people from the combination calculator.
How many people are in the group, a whole number such as 23
365 for birthdays. Any whole number works, and a power such as 2^64 for the values of a hash
Related Calculators
Probability of At Least One Calculator
Compute the chance an event happens at least once in n tries, or the tries needed to hit a target.
Permutation Calculator (nPr)
Count ordered arrangements with exact nPr and n^r results, with or without repetition.
Combination Calculator (nCr)
Count combinations exactly with big-integer nCr results, even for very large n.
What is the birthday paradox?
The birthday paradox, or birthday problem, asks how large a group has to be before it is more likely than not that two of its members share a birthday. The answer, 23 people, is far smaller than most people expect. That is why it is called a paradox, although nothing in it contradicts anything: it is only surprising.
With 23 people the chance is 50.7297%. With 57 people it passes 99%, and with 366 people it is certain, because a year has only 365 days (leaving out February 29). The same arithmetic answers a more general question: how many values can you draw at random from d possibilities before two of them are likely to be equal? Hash collisions, duplicate IDs and repeated random numbers all follow the birthday problem with d equal to the number of possible values.
How to use the calculator
- Chance of a shared birthday in a group. Enter the number of people n and the number of days d. The result is the chance that at least two of the n people share a birthday.
- People needed for a target chance. Enter the chance you want, in percent, and the number of days. The result is the smallest group that reaches it, with the chance for that group and for one person fewer.
- The days field starts at 365 and takes any whole number of up to 60 digits. Write a power as 2^64 for a 64-bit hash, which has 18,446,744,073,709,551,616 possible values.
- The result is exact while the product of the fractions can be worked out in whole numbers, which is up to 60,000 digits in the denominator. Beyond that the calculator uses a logarithmic form that is accurate to about 13 significant digits, and the steps say which method was used.
- A group size above 9,007,199,254,740,991 people is refused, and so is a target that lies too close to the chances of two neighbouring group sizes for the logarithm to tell them apart. That starts at about 10^13 people. The chance mode still works for such sizes.
The birthday problem formula
q(n) = (d/d) × ((d − 1)/d) × … × ((d − n + 1)/d) = d! / ((d − n)! × dⁿ)
P(at least two share a birthday) = 1 − q(n)
P(someone has your birthday) = 1 − ((d − 1)/d)ⁿ
Pairs of people = n(n − 1)/2
Expected number of shared pairs = n(n − 1) / (2d)
Here n is the number of people and d the number of equally likely days. The first person can have any birthday. The second must avoid the first person's day, which happens with chance (d − 1)/d. The third must avoid two days, with chance (d − 2)/d, and so on. Multiplying gives q(n), the chance that all n birthdays differ, and the chance that at least two match is what is left, 1 − q(n).
q(n) becomes 0 at n = d + 1, because the factor (d − n + 1)/d is then 0. With more people than days two of them must share a day, whatever the birthdays are (the pigeonhole principle).
Shared birthday chance for 365 days
| People (n) | Chance that at least two share a birthday |
|---|---|
| 5 | 2.7136% |
| 10 | 11.6948% |
| 15 | 25.2901% |
| 20 | 41.1438% |
| 23 | 50.7297% |
| 25 | 56.87% |
| 30 | 70.6316% |
| 40 | 89.1232% |
| 50 | 97.0374% |
| 57 | 99.0122% |
| 70 | 99.916% |
| 80 | 99.9914% |
| 90 | 99.9994% |
| 100 | more than 99.9999% (99.99997%) |
| 366 | 100% |
People needed for a target chance (365 days)
| Target chance | People needed |
|---|---|
| 1% | 4 |
| 5% | 7 |
| 10% | 10 |
| 25% | 15 |
| 50% | 23 |
| 75% | 32 |
| 90% | 41 |
| 95% | 47 |
| 99% | 57 |
| 99.9% | 70 |
| 100% | 366 |
Worked example: 23 people and 365 days
Choose Load example to enter 23 people and 365 days. Each new person lowers the chance that all birthdays are still different:
| People (n) | New factor | q(n): all birthdays differ | Chance of a shared birthday |
|---|---|---|---|
| 2 | 364/365 | 0.99726 | 0.274% |
| 3 | 363/365 | 0.991796 | 0.8204% |
| 4 | 362/365 | 0.983644 | 1.6356% |
| 5 | 361/365 | 0.972864 | 2.7136% |
| 10 | 356/365 | 0.883052 | 11.6948% |
| 22 | 344/365 | 0.524305 | 47.5695% |
| 23 | 343/365 | 0.492703 | 50.7297% |
- q(23) = (365/365) × (364/365) × … × (343/365) = 0.492703, so the chance of a shared birthday is 1 − 0.492703 = 0.507297, which is 50.7297%.
- With 22 people the chance is 47.5695%, below one half, so 23 is the smallest group that reaches 50%.
- The chance that one of the 23 people has your birthday is 1 − (364/365)^23 = 6.1151%, far lower, because it needs a match with one particular day.
- There are 23 × 22 / 2 = 253 pairs of people, so 253 / 365 = 0.6932 pairs are expected to share a birthday.
Worked example: how many people for a 90% chance?
Choose People needed for a target chance, enter 90 and 365 days. The calculator multiplies the factors one person at a time and compares each chance with 90% exactly. With 40 people the chance is 89.1232%, still below the target. With 41 people it is 90.3152%, so 41 people are needed. For 99% the answer is 57 and for 99.9% it is 70, so the last few percent cost only a few more people.
Why 23 people are enough
The number of pairs grows much faster than the number of people. A group of n people contains n(n − 1)/2 pairs: 253 pairs among 23 people, 1,225 among 50 and 4,950 among 100. Each pair has the same birthday with chance 1/365, so 23 people already give 253 / 365 = 0.69 expected matching pairs.
The chance of a match is not 253/365 = 69%. Adding up the pair chances counts a group with several matching pairs more than once, and the pairs are not independent: if A and B share a day and B and C share a day, then A and C do as well. The expected number of matching pairs is 0.69, and the chance that there is at least one is 50.7297%. For small groups the chance is close to n(n − 1)/(2d), so it grows with the square of the group size and not in proportion to it.
Someone has your birthday: a different question
The birthday problem asks for a match between any two people. If instead you want someone in the group to match your birthday, each person has only a 1/365 chance, and the chance for n people is 1 − (364/365)^n. That needs 253 people for a 50.0477% chance (with 252 it is 49.9105%) and 840 people for 90%. The calculator shows this chance next to the shared birthday chance so the two are not confused.
Hash collisions and the birthday attack
Choose the number of days d equal to the number of possible values. A hash function with b bits has d = 2^b outputs, and the chance that two of n random outputs collide is the birthday problem with those numbers. A collision becomes likely after about 2^(b/2) values, not 2^b, which is why a 128-bit hash gives only about 64 bits of collision resistance against a birthday attack.
| Bits | Possible values (d) | People for 50% | People for 99% |
|---|---|---|---|
| 16 | 65,536 | 302 | 776 |
| 24 | 16,777,216 | 4,823 | 12,430 |
| 32 | 4,294,967,296 | 77,164 | 198,892 |
| 48 | 281,474,976,710,656 | 19,753,663 | 50,916,405 |
| 64 | 18,446,744,073,709,551,616 | 5,056,937,541 | 13,034,599,789 |
For 128 bits or more the group is beyond what the group size mode can decide, but the chance mode still works: 2^64 values drawn from 2^128 possibilities collide with chance 39.3469%. These numbers are for random values. They say nothing about attacks that exploit the structure of a particular hash function.
Other numbers of days
| Days (d) | Example | People for 50% | People for 99% |
|---|---|---|---|
| 7 | Days of the week | 4 | 7 |
| 12 | Months of the year | 5 | 10 |
| 30 | Days in a month | 7 | 16 |
| 52 | Weeks of the year | 9 | 21 |
| 100 | Two-digit codes | 13 | 30 |
| 366 | Leap-year birthdays | 23 | 58 |
| 1,000 | Three-digit codes | 38 | 95 |
| 1,000,000 | Six-digit codes | 1,178 | 3,034 |
Approximations, and why the calculator does not use them
Two approximations are common. The chance of at least one match is close to 1 − e^(−n(n − 1)/(2d)), and the group size for a chance of one half is close to 1.1774 √d, where 1.1774 is the square root of 2 ln 2. They are good for estimates and for very large d, but they are not exact: for 23 people and 365 days the first gives 50.0002% where the exact chance is 50.7297%, and for 32 bits the second gives about 77,163 where the smallest group is 77,164. The calculator works out the exact value, or the verified logarithmic form for sizes too large for it, and never an approximation.
Assumptions and pitfalls
- Every day is equally likely and the birthdays are independent. Real birthdays are not evenly spread, and twins are not independent. Any uneven spread makes a match more likely, never less, so the figures here are a lower bound for real groups.
- February 29 is left out. With 366 days (choose d = 366) the group for 50% is still 23, and the chance for 23 people becomes 50.6323%.
- "Shared" means any two people, not you. The chance that someone matches your own birthday is much smaller; the calculator shows it separately.
- It is not n/365. The chance of a match is 1 − q(n), which grows with the square of the group size at first and then levels off; it is 50.7297% for 23 people, not 6.3%.
- At least two, not exactly two. The result includes groups with three or more sharing a day and groups with several matching pairs.
Birthday problem in Excel, Python and R
| Tool | Command |
|---|---|
| Excel / Google Sheets | =1-PERMUT(365,23)/365^23 gives 0.507297. It works up to 120 people, because 365^121 is larger than the biggest number these programs can hold. |
| Python | from math import perm; 1 - perm(365, 23) / 365**23 |
| R | pbirthday(23) for the chance and qbirthday(0.5) for the group size; or 1 - prod((365:343)/365) |
Each returns the same answer as the calculator for 365 days. The calculator also handles sizes that overflow a spreadsheet, and it gives the group size for any chance.
Frequently Asked Questions
What is the birthday paradox?
The birthday paradox is the result that a group of only 23 people has a better than even chance, 50.7297%, that at least two of them share a birthday. It is called a paradox because the number is far smaller than most people expect, not because it is contradictory. With 57 people the chance passes 99%, and with 366 people it is certain.
How many people are needed for a 50% chance of a shared birthday?
23 people. With 22 people the chance that at least two share a birthday is 47.5695%, and with 23 it is 50.7297%, so 23 is the smallest group that reaches one half (365 equally likely days).
How do you calculate the birthday problem?
Find the chance q(n) that all n birthdays differ by multiplying (365/365) x (364/365) x (363/365) x ... x ((365 - n + 1)/365), then take 1 - q(n). For 23 people q(23) = 0.492703, so the chance of a shared birthday is 1 - 0.492703 = 0.507297, or 50.7297%.
Why is the birthday paradox so surprising?
Because people compare the group size with the number of days, 23 with 365, when what matters is the number of pairs. A group of 23 contains 23 x 22 / 2 = 253 pairs, and every pair has a 1 in 365 chance of matching, so matches are far more likely than the group size suggests.
What is the chance that someone shares my birthday?
For n other people it is 1 - (364/365)^n. With 23 people it is only 6.1151%, and it takes 253 people to reach 50.0477% and 840 people to reach 90%. This is a different, much harder question than whether any two people in the group match each other.
How many people guarantee a shared birthday?
366 people with 365 possible birthdays, or 367 if February 29 counts as a day. With more people than days, two of them must share a day, whatever the birthdays are. This is the pigeonhole principle.
What is a birthday attack on a hash function?
It is the birthday problem applied to hash values. A hash with b bits has 2^b possible outputs, so a collision between two random inputs becomes likely after about 2^(b/2) hashes. For a 32-bit hash that is 77,164 values for a 50% chance, and for a 64-bit hash 5,056,937,541.
Does the calculator work for more or fewer than 365 days?
Yes. Change the number of days to any whole number of up to 60 digits, or write a power such as 2^64. For example, with 12 months 5 people give a 61.8056% chance of a shared birth month, and with 366 days 23 people give 50.6323%.
Are real birthdays evenly spread over the year?
No. Some months and days have more births than others, and any uneven spread makes a shared birthday more likely than the even-spread calculation says. So 23 people give slightly more than a 50% chance in practice, and the calculated figures are a lower bound for real groups.
When does the calculator give an exact result?
While the number of people times the number of digits of the number of days is at most 60,000, the product is worked out in whole numbers and rounded once at the end, so every digit shown is right. For larger sizes it uses a logarithmic form accurate to about 13 significant digits, and the steps state which method was used.
Embed This Calculator
Add this free calculator to your course page or LMS.
Adjust the height value to fit your page.