📪

Pigeonhole Principle Calculator

Generalized Formula · Step-by-Step Proof · Classic Examples

Find the minimum items needed to guarantee at least m items share the same container. Uses the generalized pigeonhole formula k(m−1)+1 or ceiling ⌈n/k⌉.

Choose Calculation Mode

Mode 1: Given the number of containers (k) and the guarantee threshold (m), find the minimum total items needed so that at least one container holds m or more items. Formula: k(m−1) + 1

Quick Examples

Quick Reference — Classic Pigeonhole Examples

Click any card to auto-fill the calculator with that scenario.

Cards & Suits
k=4, m=2 → 5
5 cards from a deck guarantee 2 of the same suit
Birthdays (Month)
k=12, m=2 → 13
13 people guarantee 2 born in the same month
Same Weekday
k=7, m=2 → 8
8 people guarantee 2 born on the same day of the week
Matching Socks
k=5, m=2 → 6
With 5 sock colors, grab 6 to guarantee a matching pair
Birthday (Day)
k=366, m=2 → 367
367 people guarantee 2 share the exact same birthday
3 Share Birthday
k=366, m=3 → 733
733 people guarantee 3 share the exact same birthday

What Is the Pigeonhole Principle?

The pigeonhole principle — also known as Dirichlet's box principle or the drawer principle — is one of the most elegant and broadly applicable theorems in combinatorics and discrete mathematics. In its simplest form it states: if n items are placed into k containers and n > k, then at least one container must hold more than one item.

The name evokes a classic image: if you have 10 pigeons and only 9 pigeonholes (the compartmented wall-mounted boxes historically used to sort mail), at least one pigeonhole must contain 2 or more pigeons. Despite its apparent simplicity, the principle underlies surprisingly deep results in number theory, graph theory, and computer science.

The Generalized Pigeonhole Principle

The generalized pigeonhole principle extends the basic statement to any threshold m. If n items are distributed into k containers, then at least one container holds at least ⌈n/k⌉ items (where ⌈ ⌉ denotes the ceiling function, rounding up to the nearest integer).

Equivalently, to guarantee that at least one container holds m or more items, you need at least:

N = k(m − 1) + 1

The logic is airtight: with k(m−1) items you could distribute exactly m−1 per container, with no container reaching m. The very next item — the (k(m−1)+1)-th — must go into some container, pushing it to m items.

Historical Background — Dirichlet's Box Principle

The principle was formalized by German mathematician Peter Gustav Lejeune Dirichlet around 1834, who called it the Schubfachprinzip (drawer principle). Dirichlet used it to prove deep results in Diophantine approximation — specifically, that for any real number α and integer N, there exist integers p and q with 1 ≤ q ≤ N such that |α − p/q| < 1/(qN). This is the fundamental theorem of Diophantine approximation.

Despite being a nineteenth-century formalization, applications of the principle appear implicitly in even earlier mathematical work. The "pigeonhole" metaphor itself is an English-language coinage that became standard in the twentieth century.

Applications in Number Theory

The pigeonhole principle has powerful applications across number theory:

  • Rational approximation (Dirichlet): For any irrational α and integer N ≥ 1, there exist integers p, q with 0 < q ≤ N and |qα − p| < 1/N. The proof partitions the N+1 fractional parts {0}, {α}, {2α}, …, {Nα} into N intervals of length 1/N — by pigeonhole, two must fall in the same interval.
  • Schur's theorem: For any r-coloring of the integers {1, 2, …, N} (for large enough N), there exist positive integers x, y, z of the same color with x + y = z. The proof uses a pigeonhole argument over color classes.
  • Ramsey theory: R(3,3) = 6 means any 2-coloring of the edges of K₆ contains a monochromatic triangle. The proof is a direct application of pigeonhole applied to the 5 edges incident to any vertex.
  • Perfect squares: Any set of n+1 integers from {1, 2, …, 2n} contains two that are consecutive (pigeonhole over pairs {1,2}, {3,4}, …, {2n-1,2n}).

