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 S(n,k)S(n,k) or {nk}\left\{{n\atop k}\right\}, answer exactly this question. They count the partitions of an nn-element set into kk nonempty, unlabeled blocks. This object sits at a genuine fork in enumerative combinatorics. Counting surjections from an nn-set onto a kk-set is a close relative. A surjection is a partition into kk blocks plus a labeling of those blocks by the kk target elements. The two counts differ by exactly a factor of k!k!. 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 S(n,k)S(n,k). 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 k=0k=0 and k=nk=n must be handled with care.

Key takeaways
  • S(n,k)S(n,k) counts partitions of an nn-element set into exactly kk nonempty, unordered, unlabeled blocks.
  • The defining recurrence is S(n,k)=k S(n−1,k)+S(n−1,k−1)S(n,k) = k\,S(n-1,k) + S(n-1,k-1), based on the fate of one distinguished element.
  • Boundary values: S(n,0)=0S(n,0)=0 for n≥1n\ge 1, S(0,0)=1S(0,0)=1, S(n,n)=1S(n,n)=1, S(n,1)=1S(n,1)=1.
  • Surjections from an nn-set onto a kk-set number k! S(n,k)k!\,S(n,k) — labeling the k!k! ways to name the blocks.
  • Summing over all kk gives the Bell number Bn=∑k=0nS(n,k)B_n = \sum_{k=0}^n S(n,k), 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, S(n,k)S(n,k) is the essential ingredient for counting surjections, via Surj(n,k)=k! S(n,k)\text{Surj}(n,k) = k!\,S(n,k), and summing over kk gives the Bell numbers Bn=∑k=0nS(n,k)B_n = \sum_{k=0}^n S(n,k), 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, S(n,k)S(n,k) 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 xnx^n and the falling factorial basis (x)k=x(x−1)⋯(x−k+1)(x)_k = x(x-1)\cdots(x-k+1):

xn=∑k=0nS(n,k) (x)k,x^n = \sum_{k=0}^n S(n,k)\,(x)_k,

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 S(n,k)S(n,k) get derived from the surjection count, step by step?

DefinitionStirling number of the second kind

Let nn and kk be nonnegative integers. A partition of a set XX into kk blocks is a collection {B1,…,Bk}\{B_1,\dots,B_k\} of pairwise disjoint, nonempty subsets of XX (the blocks) whose union is XX, where the blocks are regarded as an unordered collection (no labeling or ordering distinguishes them). The Stirling number of the second kind S(n,k)S(n,k), also written {nk}\left\{{n\atop k}\right\}, is the number of partitions of an nn-element set into exactly kk nonempty blocks:

S(n,k)  =  #{{B1,…,Bk}:Bi⊆[n], Bi≠∅, Bi∩Bj=∅ (i≠j), ⋃iBi=[n]},S(n,k) \;=\; \#\Big\{ \{B_1,\dots,B_k\} : B_i \subseteq [n],\ B_i \neq \varnothing,\ B_i \cap B_j = \varnothing \ (i\ne j),\ \textstyle\bigcup_i B_i = [n] \Big\},

where [n]={1,2,…,n}[n] = \{1,2,\dots,n\}. By convention S(0,0)=1S(0,0)=1 (the empty set has exactly one partition, the empty collection of blocks), and S(n,0)=0S(n,0)=0 for n≥1n\ge 1, and S(n,k)=0S(n,k)=0 whenever k>nk>n or k<0k<0.

Intuition

