Stirling Number Calculator (Second Kind)
Stirling numbers of the second kind, written S(n,k), count the number of ways to partition a set of n distinct elements into exactly k non-empty, unordered subsets. For instance, S(4,2) = 7 because the set 4 can be divided into exactly 2 non-empty parts in 7 distinct ways. Enter n and k (each from 0 to 10) to compute S(n,k) and view the complete Stirling triangle for all k values from 0 to n. The defining recurrence is S(n,k) = k times S(n-1,k) + S(n-1,k-1). The first term counts ways to add a new element to one of the k existing subsets; the second counts starting a new singleton subset, reducing the remaining problem to k-1 subsets. Stirling numbers of the second kind are fundamental in combinatorics: their row sums are Bell numbers (the total count of all set partitions), and they convert ordinary powers into falling factorial polynomials via the formula x^n = sum of S(n,k) times x(x-1)...(x-k+1).
Stirling triangle for the given n
| k |
|---|
Stirling number recurrence
S(n, k) = k * S(n-1, k) + S(n-1, k-1)
Base cases: S(0, 0) = 1; S(n, 0) = 0 for n > 0; S(0, k) = 0 for k > 0
Special values: S(n, 1) = 1; S(n, n) = 1; S(n, 2) = 2^(n-1) - 1
Stirling numbers: frequently asked questions
What are Stirling numbers of the second kind?
Stirling numbers of the second kind, written S(n,k) or {n choose k} in curly braces, count the number of ways to partition a set of n distinct elements into exactly k non-empty, non-ordered subsets. For example, S(4,2) = 7 because a 4-element set can be split into exactly 2 non-empty subsets in 7 ways.
What is the recurrence relation for S(n,k)?
The Stirling numbers of the second kind satisfy S(n,k) = k * S(n-1,k) + S(n-1,k-1), with base cases S(0,0)=1 and S(n,0)=S(0,k)=0 for n,k greater than 0. The factor k comes from placing element n into one of the existing k subsets; the term S(n-1,k-1) comes from starting a new subset containing only element n.
What is the difference between Stirling numbers of the first and second kind?
Stirling numbers of the second kind S(n,k) count set partitions into k non-empty subsets. Stirling numbers of the first kind s(n,k) count permutations of n elements with exactly k disjoint cycles. This calculator computes only the second kind.
What are S(n,k) equal to at the boundary cases?
S(n,1) = 1 for all n greater than 0 (only one way to put everything in one subset). S(n,n) = 1 for all n (only one way to put each element in its own subset). S(n,2) = 2^(n-1) - 1. S(n,n-1) = n*(n-1)/2 (choose which two elements share a subset).
How are Stirling numbers related to other combinatorial numbers?
The sum of S(n,k) for k from 0 to n equals the nth Bell number B(n), which counts all partitions of an n-element set. Also, x^n = sum of S(n,k) * x(x-1)(x-2)...(x-k+1) for k from 0 to n, expressing powers of x as falling factorial polynomials.
Sources
- Stirling numbers: OEIS A008277 (Stirling numbers of the second kind).
- Combinatorics reference: Wolfram MathWorld, Stirling Number of the Second Kind.
Reviewed by the CalculatorHub team, edited by James Graham, 14 June 2026. See our methodology.