Applications in Computer Science

  • Hash collisions: Any hash function mapping a larger input space to a smaller output space must produce collisions. If a hash function produces 32-bit outputs (2³² possible values) but can process files of any size, then the moment you have more than 2³² distinct files, some pair must share a hash. This is why cryptographic hash functions are designed to make collisions computationally hard to find, not impossible.
  • Lossless compression limits: No lossless compression algorithm can compress all inputs. If it compressed every file of length n bits to fewer bits, there would be more source files than compressed representations — impossible by pigeonhole. Some files must be unchanged or lengthened.
  • Graph coloring lower bounds: In a graph where the maximum degree is Δ, the chromatic number is at most Δ+1 (greedy coloring), and certain dense subgraph structures force a higher chromatic number by pigeonhole arguments.
  • Sorting lower bounds: Any comparison-based sorting algorithm requires at least ⌈log₂(n!)⌉ comparisons in the worst case. The argument uses pigeonhole over the decision tree of comparisons.

The Birthday Paradox Connection

The pigeonhole principle tells us that 367 people in a room guarantee (with 100% certainty) that at least two share a birthday (since there are at most 366 distinct birthdays). This is a hard threshold.

The famous birthday paradox is a probabilistic cousin: with only 23 people, the probability that some pair shares a birthday exceeds 50%. With 70 people, this probability exceeds 99.9%. The "paradox" is that people underestimate how quickly the probability of a collision grows as the group size increases.

The two results address different questions: pigeonhole gives a certainty bound (worst-case guarantee), while the birthday paradox gives a probabilistic bound (average-case behavior). Both are important tools in cryptographic analysis — the birthday attack on hash functions exploits the probabilistic result.

Reference Table — Common Pigeonhole Applications

Scenario Items (n) Containers (k) Guarantee (m) Minimum Needed
Same birthday (day)people3662367
3 share birthday (day)people3663733
Same birth monthpeople12213
Same weekday birthdaypeople728
Matching sock pairsocksk colors2k + 1
2 cards same suitcards425
3 cards same suitcards439

Frequently Asked Questions

What is the pigeonhole principle?
The pigeonhole principle states that if n items are placed into k containers and n > k, at least one container must hold more than one item. The generalized form says: if n items go into k containers, at least one container holds ⌈n/k⌉ or more items. It is attributed to Dirichlet (1834) and is a foundational tool in combinatorics, number theory, and computer science.
What is the generalized pigeonhole principle?
The generalized pigeonhole principle states: if n items are distributed among k containers, at least one container holds at least ⌈n/k⌉ items. Equivalently, to guarantee at least m items in one container you need at least k(m−1)+1 items total. The basic principle is the m=2 special case: if n > k, then ⌈n/k⌉ ≥ 2.
What is the minimum number to guarantee a match?
To guarantee that at least m items share the same container when you have k containers, the minimum number of items needed is k(m−1) + 1. This is tight: with exactly k(m−1) items it is possible (though not required) to put only m−1 in each container. The (k(m−1)+1)-th item must land in some container, bringing it to m.
How is the pigeonhole principle used in computer science?
Key applications include: (1) Hash collisions — any hash function with fewer outputs than inputs must produce collisions; (2) Compression limits — no lossless compressor can shorten every possible file; (3) Graph theory — proving chromatic number lower bounds; (4) Sorting lower bounds — at least ⌈log₂(n!)⌉ comparisons are needed for comparison-based sorting.
What is the birthday paradox?
The birthday paradox is the observation that in a group of just 23 people, the probability of at least two sharing a birthday exceeds 50%. The pigeonhole principle gives the certainty threshold: 367 people guarantee a shared birthday with 100% probability. The birthday paradox uses probability, not the pigeonhole principle — it exploits the fact that collision probability grows quadratically with group size.
Who discovered the pigeonhole principle?
The principle is attributed to the German mathematician Peter Gustav Lejeune Dirichlet (~1834), who named it the Schubfachprinzip (drawer principle) and used it in his foundational work on Diophantine approximation. Because of this, it is also called Dirichlet's box principle in European mathematical literature. The "pigeonhole" metaphor became dominant in English-language texts during the twentieth century.
Can the pigeonhole principle prove that two people share a birthday?
Yes — with certainty. There are at most 366 distinct birthdays (including Feb 29). With 367 or more people, the pigeonhole principle guarantees that at least two people share a birthday, regardless of when they were born. This is a deterministic guarantee, not a probability. For fewer than 367 people, sharing is possible but not guaranteed.