Skip to content

Counting

Count the ways to arrange and to choose, and see why 23 people are enough for a shared birthday to be more likely than not.

Helps to know firstWhat probability measures

Helps to know first
This topic

First, the picture

How many people must be in a room before two of them probably share a birthday? Guess, then watch the room fill.

The birthday paradox

People with random birthdays walk into a room (seed 1200); 365 equally likely days.

People walk into a room one at a time, each with a random birthday. A line joins every pair: each pair could share a birthday.

people
0
pairs
0
chance of a shared birthday
0.000

Predict first. How many people must be in a room before two probably share a birthday?

0.00 / 14.49 s
Describe this picture

Two panels, side by side on a wide screen and stacked on a phone. One is a ring where people appear as dots, one at a time, each with a birthday drawn at random (seed 1200). Every pair of people is joined by a faint line, and when two people share a birthday, both dots and their line light up in colour, with the people’s numbers beside them; the room waits a moment after each, and the caption names the pair. In this room, person 20 shares a birthday with person 15, and person 23 with person 22. The other panel is a curve of the exact chance that at least two people share a birthday against the number of people, from 0 to 60, climbing from 0 towards 1, with a dashed level at one half labelled “more likely than not” and a marker at the present count. Before the clip, a question asks how many people it takes for a shared birthday to be more likely than not, with three drawings: about 180, about 60 and about 23; a tap picks one and starts the clip. Your guess is drawn as a dotted vertical line on the curve, or, for 180, as an arrow past the right edge. The clip fills the room to 23 people. Readouts give people, pairs and the chance. After the clip a slider, “People in the room”, sets the number from 2 to 60.

Counting pairs

Most people guess far too high. The answer is 23: in a room of 23 people, a shared birthday is slightly more likely than not, with a chance of 0.507.

The usual mistake is to think about your own birthday: how many people would it take for someone to share mine? That needs a lot of people. But the question is about any two people in the room, and that is a question about pairs.

Watch the lines in the room. With 23 people, each person can pair with 22 others. That counts every pair twice, once from each end, so there are

23×222=253\frac{23\times22}{2}=253

pairs. Each of them is a chance for a shared birthday.

After the clip, drag the number of people and watch the pairs readout. Double the people and the pairs roughly quadruple: 10 people make 45 pairs, 20 make 190, 40 make 780.

To get the exact chance, I need to count carefully. That takes two tools.

The multiplication rule

A bike lock has 4 dials, and you set a code with 4 different digits, 0 to 9. How many codes are there? The first digit can be any of 10. Whatever it was, the second can be any of the 9 left, then 8, then 7:

10×9×8×7=5040.10\times9\times8\times7=5040.

This is the multiplication rule: when a choice is made in steps, and each step has the same number of options whatever came before, multiply the numbers of options.

Arranging all nn things of a set in a row gives n×(n−1)×⋯×2×1n\times(n-1)\times\dots\times2\times1 orders. This product is written n!n! and read ”nn factorial”; 3!=63!=6 and 4!=244!=24. By agreement 0!=10!=1.

Arranging only kk of the nn things, in order, stops the product after kk steps:

n×(n−1)×⋯×(n−k+1)=n!(n−k)!.n\times(n-1)\times\dots\times(n-k+1)=\frac{n!}{(n-k)!}.

The lock’s codes are 10!/6!=504010!/6!=5040.

Order, or no order

Now choose a committee of 3 people from 8. A committee has no first or second member: Ana, Ben, Cai is the same committee as Cai, Ana, Ben.

Count in order first: 8×7×6=3368\times7\times6=336 ordered lists. Each committee of 3 shows up in 3!=63!=6 of them, once for each order of its members. So the number of committees is 336/6=56336/6=56.

The number of ways to choose kk things from nn, when order does not matter, is the binomial coefficient, read ”nn choose kk”:

(nk)=n!k! (n−k)!.\binom{n}{k}=\frac{n!}{k!\,(n-k)!}.

The (n−k)!(n-k)! stops the ordered count after kk steps, and the k!k! removes the orders.

There is a second way to build these numbers. Pick one of the nn people, say Ana. Every committee of kk either includes Ana, and then picks k−1k-1 more from the other n−1n-1, or it leaves Ana out and picks all kk from the other n−1n-1:

(nk)=(n−1k−1)+(n−1k).\binom{n}{k}=\binom{n-1}{k-1}+\binom{n-1}{k}.

Write the numbers in rows, row nn holding (n0)\binom{n}{0} to (nn)\binom{n}{n}, and each number is the sum of the two above it. This is Pascal’s triangle.

111121133114641151010511615201561
Fig. Pascal’s triangle, rows 0 to 6. Each number is the sum of the two above it, as 4 + 6 = 10. Row n lists n choose k for k = 0 to n: row 4 says there are 6 ways to choose 2 things from 4.

In signal processing · repeated convolution

Row nn of the triangle holds the coefficients of (1+z)n(1+z)^n: (1+z)2=1+2z+z2(1+z)^2=1+2z+z^2. Each row is the row above convolved with [1,1][1,1], the “add the two above” rule written as a convolution. Sums of random variables uses the same step to add dice.

