Formula Bro

Math and physics formulas, explained like you are new.


Pigeonhole Principle

In one sentence: If you put more things than boxes into the boxes, at least one box must hold two or more things.

maxjbj≥⌈nm⌉\max_{j}\, b_j \ge \left\lceil \frac{n}{m} \right\rceil

Read it out loud: “The largest number of items in any box is at least the ceiling of n over m. Here n is the number of items, m is the number of boxes, and the ceiling of a number means rounding it up to the next whole number. The letter j names a box, and b sub j is the number of items in box j.”

Before you start

The ideas and signs this page uses, explained from zero. For powers of ten, Greek letters and other notation in general, see Math basics.

Rounding up, the ceiling ⌈x⌉\lceil x \rceil

The ceiling of xx, written ⌈x⌉\lceil x \rceil, is xx rounded up to the next whole number. For example ⌈2.08⌉=3\lceil 2.08 \rceil = 3, because 2.08 rounds up to 3. A whole number is already its own ceiling, so ⌈4⌉=4\lceil 4 \rceil = 4. Rounding down instead is called the floor, and the principle needs the ceiling, not the floor.

Dividing to find an average

A fraction bar means divide. The fraction 2512\frac{25}{12} means 25 items shared among 12 boxes, which is about 2.08 items per box. This is an average: the total divided by the number of groups. The average may not be a whole number, even when every item is a whole item.

Subscripts, like bjb_j

A small letter placed below another letter is a subscript. bjb_j is read ‘b sub j’, and it means the number of items in box number jj. So b1b_1 is the count for box 1, and b2b_2 is the count for box 2. The letter jj is a label, not a number of items.

Maximum, max\max, and at least, ≥\ge

max⁡jbj\max_{j} b_j means the largest value of bjb_j over all the boxes. If three boxes hold 2, 5 and 1 items, the maximum is 5. The sign ≥\ge means ‘greater than or equal to’, so ‘at least 3’ is written ≥3\ge 3, and it is true for 3 and for 4.

Proof by contradiction

A proof by contradiction assumes the opposite of what you want to show, and then finds that the assumption leads to something impossible. Here, if every box held at most 2 items, the total would be at most 24. But there are 25 items, so the assumption must be false.

Hash table and buckets (background)

A hash table stores items by computing a bucket number for each key, using a rule called a hash function. The buckets are the numbered slots. Many buckets can hold items, and some buckets can end up with more than one item. That situation is called a collision.

What each symbol means

SymbolMeaning

max⁡jbj\max_{j}\, b_j

The number of items in the fullest box. The letter jj names a box, and bjb_j is how many items box jj holds. The maximum is taken over all boxes, and the result is a count of items, with no unit.

nn

The number of items being placed into the boxes, a whole number such as 25 members. Each item goes into exactly one box. The count has no unit, because it counts things like people, letters or files.

mm

The number of boxes, a whole number of at least 1 such as 12 months. Some boxes may stay empty. The count has no unit, and it is set before the items are placed.

⌈x⌉\left\lceil x \right\rceil

The ceiling of xx: xx rounded up to the next whole number. For example ⌈2.08⌉=3\lceil 2.08 \rceil = 3 and ⌈4⌉=4\lceil 4 \rceil = 4. The result is a whole number of items, so it has no unit.

The formula piece by piece

nn

The number of items to place. In the club example, n=25n = 25 members. Every item goes into one box, and that is the only rule the principle uses about how the items are placed.

mm

The number of boxes. In the club example, m=12m = 12 months. The principle does not require every box to hold something, so some boxes can stay empty.

nm\frac{n}{m}

The average number of items per box, found by dividing the items by the boxes. For n=25n = 25 and m=12m = 12 it is 2512\frac{25}{12}, which is about 2.08. This average is not a whole number, so it cannot be the count of the fullest box on its own.

⌈nm⌉\left\lceil \frac{n}{m} \right\rceil

The average rounded up to the next whole number. Rounding up, not down, is what the principle guarantees. Since ⌈2.08⌉=3\lceil 2.08 \rceil = 3, the fullest box must hold at least 3 items in the club example.

max⁡jbj\max_{j}\, b_j

The largest count among all the boxes, the count of the fullest box. The principle does not say which box it is, only how big its count must be.

max⁡jbj≥⌈nm⌉\max_{j}\, b_j \ge \left\lceil \frac{n}{m} \right\rceil

