Stirling Numbers of the Second Kind
How many ways can seven distinguishable committee members be split into three nonempty working groups? This is not a question about ordered lists or labeled boxes. It is a question about partitions of a set. Here the groups themselves carry no names or order. The Stirling numbers of the second kind, written or , answer exactly this question. They count the partitions of an -element set into nonempty, unlabeled blocks. This object sits at a genuine fork in enumerative combinatorics. Counting surjections from an -set onto a -set is a close relative. A surjection is a partition into blocks plus a labeling of those blocks by the target elements. The two counts differ by exactly a factor of . Stirling numbers of the second kind are the "unlabeled" backbone underneath surjections, binomial coefficients. They also underlie, eventually, the Bell numbers (partitions into any number of blocks). They fill a whole row of the Twelvefold Way. The central tool of this article is a two-term recurrence. It is proved by a direct combinatorial argument about where the largest element of the set goes. This recurrence is the workhorse. It generates a triangular array of numbers. It gives a clean inductive proof technique. It connects to an explicit closed form via inclusion–exclusion. Along the way we will see why the recurrence is not just a computational shortcut. It is the theorem. It is the identity that makes the entire triangle of values computable from two base cases. By the end, you will be able to state and prove the recurrence for . You will derive it from a bijective decomposition of partitions. You will connect it to surjection counts and binomial coefficients. You will compute nontrivial values by hand. You will see precisely where the boundary/edge cases and must be handled with care.
- counts partitions of an -element set into exactly nonempty, unordered, unlabeled blocks.
- The defining recurrence is , based on the fate of one distinguished element.
- Boundary values: for , , , .
- Surjections from an -set onto a -set number — labeling the ways to name the blocks.
- Summing over all gives the Bell number , the total number of set partitions.
- Key idea: track the block containing the largest (or a fixed) element to split any partition-counting problem into two smaller cases.
Where this lives today
Stirling numbers of the second kind appear throughout discrete mathematics and its applications. In combinatorics on words and functions, is the essential ingredient for counting surjections, via , and summing over gives the Bell numbers , the total count of set partitions — a quantity central to the study of equivalence relations on finite sets. In the Twelvefold Way framework for counting functions between finite sets under various symmetry conditions, occupies exactly the cell corresponding to "surjections from an unlabeled domain onto an unlabeled codomain, up to relabeling the codomain," making it one of the twelve canonical counting problems. In algebra and analysis, Stirling numbers of the second kind provide the change-of-basis coefficients between the monomial basis and the falling factorial basis :
a fact used in finite-difference calculus (Stirling's original motivation), in the theory of moments of discrete probability distributions, and in umbral calculus. In probability and statistics, Stirling numbers appear in the moments of the Poisson distribution and in occupancy problems (balls into unlabeled, non-empty urns). In computer science, they arise in the analysis of hashing schemes, in counting the number of ways to partition data into non-empty labeled or unlabeled clusters (relevant to clustering algorithms and combinatorial data structures), and in the enumeration of equivalence classes of finite automata states. In cryptography and coding theory, closely related surjection and partition counts arise when bounding the number of possible key-to-plaintext block assignments or analyzing collision structures in hash-based schemes. Finally, Stirling numbers of the second kind are a natural stepping stone toward Stirling Numbers of the First Kind, which perform an analogous role for counting permutations by their cycle structure rather than sets by their block structure.
Ask the tutor: How does the closed-form inclusion–exclusion formula for get derived from the surjection count, step by step?
Let and be nonnegative integers. A partition of a set into blocks is a collection of pairwise disjoint, nonempty subsets of (the blocks) whose union is , where the blocks are regarded as an unordered collection (no labeling or ordering distinguishes them). The Stirling number of the second kind , also written , is the number of partitions of an -element set into exactly nonempty blocks:
where . By convention (the empty set has exactly one partition, the empty collection of blocks), and for , and whenever or .
Intuition
Think of labeled balls that must be dropped into some number of identical, unlabeled buckets, with no bucket left empty. The buckets have no names — swapping the contents of "bucket A" and "bucket B" produces the same partition, because there is no A or B to begin with. This is the essential difference from counting functions or surjections: a surjection onto additionally tells you which bucket is which, so it overcounts partitions by a factor of (the number of ways to assign labels to the indistinguishable buckets). The key combinatorial move — used in the proof below and in almost every Stirling-number argument — is to isolate one distinguished element, say the largest, element , and ask: does sit alone in its own block, or does it share a block with others? If is alone, the rest of the partition is an arbitrary partition of into blocks. If shares a block, remove ; what remains is a partition of into blocks, and could have been inserted into any of those blocks. This dichotomy is exactly the two terms of the recurrence.
The recurrence and its proof
For all integers and ,
with base cases , for , for , and for .
We use a combinatorial (bijective decomposition) proof: we partition the set of objects being counted by into two disjoint classes and show each class is in bijection with the set counted by one term on the right-hand side. Fix , , and let . Let denote the set of all partitions of into exactly nonempty blocks, so by definition. We classify each partition according to the block containing the element .
Case A: is a block of by itself. Let be the set of such partitions. Given , remove the singleton block ; the remaining blocks form a partition of into exactly nonempty blocks (removing one block from the blocks of leaves blocks, all still nonempty and still partitioning , since appeared in no other block). This defines a map
This map is a bijection: it is injective because is recovered from by adjoining the singleton block , and this recovery is exactly determined by , so distinct give distinct . It is surjective because for any partition of into blocks, adjoining the new block produces a partition of into blocks lying in , and sends it back to . Hence
Case B: the block of containing has at least one other element. Let be the set of such partitions. Given , let be the block of containing ; by assumption . Define
i.e. remove from its block and keep all other blocks unchanged. Since is nonempty and every other block of is unaffected and unchanged, is a partition of into exactly nonempty blocks (the same blocks as , one of them shrunk by the removal of the single element ). So maps into . The map is exactly -to-: given a partition with blocks , the partitions with are precisely those obtained by inserting the element into one of the blocks (there is no option to make a new singleton block, since that would put in , not ). These choices give distinct partitions of , because inserting into versus () produces partitions differing in which block contains together with which other elements. Conversely every such insertion, for every , is counted once. Hence is exactly -to-one and onto , so
Combining. Since and partition (every partition of into blocks falls into exactly one of the two cases, depending on whether 's block is a singleton),
This is precisely the claimed recurrence. The boundary values are immediate from the definition: there is exactly one partition of the empty set (the empty collection of blocks), giving ; a nonempty set cannot be partitioned into nonempty blocks, giving for ; and no set can be partitioned into more blocks than it has elements without some block being empty, giving for .
∎For all : , , and .
: there is exactly one partition of into a single block, namely itself; this can also be checked from the recurrence by induction, since , and for while directly, giving . : a partition of an -set into exactly nonempty blocks must put each element in its own block (if any block had elements, the total block count would be ), so there is exactly one such partition, the partition into singletons. : a partition of into nonempty blocks corresponds to choosing a nonempty proper subset , except that and give the same unordered partition. The number of nonempty proper subsets of is (all subsets minus the empty set and the full set), and each partition is counted exactly twice this way (once as , once as its complement), so
Worked examples
Example 1: computing by the recurrence, and interpreting it. We build up the needed table entries using , together with and . Row : . Row :
(Check against the closed form for : matches.) Row :
Row :
We need . So
Interpretation check via surjections. The number of surjections from a -element set onto a -element (labeled) set is . We can cross-check this against the inclusion–exclusion formula for surjections ,
For :
This matches exactly, confirming .
Example 2: partitioning distinguishable tasks among indistinguishable work-teams, no team idle, with an explicit further constraint. Suppose labeled tasks must be split into exactly nonempty, unlabeled teams — a raw count of — but suppose additionally we want the number of such partitions in which task and task end up on different teams. We compute this via complementary counting inside , illustrating the recurrence's usefulness for auxiliary computations, not just the base numbers. First, we need . Build the table (using , , , and the recurrence for the rest): Row 3: Row 4: Row 5: Row 6: — we computed above; now
Row 6: . Row 7:
Row 7: . Row 8:
So there are ways to split labeled tasks into nonempty unlabeled teams. Now, the number of these partitions in which tasks and lie in the same team: merge tasks into a single "super-task," reducing to a partition of labeled objects into nonempty unlabeled blocks — exactly such partitions (this is a bijection: merging/unmerging the super-task is reversible, since the super-task's presence just says "1 and 2 are together"). Hence the number of partitions of into blocks with in different blocks is
This value is our answer: among the ways to form four unlabeled non-idle teams from eight labeled tasks, exactly of them separate tasks and onto different teams.
The recurrence and its base cases depend critically on requiring every block to be nonempty. Suppose instead we (incorrectly) tried to define as the number of ways to partition into a collection of at most possibly-empty labeled slots that happen to be treated as unlabeled — i.e., we drop the nonemptiness requirement but keep everything else. Concretely, let us test the naive claim that "partitions of into blocks, empty blocks allowed" should still satisfy with the same interpretation used in the proof. Take , . Genuine partitions of into exactly nonempty blocks do not exist, so the correctly-defined , consistent with for . But if we allow empty blocks, then "partitioning into blocks" could mean , , or other empty-padded splittings; if the blocks are still considered unlabeled, most of these become identified with lower- partitions since empty blocks carry no information and multiple empty blocks are indistinguishable from one another. This immediately shows that the sensible way to "count partitions into at most blocks with padding" is not a new number at all — it collapses back to , not to a value satisfying the two-term recurrence at level with fresh combinatorial content. More sharply: the bijective argument in the proof of the theorem used, in Case B, that inserting element into one of the blocks of a partition gives distinct results, because each block is nonempty and inserting into different nonempty blocks changes the block's content in a way that is distinguishable after the fact. If empty blocks were allowed and treated as interchangeable placeholders, then "inserting into empty block " versus "inserting into empty block " would produce the same set partition (a new singleton plus the same nonempty blocks of ) counted multiple times, since two empty unlabeled blocks are simply the same object. This overcounting exactly breaks the -to-one claim underlying the term , and the recurrence fails. This is precisely why the nonemptiness hypothesis on blocks is written into the definition, not left implicit: it is what makes each "slot" in the counting argument distinguishable by its (nonempty) content rather than by an arbitrary label.
Scope, edge cases & common traps
| Situation | What happens | Common mistake | |
|---|---|---|---|
| Forgetting to force as the true base case, and instead setting for all including | |||
| (only the all-singletons partition) | Confusing this with ; both equal but for different combinatorial reasons | ||
| Applying the recurrence blindly without checking that or might also need a zero base case, leading to negative-index lookups | |||
| Confusing with surjections | number of surjections | The correct relation is ; omitting the undercounts labeled assignments by exactly the group of block-relabelings | |
| Confusing with Stirling numbers of the first kind | Notation vs. | Mixing up set partitions (second kind) with permutation cycle counts ([[Stirling Numbers of the First Kind | first kind]]) — they satisfy different recurrences entirely |
The mathematician behind it
Origins · 1 minJames Stirling and how this was discovered
James Stirling worked in the generation immediately following Isaac Newton, contributing to the theory of infinite series, interpolation, and the asymptotic analysis of factorials — the source of the eponymous Stirling's approximation for . He corresponded with Newton and other members of the early Royal Society mathematical community, and his 1730 treatise Methodus Differentialis laid foundational groundwork for finite-difference calculus, from which the triangular arrays now called Stirling numbers (of both kinds) eventually took their modern combinatorial meaning. Stirling later worked as a mine manager in Scotland, a departure from academic life that did not stop his mathematical output from shaping analysis and combinatorics for centuries.
Is the same as the number of ways to color objects with colors so every color is used?
Not quite, but they are closely related. Coloring labeled objects with labeled colors such that every color is used at least once is exactly a surjection from the -set onto the -set of colors, which is counted by , not by itself. The Stirling number only counts the underlying partition into color classes, forgetting which color name went with which class. If the colors are truly indistinguishable — for instance if you only care which objects ended up grouped together, not what the group is called — then is exactly the right count. The factor is the number of ways to assign the distinguishable color labels to the indistinguishable blocks after the fact.
How does relate to the Bell numbers?
The Bell number counts all partitions of an -element set, with no restriction on the number of blocks, so it is obtained by summing over every possible block count from to :
For example . This makes a refinement of by number of blocks, exactly analogous to how binomial coefficients refine by subset size. The Bell numbers satisfy their own recurrence derivable directly from this sum together with the Stirling recurrence.
Why is the recurrence considered a proof and not just a pattern?
The recurrence is proved by explicitly constructing a bijection (in Case A) and an exact -to-one correspondence (in Case B) between the set of partitions counted by and the disjoint union of the sets counted by and copies of the set counted by . Because every partition of into blocks falls into exactly one of the two cases (whether 's block is a singleton), and the correspondences in each case are shown to be exact bijections (respectively an exact -to-one map), the equality of counts follows rigorously from the equality of the underlying sets, not merely from checking small numerical cases. This is what distinguishes a proved combinatorial recurrence from an empirically observed pattern in a table of numbers.
Can or be zero, and what values does the recurrence give then?
Yes, and the boundary cases must be handled explicitly because the recurrence proof (via the fate of element ) implicitly assumes . By definition, because the empty set has exactly one partition: the empty collection of blocks. For , , since a nonempty set cannot be partitioned into zero blocks (the union of zero blocks is empty, not ). Also for , since the empty set cannot be partitioned into a positive number of nonempty blocks. These base cases, together with the recurrence for , are what make the entire triangle computable from the top down.
How is different from Stirling numbers of the first kind?
Stirling numbers of the second kind, , count partitions of a set into nonempty unlabeled blocks — a purely set-theoretic notion with no notion of internal order within a block. Stirling Numbers of the First Kind instead count permutations of having exactly cycles (in the unsigned version), which is a fundamentally different structure because a cycle has an internal cyclic order, whereas a block in a set partition does not. The two families satisfy different recurrences and act as inverse-like change-of-basis matrices between the monomial basis and the falling/rising factorial bases in algebra, but they answer different combinatorial questions and should not be conflated despite the similar notation and shared name.
Is there a closed-form (non-recursive) formula for ?
Yes. Using inclusion–exclusion on the surjection count and then dividing out the labeling factor gives
This formula is exact for all (with the usual convention when ), and it can be verified to satisfy the same recurrence and boundary conditions proved in this article, by direct algebraic manipulation of the binomial sum. In practice, for hand computation of small to moderate values, the two-term recurrence is usually faster and less error-prone than evaluating this alternating sum directly, which is why the recurrence remains the primary computational and conceptual tool.
Where does show up outside pure combinatorics?
Beyond counting set partitions directly, appears as the coefficients converting monomials into falling factorials , a fact used throughout finite-difference calculus, numerical analysis, and the calculation of moments of discrete probability distributions such as the Poisson and binomial families. In computer science, Stirling numbers of the second kind arise in the analysis of hash-table collision structures, in counting partitions relevant to clustering and combinatorial optimization, and in enumerating equivalence classes over finite state spaces. They also occur as intermediate quantities in the study of random set partitions and in combinatorial species theory, which studies structures like partitions using generating-function methods that generalize the recurrence proved here.