In probability theory, the birthday problem asks for the probability that, in a set of randomly chosen people, at least two will share the same birthday. The birthday paradox is the counterintuitive fact that only 23 people are needed for that probability to exceed 50%.
The birthday paradox is a veridical paradox: it seems wrong at first glance but is, in fact, true. While it may seem surprising that only 23 individuals are required to reach a 50% probability of a shared birthday (the number being less than 1/15th of the number of days in a year), this result is made more intuitive by considering that the birthday comparisons will be made between every possible pair of individuals. With 23 individuals, there are pairs to consider.
Real-world applications for the birthday problem include a cryptographic attack called the birthday attack, which uses this probabilistic model to reduce the complexity of finding a collision for a hash function, as well as calculating the approximate risk of a hash collision existing within the hashes of a given size of population.
The problem is generally attributed to Harold Davenport in about 1927, though he did not publish it at the time. Davenport did not claim to be its discoverer "because he could not believe that it had not been stated earlier".David Singmaster, Sources in Recreational Mathematics: An Annotated Bibliography, Eighth Preliminary Edition, 2004, section 8.BH. S. M. Coxeter, "Mathematical Recreations and Essays, 11th edition", 1940, p 45, as reported in I. J. Good, Probability and the weighing of evidence, 1950, p. 38 The first publication of a version of the birthday problem was by Richard von Mises in 1939.Richard Von Mises, "Über Aufteilungs- und Besetzungswahrscheinlichkeiten", Revue de la faculté des sciences de l'Université d'Istanbul 4:145-163, 1939, reprinted in
Calculating the probability
Consider the event that a group of people does not have any repeated birthdays, and let the complementary event be that of a group of people contains at least two people who share a birthday. Then the probabilities and of the two events are related by the equation . The probability can be computed using the perspective of permutations, as follows. Let be the total number of ways that people can have distinct birthdays, and let be the total number of ways people can have birthdays arranged, including possibly repeated birthdays. The probability is the ratio of these two quantities, divided by . When , the two counts are given by
and
their ratio is , and so
Another way the birthday problem can be solved is by asking for an approximate probability that in a group of people at least two have the same birthday. For simplicity, leap years, twins, selection bias, and seasonal and weekly variations in birth rates are generally disregarded, and instead it is assumed that there are 365 possible birthdays, and that each person's birthday is equally likely to be any of these days, independent of the other people in the group.
For independent birthdays, a uniform distribution of birthdays minimizes the probability of two people in a group having the same birthday. Any unevenness increases the likelihood of two people sharing a birthday. However, real-world birthdays are not sufficiently uneven to make much change: the real-world group size necessary to have a greater than 50% chance of a shared birthday is 23, as in the theoretical uniform distribution.
The goal is to compute , the probability that at least two people in the room have the same birthday. However, it is simpler to calculate , the probability that no two people in the room have the same birthday. Then, because and are the only two possibilities and are also mutually exclusive,
Here is the calculation of for 23 people. Let the 23 people be numbered 1 to 23. The event that all 23 people have different birthdays is the same as the event that person 2 does not have the same birthday as person 1, and that person 3 does not have the same birthday as either person 1 or person 2, and so on, and finally that person 23 does not have the same birthday as any of persons 1 through 22. Let these events be called Event 2, Event 3, and so on. Event 1 is the event of person 1 having a birthday, which occurs with probability 1. This conjunction of events may be computed using conditional probability: the probability of Event 2 is , as person 2 may have any birthday other than the birthday of person 1. Similarly, the probability of Event 3 given that Event 2 occurred is , as person 3 may have any of the birthdays not already taken by persons 1 and 2. This continues until finally the probability of Event 23 given that all preceding events occurred is . Finally, the principle of conditional probability implies that is equal to the product of these individual probabilities:
The terms of equation () can be collected to arrive at:
Evaluating equation () gives
Therefore, (50.7297%).
This process can be generalized to a group of people, where is the probability of at least two of the people sharing a birthday. It is easier to first calculate the probability that all birthdays are different. According to the pigeonhole principle, is zero when . When :
where is the factorial operator, is the binomial coefficient and denotes permutation.
The equation expresses the fact that the first person has no one to share a birthday, the second person cannot have the same birthday as the first , the third cannot have the same birthday as either of the first two , and in general the th birthday cannot be the same as any of the preceding birthdays.
The event of at least two of the persons having the same birthday is complementary to all birthdays being different. Therefore, its probability is
The following table shows the probability for some other values of (for this table, the existence of leap years is ignored, and each birthday is assumed to be equally likely):
{| class="wikitable" !!! |- |align=right|1 || 0.0% |- |align=right|5 || 2.7% |- |align=right|10 || 11.7% |- |align=right|20 || 41.1% |- |align=right|23 || 50.7% |- |align=right|30 || 70.6% |- |align=right|40 || 89.1% |- |align=right|50 || 97.0% |- |align=right|60 || 99.4% |- |align=right|70 || 99.9% |- |align=right|75 || 99.97% |- |align=right|100 || % |- |align=right|200 || (100 − )% |- |align=right|300 || (100 − )% |- |align=right|350 || (100 − )% |- |align=right|365 || (100 − )% |- |align=right|≥ 366 || 100%
Approximations
The Taylor series expansion of the exponential function (the constant )
provides a first-order approximation for for :
To apply this approximation to the first expression derived for , set . Thus,
Then, replace with non-negative integers for each term in the formula of until , for example, when ,
The first expression derived for can be approximated as
Therefore,
An even coarser approximation is given by
which, as the graph illustrates, is still fairly accurate.
According to the approximation, the same approach can be applied to any number of "people" and "days". If rather than 365 days there are , if there are persons, and if , then using the same approach as above we achieve the result that if is the probability that at least two out of people share the same birthday from a set of available days, then:
Simple exponentiation The probability of any two people not having the same birthday is . In a room containing n people, there are pairs of people, i.e. events. The probability of no two people sharing the same birthday can be approximated by assuming that these events are independent and hence by multiplying their probability together. Being independent would be equivalent to picking with replacement, any pair of people in the world, not just in a room. In short can be multiplied by itself times, which gives us
Since this is the probability of no one having the same birthday, then the probability of someone sharing a birthday is
And for the group of 23 people, the probability of sharing is
Poisson approximation Applying the Poisson approximation for the binomial on the group of 23 people,
so
The result is over 50% as previous descriptions. This approximation is the same as the one above based on the Taylor expansion that uses .
Square approximation A good rule of thumb which can be used for mental calculation is the relation
which can also be written as
which works well for probabilities less than or equal to . In these equations, is the number of days in a year.
For instance, to estimate the number of people required for a chance of a shared birthday, we get
Which is not too far from the correct answer of 23.
Approximation of number of people This can also be approximated using the following formula for the number of people necessary to have at least a chance of matching:
This is a result of the good approximation that an event with probability will have a chance of occurring at least once if it is repeated times.
Probability table
{| class="wikitable" style="white-space:nowrap;" |- ! rowspan="2" | length of hex string ! rowspan="2" | no. ofbits() ! rowspan="2" | hash spacesize() ! colspan="10" | Number of hashed elements such that probability of at least one hash collision ≥ |- ! = ! = ! = ! = ! = ! = 0.001 ! = 0.01 ! = 0.25 ! = 0.50 ! = 0.75 |- align="center" | bgcolor="#F2F2F2" | 8 | bgcolor="#F2F2F2" | 32 | bgcolor="#F2F2F2" | | 2 | 2 | 2 | 2.9 | 93
|- align="center" | bgcolor="#F2F2F2" | (10) | bgcolor="#F2F2F2" | (40) | bgcolor="#F2F2F2" | () | 2 | 2 | 2 | 47
|- align="center" | bgcolor="#F2F2F2" | (12) | bgcolor="#F2F2F2" | (48) | bgcolor="#F2F2F2" | () | 2 | 2 | 24
|- align="center" | bgcolor="#F2F2F2" | 16 | bgcolor="#F2F2F2" | 64 | bgcolor="#F2F2F2" | | 6.1
|- align="center" | bgcolor="#F2F2F2" | (24) | bgcolor="#F2F2F2" | (96) | bgcolor="#F2F2F2" | ()
|- align="center" | bgcolor="#F2F2F2" | 32 | bgcolor="#F2F2F2" | 128 | bgcolor="#F2F2F2" |
|- align="center" | bgcolor="#F2F2F2" | (48) | bgcolor="#F2F2F2" | (192) | bgcolor="#F2F2F2" | ()
|- align="center" | bgcolor="#F2F2F2" | 64 | bgcolor="#F2F2F2" | 256 | bgcolor="#F2F2F2" |
|- align="center" | bgcolor="#F2F2F2" | (96) | bgcolor="#F2F2F2" | (384) | bgcolor="#F2F2F2" | ()
|- align="center" | bgcolor="#F2F2F2" | 128 | bgcolor="#F2F2F2" | 512 | bgcolor="#F2F2F2" |
The lighter fields in this table show the number of hashes needed to achieve the given probability of collision (column) given a hash space of a certain size in bits (row). Using the birthday analogy: the "hash space size" resembles the "available days", the "probability of collision" resembles the "probability of shared birthday", and the "required number of hashed elements" resembles the "required number of people in a group". One could also use this chart to determine the minimum hash size required (given upper bounds on the hashes and probability of error), or the probability of collision (for fixed number of hashes and probability of error).
For comparison, to is the uncorrectable bit error rate of a typical hard disk.Jim Gray, Catharine van Ingen. Empirical Measurements of Disk Failure Rates and Error Rates In theory, 128-bit hash functions, such as MD5, should stay within that range until about documents, even if its possible outputs are many more.
An upper bound on the probability and a lower bound on the number of people The argument below is adapted from an argument of Paul Halmos.
As stated above, the probability that no two birthdays coincide is
As in earlier paragraphs, interest lies in the smallest such that ; or equivalently, the smallest such that .
Using the inequality in the above expression we replace with . This yields
Therefore, the expression above is not only an approximation, but also an upper bound of . The inequality
implies . Solving for gives