MathLabs

Combinatorics and discrete mathematics

The pigeonhole principle

If more objects are placed into boxes than there are boxes, some box must contain more than one.

IntuitionWhy must two pigeons share a hole?

Suppose you have 1010 pigeons and only 99 pigeonholes, and every pigeon must fly into some hole. No matter how cleverly the pigeons are placed, at least one hole ends up with two or more pigeons in it — there simply are not enough holes for everyone to get their own. This obvious-sounding fact is called the pigeonhole principle, and despite its simplicity it proves surprisingly deep results across number theory, geometry and computer science.

Network diagram illustrating $10$ pigeon vertices mapped into $9$ hole vertices, with one hole highlighted receiving two edges.
A bipartite network connecting 1010 pigeons to 99 holes: whichever way the edges are drawn, some hole vertex must receive at least two edges, since 10>910 > 9.

SchoolStating the principle precisely

Definition: Pigeonhole principle

If nn objects are placed into kk boxes and n>kn > k, then at least one box contains at least 22 objects. More generally, if nn objects are placed into kk boxes, some box contains at least ⌈n/k⌉\lceil n/k\rceil objects.

n>k ⟹ ∃ box with≥2 objectsn>k\ \Longrightarrow\ \exists\text{ box with}\ge2\text{ objects}

The number ⌈n/k⌉\lceil n/k\rceil ("n/kn/k rounded up") is the smallest integer that is at least n/kn/k; it is the guaranteed minimum load of the fullest box when nn objects are spread as evenly as possible over kk boxes. For example, splitting n=10n=10 objects over k=3k=3 boxes as evenly as possible gives loads 4,3,34,3,3, and indeed ⌈10/3⌉=4\lceil 10/3\rceil=4.

⌈nk⌉=⌊n−1k⌋+1\left\lceil\frac{n}{k}\right\rceil=\left\lfloor\frac{n-1}{k}\right\rfloor+1
How many objects, how many boxes, what is guaranteed
Objects nn / boxes kkGuaranteed minimum in the fullest box
n=10, k=9n=10,\ k=9⌈10/9⌉=2\lceil 10/9\rceil=2
n=13, k=12n=13,\ k=12⌈13/12⌉=2\lceil 13/12\rceil=2
n=100, k=9n=100,\ k=9⌈100/9⌉=12\lceil 100/9\rceil=12
n=k+1, kn=k+1,\ k arbitrary⌈(k+1)/k⌉=2\lceil (k+1)/k\rceil=2

UndergraduateTwo theorems: the basic and the generalized principle

If nn objects are distributed into kk boxes with n>kn>k, then at least one box contains at least 22 objects.

Why is it true?

This is really a statement about counting, proved by assuming the opposite and reaching a contradiction: if every box had at most 11 object, the boxes could not hold more than kk objects in total.

Proof

Assume, for contradiction, that the conclusion fails: every one of the kk boxes contains at most 11 object.

Then the total number of objects distributed is at most k×1=kk\times1=k.

But we distributed nn objects, and n>kn>k by hypothesis, so the total number of objects distributed is n>kn>k.

These two counts of the same set of objects contradict each other (n>kn>k but also total ≤k\le k), so the assumption was false: some box must contain at least 22 objects.

If nn objects are distributed into kk boxes, then some box contains at least ⌈n/k⌉\lceil n/k\rceil objects.

Why is it true?

The basic principle only guarantees 22 objects somewhere; the generalized version sharpens this to the exact minimum forced by averaging nn objects over kk boxes, using the same contradiction idea but comparing against ⌈n/k⌉−1\lceil n/k\rceil-1 instead of 11.

Proof

Assume, for contradiction, that every box contains at most ⌈n/k⌉−1\lceil n/k\rceil-1 objects.

Then the total number of objects distributed is at most k(⌈n/k⌉−1)k\left(\lceil n/k\rceil-1\right).

Since ⌈n/k⌉\lceil n/k\rceil is the smallest integer at least n/kn/k, we have ⌈n/k⌉−1<n/k\lceil n/k\rceil-1<n/k, so k(⌈n/k⌉−1)<k⋅nk=nk\left(\lceil n/k\rceil-1\right)<k\cdot\frac{n}{k}=n.

So the total distributed is strictly less than nn, contradicting that all nn objects were distributed. Hence some box contains at least ⌈n/k⌉\lceil n/k\rceil objects.

UndergraduateReal-world applications and worked examples

Despite its simplicity, the pigeonhole principle is a standard tool in computer science (proving that a hash table with more keys than slots must have a collision), in number theory (proving that some multiple of a given integer has a specific digit pattern), and in everyday combinatorics puzzles about scheduling, sorting and social networks.

Example: Socks in a drawer

A drawer contains socks of 44 colors, with plenty of each color but mixed together in the dark. What is the smallest number of socks you must pull out to be certain of having a matching pair?

Solution

Think of the 44 colors as k=4k=4 boxes, and each sock you pull out as an object dropped into the box matching its color. A "matching pair" means some box receives at least 22 objects.

By the basic pigeonhole principle, once you pull nn socks with n>k=4n>k=4, i.e. n≥5n\ge5, some color box must contain at least 22 socks — a matching pair is guaranteed.

Is 55 actually the smallest such number? With only 44 socks it is possible (though unlucky) to have pulled exactly one of each of the 44 colors, with no pair yet. So 44 socks do not guarantee a pair, but 55 do.

The answer is 55 socks.

Example: Two people at a party with the same number of friends

At a party of n≥2n\ge2 people, "friendship" is mutual and no one is a friend of themselves. Show that there must be two people at the party who have exactly the same number of friends present.

Solution

Each person's number of friends at the party is an integer between 00 and n−1n-1 (you cannot have more friends than the other n−1n-1 people present), giving nn possible values and nn people — pigeonholing the friend-counts directly would only give nn boxes for nn people, not yet a forced collision.

The key extra observation is that the values 00 and n−1n-1 cannot both occur: if someone has 00 friends, no one can have n−1n-1 friends (which would mean being friends with everyone, including that person), and vice versa. So only n−1n-1 distinct friend-counts are actually available: either {0,1,…,n−2}\{0,1,\dots,n-2\} or {1,2,…,n−1}\{1,2,\dots,n-1\}.

Now apply the basic pigeonhole principle with nn people (objects) and at most n−1n-1 possible friend-counts (boxes). Since n>n−1n>n-1, some friend-count box must receive at least 22 people.

Therefore at least two people at the party have exactly the same number of friends present.

If 1313 pigeons fly into 1212 holes, what does the basic pigeonhole principle guarantee?

Using the generalized pigeonhole principle, what is the guaranteed minimum number of objects in the fullest box when n=100n=100 objects are placed into k=9k=9 boxes?

Which everyday situation is a direct application of the pigeonhole principle?

In the party example where friendship is mutual, why can the friend-counts 00 and n−1n-1 not both occur among the nn guests?