Works on this device
Pigeonhole Principle Calculator
The pigeonhole principle says: if you put more items than boxes into the boxes, some box holds at least two. This calculator works out the numbers for that idea and its general forms, and it writes out the worst case step by step.
Enter your values
Check these values
Your values are worked out in this browser. They are not sent to a server.
Your result will show here
Fill in the values, then choose Calculate.
Your result
How it was worked out
How to use this calculator
- Choose what you want to find in the first menu.
- Enter the numbers. A box (pigeonhole) is a group that an item (pigeon) falls into, such as a month, a colour or a suit.
- You can pick a classic example from the menu above the fields and then change its numbers.
- Choose Calculate. The result shows the answer, the formula with your numbers, the reasoning in steps and a table of the worst case.
The formulas
- Items that force k in one box: with m boxes you need m × (k − 1) + 1 items. With m × (k − 1) items it can still be avoided.
- The most that some box must hold: n items in m boxes put at least ⌈n ÷ m⌉ items in some box. The signs ⌈ ⌉ mean: round up to a whole number. Some box also holds at most ⌊n ÷ m⌋, which is n ÷ m rounded down.
- Boxes with different limits: if box 1 may hold q1 items, box 2 may hold q2 and so on, then q1 + q2 + … + 1 items force some box to pass its limit. With targets a1, a2, … in place of limits, (a1 − 1) + (a2 − 1) + … + 1 items force some box to reach its target.
- Draws from a drawer: to be sure of k things of the same kind, add up the smaller of (k − 1) and the number of each kind, and add 1. To be sure of k different kinds, add up the largest k − 1 kinds and add 1.
- Most boxes: n items still force k in one box when there are at most ⌊(n − 1) ÷ (k − 1)⌋ boxes.
Worked examples
Birth months. There are 12 months. To be sure that two people in a room were born in the same month you need 12 × (2 − 1) + 1 = 13 people. With 12 people every month can be different.
Birthdays. A year has at most 366 days, with 29 February. So 366 × 1 + 1 = 367 people are sure to have two with the same birthday.
A class. 30 pupils and 12 months: 30 ÷ 12 = 2 with 6 left over, so at least 3 pupils share a birth month.
Socks. A drawer holds 10 black, 6 white and 4 grey socks. For a matching pair you take min(10, 1) + min(6, 1) + min(4, 1) + 1 = 4 socks. For one sock of every colour you take 10 + 6 + 1 = 17 socks, because the first 16 could all be black or white.
Buses. Three buses have 40, 52 and 30 seats. With 40 + 52 + 30 + 1 = 123 people, some bus has more people than seats.
Hairs on heads. Here you need two figures of your own. As an example only: if a town has 1,000,000 people and nobody has more than 150,000 hairs, there are 150,001 possible numbers of hairs (0 to 150,000). Then ⌈1,000,000 ÷ 150,001⌉ = 7, so at least 7 people have the same number of hairs. Change both figures to the ones you want to assume.
Limits you should know
- The tool gives what is certain, not what is likely. Two people in a group of 23 often share a birthday, but only 367 people make it sure. For chances, use a probability calculator.
- It counts whole items and whole boxes, each up to 1,000,000,000,000,000. All results are exact whole numbers.
- The table of boxes with limits and the table of kinds take up to 60 rows.
- Figures about the real world in the examples, such as people in a town or hairs on a head, are example assumptions. They are not facts given by this tool.
- It does not write a proof for a problem in words. You choose what the boxes and the items are.