The birthday product

Back to the room. I assume every person’s birthday is one of 365 days, each as likely as the others, and that nobody’s birthday depends on anyone else’s. So I ignore 29 February and twins.

Line the kk people up and write down their birthdays in order. By the multiplication rule there are 365k365^k such lists, all equally likely. In how many do all the birthdays differ? The first person can have any of 365 days, the second any of the other 364, and so on:

365×364×⋯×(365−k+1).365\times364\times\dots\times(365-k+1).

The chance that no two of the kk people share a birthday is the share of lists with all birthdays different:

Pr⁡{no match}=365365⋅364365⋯365−k+1365=∏r=0k−1365−r365.\Pr\{\text{no match}\}=\frac{365}{365}\cdot\frac{364}{365}\cdots\frac{365-k+1}{365}=\prod_{r=0}^{k-1}\frac{365-r}{365}.

The symbol ∏\prod means “multiply together”, as ∑\sum means “add together”. By the complement rule of What probability measures, the chance of at least one shared birthday is 1−Pr⁡{no match}1-\Pr\{\text{no match}\}.

For 23 people this is 0.507, and for 22 it is 0.476. So 23 is the smallest room where a shared birthday is more likely than not.

A check with pairs. Each of the 253 pairs shares a birthday with chance 1/3651/365. So over many rooms of 23, there are on average 253/365=0.69253/365=0.69 shared pairs per room, close to one. If the pairs could not affect each other, the chance that none of them matched would be (364/365)253=0.4995(364/365)^{253}=0.4995, a match chance of 0.50050.5005. That is close to the exact 0.507; the pairs share people, so they are not quite separate.

Worked example

1. Codes. A code of 4 different digits: 10×9×8×7=504010\times9\times8\times7=5040 codes. Allow repeated digits and every dial has 10 options: 104=10 00010^4=10\,000 codes.

2. A lottery. Choose 6 numbers from 1 to 49; the order of the draw does not matter.

(496)=49×48×47×46×45×446!=13 983 816.\binom{49}{6}=\frac{49\times48\times47\times46\times45\times44}{6!}=13\,983\,816.

One ticket wins with chance 1/13 983 816=7.15×10−81/13\,983\,816=7.15\times10^{-8}, about one in 14 million.

3. Rooms of different sizes. The birthday product, worked out for a few rooms:

PeoplePairsChance of a shared birthday
5100.0271
10450.1169
222310.4757
232530.5073
5012250.9704
5715960.9901

With 57 people a shared birthday is 99 % likely. It becomes certain only at 366 people: with 366 people and 365 days, two must share.

Try it yourself. A poker hand is 5 cards from 52, with order not mattering. There are (525)=2 598 960\binom{52}{5}=2\,598\,960 hands.

Where you’ll meet this

Hash collisions. A computer often files items by a short code computed from each one, a hash. A 32-bit hash has 2322^{32}, about 4.3 billion, possible codes. By the same count as for birthdays, two items are more likely than not to share a code after only about 77 000 items. Programs that rely on hashes are designed for that, not for the 4.3 billion.

The rule of thumb behind this works for any number of codes: a shared code becomes likely once the number of pairs reaches about 0.693 times (that is, ln⁡2\ln 2 times) the number of codes. For birthdays that is 0.69×365=2530.69\times365=253 pairs, 23 people.

Lotteries, codes and passwords. The size of a lottery, a PIN or a password space is a count by the multiplication rule or a binomial coefficient. Each extra character multiplies the number of passwords an attacker must try.

Choosing teams and samples. The number of ways to pick a team, a jury or a survey sample is a binomial coefficient. It returns in Discrete random variables, where it counts the ways to get kk heads in nn flips.

Reference card

QuantityFormulaNotes
Multiplication rulemultiply the options at each stepsame number of options whatever came before
All nn in a rown!=n(n−1)⋯1n!=n(n-1)\cdots10!=10!=1
kk of nn, in ordern!/(n−k)!n!/(n-k)!codes with different digits
kk of nn, no order(nk)=n!/(k!(n−k)!)\binom{n}{k}=n!/(k!(n-k)!)committees, hands, tickets
Pascal’s rule(nk)=(n−1k−1)+(n−1k)\binom{n}{k}=\binom{n-1}{k-1}+\binom{n-1}{k}each entry is the sum of the two above
Pairs among kk(k2)=k(k−1)/2\binom{k}{2}=k(k-1)/2253 for 23 people
No shared birthday among kk∏r=0k−1(365−r)/365\prod_{r=0}^{k-1}(365-r)/365shared: one minus this; 0.507 at 23

Keep reading with a free account.

By creating an account you accept the terms of use.

Sign in

Already have an account? Use the service you signed up with.

Or keep reading: get new lessons by email

Are you 13 or over?

Accounts and email updates are for people aged 13 or over. We keep only your answer, never your date of birth.

End of the lesson

Where to go next.

Phasorium

Account

Sign inKeep your place on any device

Subjects

Site

Look