Think of nn 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 {1,…,k}\{1,\dots,k\} additionally tells you which bucket is which, so it overcounts partitions by a factor of k!k! (the number of ways to assign labels to the kk 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 nn, and ask: does nn sit alone in its own block, or does it share a block with others? If nn is alone, the rest of the partition is an arbitrary partition of {1,…,n−1}\{1,\dots,n-1\} into k−1k-1 blocks. If nn shares a block, remove nn; what remains is a partition of {1,…,n−1}\{1,\dots,n-1\} into kk blocks, and nn could have been inserted into any of those kk blocks. This dichotomy is exactly the two terms of the recurrence.

Figure
The triangle of Stirling numbers of the second kind, rows n=0n=0 to n=5n=5
n \ k k=0 k=1 k=2 k=3 k=4 k=5 n=0 1 n=1 0 1 n=2 0 1 1 n=3 0 1 3 1 n=4 0 1 7 6 1 n=5 0 1 15 25 10 1 S(5,3) = 3·S(4,3) + S(4,2) = 3·6 + 7 = 25

The recurrence and its proof

TheoremRecurrence for Stirling numbers of the second kind

For all integers n≥1n \ge 1 and k≥1k \ge 1,

S(n,k)  =  k⋅S(n−1,k)  +  S(n−1,k−1),S(n,k) \;=\; k\cdot S(n-1,k) \;+\; S(n-1,k-1),

with base cases S(0,0)=1S(0,0)=1, S(n,0)=0S(n,0)=0 for n≥1n\ge1, S(0,k)=0S(0,k)=0 for k≥1k\ge1, and S(n,k)=0S(n,k)=0 for k>nk>n.

Proof

We use a combinatorial (bijective decomposition) proof: we partition the set of objects being counted by S(n,k)S(n,k) into two disjoint classes and show each class is in bijection with the set counted by one term on the right-hand side. Fix n≥1n\ge 1, k≥1k\ge 1, and let X=[n]={1,2,…,n}X = [n] = \{1,2,\dots,n\}. Let P(n,k)\mathcal{P}(n,k) denote the set of all partitions of [n][n] into exactly kk nonempty blocks, so ∣P(n,k)∣=S(n,k)|\mathcal{P}(n,k)| = S(n,k) by definition. We classify each partition P∈P(n,k)P \in \mathcal{P}(n,k) according to the block containing the element nn.

Case A: {n}\{n\} is a block of PP by itself. Let A⊆P(n,k)\mathcal{A} \subseteq \mathcal{P}(n,k) be the set of such partitions. Given P∈AP \in \mathcal{A}, remove the singleton block {n}\{n\}; the remaining blocks form a partition P′P' of [n−1]={1,…,n−1}[n-1] = \{1,\dots,n-1\} into exactly k−1k-1 nonempty blocks (removing one block from the kk blocks of PP leaves k−1k-1 blocks, all still nonempty and still partitioning [n−1][n-1], since nn appeared in no other block). This defines a map

φ:A⟶P(n−1,k−1),φ(P)=P∖{{n}}.\varphi: \mathcal{A} \longrightarrow \mathcal{P}(n-1,k-1), \qquad \varphi(P) = P \setminus \{\{n\}\}.

This map is a bijection: it is injective because PP is recovered from P′=φ(P)P' = \varphi(P) by adjoining the singleton block {n}\{n\}, and this recovery is exactly determined by P′P', so distinct PP give distinct P′P'. It is surjective because for any partition P′P' of [n−1][n-1] into k−1k-1 blocks, adjoining the new block {n}\{n\} produces a partition of [n][n] into kk blocks lying in A\mathcal{A}, and φ\varphi sends it back to P′P'. Hence

∣A∣=∣P(n−1,k−1)∣=S(n−1,k−1).|\mathcal{A}| = |\mathcal{P}(n-1,k-1)| = S(n-1,k-1).

Case B: the block of PP containing nn has at least one other element. Let B=P(n,k)∖A\mathcal{B} = \mathcal{P}(n,k)\setminus \mathcal{A} be the set of such partitions. Given P∈BP \in \mathcal{B}, let BB be the block of PP containing nn; by assumption B∖{n}≠∅B \setminus \{n\} \neq \varnothing. Define

ψ(P)=(P∖{B})∪{B∖{n}},\psi(P) = \big(P \setminus \{B\}\big) \cup \{B \setminus \{n\}\},

i.e. remove nn from its block and keep all other blocks unchanged. Since B∖{n}B\setminus\{n\} is nonempty and every other block of PP is unaffected and unchanged, ψ(P)\psi(P) is a partition of [n−1][n-1] into exactly kk nonempty blocks (the same kk blocks as PP, one of them shrunk by the removal of the single element nn). So ψ\psi maps B\mathcal{B} into P(n−1,k)\mathcal{P}(n-1,k). The map ψ\psi is exactly kk-to-11: given a partition Q∈P(n−1,k)Q \in \mathcal{P}(n-1,k) with blocks C1,…,CkC_1,\dots,C_k, the partitions P∈BP \in \mathcal{B} with ψ(P)=Q\psi(P) = Q are precisely those obtained by inserting the element nn into one of the kk blocks C1,…,CkC_1,\dots,C_k (there is no option to make nn a new singleton block, since that would put PP in A\mathcal{A}, not B\mathcal{B}). These kk choices give kk distinct partitions of [n][n], because inserting nn into CiC_i versus CjC_j (i≠ji\ne j) produces partitions differing in which block contains nn together with which other elements. Conversely every such insertion, for every QQ, is counted once. Hence ψ\psi is exactly kk-to-one and onto P(n−1,k)\mathcal{P}(n-1,k), so

∣B∣=k⋅∣P(n−1,k)∣=k⋅S(n−1,k).|\mathcal{B}| = k \cdot |\mathcal{P}(n-1,k)| = k\cdot S(n-1,k).

Combining. Since A\mathcal{A} and B\mathcal{B} partition P(n,k)\mathcal{P}(n,k) (every partition of [n][n] into kk blocks falls into exactly one of the two cases, depending on whether nn's block is a singleton),

S(n,k)=∣P(n,k)∣=∣A∣+∣B∣=S(n−1,k−1)+k⋅S(n−1,k).S(n,k) = |\mathcal{P}(n,k)| = |\mathcal{A}| + |\mathcal{B}| = S(n-1,k-1) + k\cdot S(n-1,k).

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 S(0,0)=1S(0,0)=1; a nonempty set cannot be partitioned into 00 nonempty blocks, giving S(n,0)=0S(n,0)=0 for n≥1n \ge 1; and no set can be partitioned into more blocks than it has elements without some block being empty, giving S(n,k)=0S(n,k)=0 for k>nk>n. ■\blacksquare

∎
CorollarySpecial values

For all n≥1n \ge 1: S(n,1)=1S(n,1) = 1, S(n,n)=1S(n,n) = 1, and S(n,2)=2n−1−1S(n,2) = 2^{n-1}-1.

Proof

S(n,1)=1S(n,1)=1: there is exactly one partition of [n][n] into a single block, namely {[n]}\{[n]\} itself; this can also be checked from the recurrence by induction, since S(n,1)=1⋅S(n−1,1)+S(n−1,0)S(n,1) = 1\cdot S(n-1,1) + S(n-1,0), and S(n−1,0)=0S(n-1,0)=0 for n≥2n\ge 2 while S(1,1)=1S(1,1)=1 directly, giving S(n,1)=S(n−1,1)=⋯=S(1,1)=1S(n,1)=S(n-1,1)=\cdots=S(1,1)=1. S(n,n)=1S(n,n)=1: a partition of an nn-set into exactly nn nonempty blocks must put each element in its own block (if any block had ≥2\ge 2 elements, the total block count would be <n<n), so there is exactly one such partition, the partition into singletons. S(n,2)S(n,2): a partition of [n][n] into 22 nonempty blocks {B,[n]∖B}\{B, [n]\setminus B\} corresponds to choosing a nonempty proper subset B⊊[n]B \subsetneq [n], except that BB and [n]∖B[n]\setminus B give the same unordered partition. The number of nonempty proper subsets of [n][n] is 2n−22^n - 2 (all subsets minus the empty set and the full set), and each partition is counted exactly twice this way (once as BB, once as its complement), so

S(n,2)=2n−22=2n−1−1.■S(n,2) = \frac{2^n-2}{2} = 2^{n-1}-1. \qquad \blacksquare
∎

Worked examples

Example 1: computing S(6,3)S(6,3) by the recurrence, and interpreting it. We build up the needed table entries using S(n,k)=k S(n−1,k)+S(n−1,k−1)S(n,k) = k\,S(n-1,k) + S(n-1,k-1), together with S(n,1)=1S(n,1)=1 and S(n,n)=1S(n,n)=1. Row n=3n=3: S(3,1)=1, S(3,2)=22−1=3, S(3,3)=1S(3,1)=1,\ S(3,2)=2^{2}-1=3,\ S(3,3)=1. Row n=4n=4:

S(4,2)=2 S(3,2)+S(3,1)=2(3)+1=7,S(4,3)=3 S(3,3)+S(3,2)=3(1)+3=6.S(4,2) = 2\,S(3,2) + S(3,1) = 2(3)+1 = 7, \qquad S(4,3) = 3\,S(3,3)+S(3,2) = 3(1)+3 = 6.

(Check S(4,2)=23−1=7S(4,2)=2^3-1=7 against the closed form for k=2k=2: matches.) Row n=5n=5:

S(5,3)=3 S(4,3)+S(4,2)=3(6)+7=25.S(5,3) = 3\,S(4,3) + S(4,2) = 3(6) + 7 = 25.

Row n=6n=6:

S(6,3)=3 S(5,3)+S(5,2).S(6,3) = 3\,S(5,3) + S(5,2).

We need S(5,2)=24−1=15S(5,2) = 2^4-1 = 15. So

S(6,3)=3(25)+15=75+15=90.S(6,3) = 3(25) + 15 = 75 + 15 = 90.

Interpretation check via surjections. The number of surjections from a 66-element set onto a 33-element (labeled) set is 3! S(6,3)=6⋅90=5403!\, S(6,3) = 6 \cdot 90 = 540. We can cross-check this against the inclusion–exclusion formula for surjections [n]↠[k][n]\twoheadrightarrow[k],

Surj(n,k)=∑j=0k(−1)j(kj)(k−j)n.\text{Surj}(n,k) = \sum_{j=0}^{k} (-1)^j \binom{k}{j}(k-j)^n.

For n=6,k=3n=6,k=3:

Surj(6,3)=(30)36−(31)26+(32)16−(33)06=729−3(64)+3(1)−0=729−192+3=540.\text{Surj}(6,3) = \binom{3}{0}3^6 - \binom{3}{1}2^6 + \binom{3}{2}1^6 - \binom{3}{3}0^6 = 729 - 3(64) + 3(1) - 0 = 729 - 192 + 3 = 540.

This matches 6⋅90=5406 \cdot 90 = 540 exactly, confirming S(6,3)=90S(6,3) = 90.

Example 2: partitioning 88 distinguishable tasks among 44 indistinguishable work-teams, no team idle, with an explicit further constraint. Suppose 88 labeled tasks {1,…,8}\{1,\dots,8\} must be split into exactly 44 nonempty, unlabeled teams — a raw count of S(8,4)S(8,4) — but suppose additionally we want the number of such partitions in which task 11 and task 22 end up on different teams. We compute this via complementary counting inside S(8,4)S(8,4), illustrating the recurrence's usefulness for auxiliary computations, not just the base numbers. First, we need S(8,4)S(8,4). Build the table (using S(n,1)=1S(n,1)=1, S(n,n)=1S(n,n)=1, S(n,2)=2n−1−1S(n,2)=2^{n-1}-1, and the recurrence for the rest): Row 3: 1,3,11,3,1 Row 4: 1,7,6,11,7,6,1 Row 5: 1,15,25,10,11,15,25,10,1 Row 6: 1,31,S(6,3),S(6,4),15,11,31,S(6,3),S(6,4),15,1 — we computed S(6,3)=90S(6,3)=90 above; now

S(6,4)=4 S(5,4)+S(5,3)=4(10)+25=65.S(6,4) = 4\,S(5,4)+S(5,3) = 4(10)+25 = 65.

Row 6: 1,31,90,65,15,11,31,90,65,15,1. Row 7:

S(7,3)=3 S(6,3)+S(6,2)=3(90)+31=301,S(7,3) = 3\,S(6,3)+S(6,2) = 3(90)+31 = 301,
S(7,4)=4 S(6,4)+S(6,3)=4(65)+90=350,S(7,4) = 4\,S(6,4)+S(6,3) = 4(65)+90 = 350,
S(7,5)=5 S(6,5)+S(6,4)=5(15)+65=140.S(7,5) = 5\,S(6,5)+S(6,4) = 5(15)+65 = 140.

Row 7: 1,63,301,350,140,21,11,63,301,350,140,21,1. Row 8:

S(8,4)=4 S(7,4)+S(7,3)=4(350)+301=1400+301=1701.S(8,4) = 4\,S(7,4) + S(7,3) = 4(350) + 301 = 1400+301 = 1701.

So there are S(8,4)=1701S(8,4)=1701 ways to split 88 labeled tasks into 44 nonempty unlabeled teams. Now, the number of these partitions in which tasks 11 and 22 lie in the same team: merge tasks 1,21,2 into a single "super-task," reducing to a partition of 77 labeled objects {{1,2},3,4,…,8}\{\{1,2\},3,4,\dots,8\} into 44 nonempty unlabeled blocks — exactly S(7,4)=350S(7,4) = 350 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 [8][8] into 44 blocks with 1,21,2 in different blocks is

S(8,4)−S(7,4)=1701−350=1351.S(8,4) - S(7,4) = 1701 - 350 = 1351.

This value 13511351 is our answer: among the 17011701 ways to form four unlabeled non-idle teams from eight labeled tasks, exactly 13511351 of them separate tasks 11 and 22 onto different teams.

Counterexampledropping the "nonempty blocks" hypothesis breaks the recurrence and the boundary values

The recurrence and its base cases depend critically on requiring every block to be nonempty. Suppose instead we (incorrectly) tried to define S~(n,k)\widetilde S(n,k) as the number of ways to partition [n][n] into a collection of at most kk 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 [n][n] into kk blocks, empty blocks allowed" should still satisfy k S(n−1,k)+S(n−1,k−1)k\,S(n-1,k)+S(n-1,k-1) with the same interpretation used in the proof. Take n=2n=2, k=3k=3. Genuine partitions of {1,2}\{1,2\} into exactly 33 nonempty blocks do not exist, so the correctly-defined S(2,3)=0S(2,3)=0, consistent with S(n,k)=0S(n,k)=0 for k>nk>n. But if we allow empty blocks, then "partitioning {1,2}\{1,2\} into 33 blocks" could mean {{1,2},∅,∅}\{\{1,2\},\varnothing,\varnothing\}, {{1},{2},∅}\{\{1\},\{2\},\varnothing\}, or other empty-padded splittings; if the blocks are still considered unlabeled, most of these become identified with lower-kk 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 kk blocks with padding" is not a new number at all — it collapses back to ∑j≤kS(n,j)\sum_{j\le k} S(n,j), not to a value satisfying the two-term recurrence at level k=3k=3 with fresh combinatorial content. More sharply: the bijective argument in the proof of the theorem used, in Case B, that inserting element nn into one of the kk blocks of a partition Q∈P(n−1,k)Q\in\mathcal P(n-1,k) gives kk 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 nn into empty block ii" versus "inserting nn into empty block jj" would produce the same set partition (a new singleton {n}\{n\} plus the same nonempty blocks of QQ) counted multiple times, since two empty unlabeled blocks are simply the same object. This overcounting exactly breaks the kk-to-one claim underlying the term k⋅S(n−1,k)k\cdot S(n-1,k), 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

SituationWhat happensCommon mistake
k=0, n≥1k=0,\ n\ge 1S(n,0)=0S(n,0)=0Forgetting to force S(0,0)=1S(0,0)=1 as the true base case, and instead setting S(n,0)=0S(n,0)=0 for all nn including n=0n=0
k=nk=nS(n,n)=1S(n,n)=1 (only the all-singletons partition)Confusing this with S(n,1)=1S(n,1)=1; both equal 11 but for different combinatorial reasons
k>nk>nS(n,k)=0S(n,k)=0Applying the recurrence blindly without checking that S(n−1,k−1)S(n-1,k-1) or S(n−1,k)S(n-1,k) might also need a zero base case, leading to negative-index lookups
Confusing with surjectionsS(n,k)≠S(n,k) \ne number of surjections [n]→[k][n]\to[k]The correct relation is Surj(n,k)=k! S(n,k)\text{Surj}(n,k) = k!\,S(n,k); omitting the k!k! undercounts labeled assignments by exactly the group of block-relabelings
Confusing with Stirling numbers of the first kindNotation {nk}\left\{{n\atop k}\right\} vs. [nk]\left[{n\atop k}\right]Mixing up set partitions (second kind) with permutation cycle counts ([[Stirling Numbers of the First Kindfirst kind]]) — they satisfy different recurrences entirely

The mathematician behind it

Origins · 1 minJames Stirling and how this was discovered
JS
James Stirling
1692–1770 · Scottish mathematician, Newtonian circle, Scotland and London

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 n!n!. 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.

History
- 1692: James Stirling born in Garden, Stirlingshire, Scotland.
- 1730: Stirling publishes Methodus Differentialis, developing finite-difference and interpolation methods underlying the later-named Stirling numbers.
- 1749–1750s: Stirling's numerical machinery is absorbed into the growing theory of finite differences used by successors across Europe.
- 1770: James Stirling dies in Edinburgh.
- 19th–20th century: the modern combinatorial notations S(n,k)S(n,k) and {nk}\left\{{n\atop k}\right\} and their systematic connection to set partitions, surjections, and the Bell numbers are consolidated in the enumerative-combinatorics literature.
Is S(n,k)S(n,k) the same as the number of ways to color nn objects with kk colors so every color is used?

Not quite, but they are closely related. Coloring nn labeled objects with kk labeled colors such that every color is used at least once is exactly a surjection from the nn-set onto the kk-set of colors, which is counted by k! S(n,k)k!\,S(n,k), not by S(n,k)S(n,k) itself. The Stirling number S(n,k)S(n,k) 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 S(n,k)S(n,k) is exactly the right count. The factor k!k! is the number of ways to assign the kk distinguishable color labels to the kk indistinguishable blocks after the fact.

How does S(n,k)S(n,k) relate to the Bell numbers?

The Bell number BnB_n counts all partitions of an nn-element set, with no restriction on the number of blocks, so it is obtained by summing S(n,k)S(n,k) over every possible block count kk from 00 to nn:

Bn=∑k=0nS(n,k).B_n = \sum_{k=0}^{n} S(n,k).

For example B4=S(4,0)+S(4,1)+S(4,2)+S(4,3)+S(4,4)=0+1+7+6+1=15B_4 = S(4,0)+S(4,1)+S(4,2)+S(4,3)+S(4,4) = 0+1+7+6+1=15. This makes S(n,k)S(n,k) a refinement of BnB_n by number of blocks, exactly analogous to how binomial coefficients (nk)\binom{n}{k} refine 2n2^n by subset size. The Bell numbers satisfy their own recurrence derivable directly from this sum together with the Stirling recurrence.

Why is the recurrence S(n,k)=k S(n−1,k)+S(n−1,k−1)S(n,k) = k\,S(n-1,k) + S(n-1,k-1) considered a proof and not just a pattern?

The recurrence is proved by explicitly constructing a bijection (in Case A) and an exact kk-to-one correspondence (in Case B) between the set of partitions counted by S(n,k)S(n,k) and the disjoint union of the sets counted by S(n−1,k−1)S(n-1,k-1) and kk copies of the set counted by S(n−1,k)S(n-1,k). Because every partition of [n][n] into kk blocks falls into exactly one of the two cases (whether nn's block is a singleton), and the correspondences in each case are shown to be exact bijections (respectively an exact kk-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 kk or nn 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 nn) implicitly assumes n≥1n\ge1. By definition, S(0,0)=1S(0,0)=1 because the empty set has exactly one partition: the empty collection of blocks. For n≥1n\ge1, S(n,0)=0S(n,0)=0, since a nonempty set cannot be partitioned into zero blocks (the union of zero blocks is empty, not [n][n]). Also S(0,k)=0S(0,k)=0 for k≥1k\ge1, since the empty set cannot be partitioned into a positive number of nonempty blocks. These base cases, together with the recurrence for n,k≥1n,k\ge1, are what make the entire triangle computable from the top down.

How is S(n,k)S(n,k) different from Stirling numbers of the first kind?

Stirling numbers of the second kind, S(n,k)S(n,k), count partitions of a set into kk 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 [n][n] having exactly kk 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 S(n,k)S(n,k)?

Yes. Using inclusion–exclusion on the surjection count and then dividing out the labeling factor k!k! gives

S(n,k)=1k!∑j=0k(−1)j(kj)(k−j)n.S(n,k) = \frac{1}{k!}\sum_{j=0}^{k} (-1)^{j}\binom{k}{j}(k-j)^n.

This formula is exact for all n,k≥0n,k\ge 0 (with the usual convention 00=10^0=1 when n=k=0n=k=0), 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 S(n,k)S(n,k) show up outside pure combinatorics?

Beyond counting set partitions directly, S(n,k)S(n,k) appears as the coefficients converting monomials xnx^n into falling factorials (x)k=x(x−1)⋯(x−k+1)(x)_k = x(x-1)\cdots(x-k+1), 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.

Before this

Where this leads