In one plain sentence: when nn items go into mm boxes, the fullest box holds at least nn divided by mm, rounded up to the next whole number.

What the formula is doing, and why

What goes in and what comes out. You put nn items into mm boxes. The principle says that the fullest box must hold a certain minimum number of items. That minimum is ⌈nm⌉\lceil \frac{n}{m} \rceil, which is the average nm\frac{n}{m} rounded up. The principle makes this promise without needing to know where each item went.

Why must it be true? Suppose every box held at most ⌈nm⌉−1\lceil \frac{n}{m} \rceil - 1 items, which is one less than the minimum. Then all the boxes together hold at most mm times that number. But ⌈nm⌉−1\lceil \frac{n}{m} \rceil - 1 is less than nm\frac{n}{m}, so the total is less than nn. That leaves some items with nowhere to go, which is impossible. So some box must hold at least ⌈nm⌉\lceil \frac{n}{m} \rceil items.

Why is only one box promised? The rule says nothing about which box is crowded, or how the items got there. It only promises that one box is full enough. That is what makes it useful: you can prove that a repeat or a collision must happen without finding the example itself.

The simplest case and the limits. The simplest case is n=m+1n = m + 1. Then m+1m\frac{m+1}{m} is more than 1 and at most 2, so its ceiling is 2, and some box holds two items. The guaranteed crowding goes up only when nn passes a multiple of mm. If nn is at most mm, the rule guarantees only that one box holds at least 1 item, which says nothing new.

An everyday picture

Think of a coat rack with 4 hooks and 5 coats. Hang every coat on a hook, and at least one hook must carry two coats, because there is no way to avoid it. The average is 54=1.25\frac{5}{4} = 1.25 coats per hook, and rounded up that is 2. You do not have to see which hook is crowded to know that a crowded hook exists.

Worked example: Birthday months in a club

A club has 25 members, and each one has a birthday in one of 12 months. The months are the boxes and the members are the items. The question is: what is the least number of members that the fullest month must hold? The answer is a guarantee, and it does not depend on knowing any real birthdays.

  1. Divide the members by the months. The average per month is 2512\frac{25}{12}. Dividing 25 by 12 gives 2 with 1 left over, which is about 2.08 members per month on average.
  2. Round up to the next whole number. The principle uses the ceiling, which rounds up. So ⌈2.08⌉=3\lceil 2.08 \rceil = 3. Rounding up is what makes the promise hold for every possible arrangement of birthdays, not only for the average one.
  3. Test the opposite idea. Suppose every month held at most 2 members. Then the 12 months together would hold at most 12×2=2412 \times 2 = 24 members in total. This is the opposite of what we want to show, so we test it to see if it can be true.
  4. Compare with the real total. But there are 25 members, and 25−24=125 - 24 = 1 member too many. The assumption that every month holds at most 2 is therefore impossible, so at least one month must hold 3 members.
  5. Notice what the argument did not need. We never looked at any birthday, and we never named a month. The argument works for any club of 25 members with 12 months, so the guarantee holds for every such club.
  6. Notice why rounding down would fail. Rounding 2.08 down gives 2. But a club where every month held at most 2 members would hold only 24 members, one short of 25. So 3 is the value the principle can promise, and 2 is too small.

Answer: The fullest month holds at least 3 members. The principle proves this for any club of 25 people, without knowing a single birthday.

The numbers in this example are recomputed by script every time the site is built.

Common mistakes

Where you will meet it

Questions people ask

Does the principle say which box is crowded?

No. It only proves that some box holds at least ⌈nm⌉\lceil \frac{n}{m} \rceil items. It does not name the box, and it does not say how many boxes are crowded.

Where does the name come from?

The picture is pigeons flying into pigeonholes, which are small compartments in a desk or cabinet. With more pigeons than holes, one hole has to hold two pigeons. Some books call the same rule the drawer principle, for the same reason.

How does it apply to hash collisions?

A hash table with mm buckets that stores n>mn > m keys must have at least one bucket with two or more keys. The collision cannot be avoided once the keys outnumber the buckets.

Sources

  1. Pigeonhole principle, Wikipedia
  2. Floor and ceiling functions, Wikipedia

| All Computer Science formulas |

Published 2026-10-22. Plain-text copy for AI agents and readers: computer-science/pigeonhole-principle.md.