Stirling Number Calculator
Calculate Stirling numbers of the first or second kind for given values of n and k. Find a single value, generate a complete row, or display a Stirling number triangle using exact integer arithmetic.
Calculate Stirling Numbers
What Are Stirling Numbers?
Stirling numbers are used in combinatorics, discrete mathematics, probability, and algebra. There are two principal kinds. The first kind relates to permutations and their cycles; the second kind counts partitions of a set into nonempty subsets.
Stirling Numbers of the First Kind
The signed Stirling number of the first kind, s(n,k), is related to the number of permutations of n elements with exactly k cycles. The unsigned version, c(n,k), counts those permutations without the alternating sign.
s(n,k) = s(n − 1,k − 1) − (n − 1)s(n − 1,k)
c(n,k) = c(n − 1,k − 1) + (n − 1)c(n − 1,k)
Stirling Numbers of the Second Kind
The Stirling number of the second kind, S(n,k), counts the number of ways to partition a set of n distinct elements into exactly k nonempty, unlabeled subsets.
S(n,k) = kS(n − 1,k) + S(n − 1,k − 1)
For both kinds, the usual boundary values include a value of 1 when n = k, and the convention that the zeroth Stirling number is 1: s(0,0) = c(0,0) = S(0,0) = 1.
Example Values
These examples can help you verify that you selected the intended definition.
| n | k | Signed first kind s(n,k) | Unsigned first kind c(n,k) | Second kind S(n,k) |
|---|---|---|---|---|
| 3 | 1 | 2 | 2 | 1 |
| 3 | 2 | -3 | 3 | 3 |
| 4 | 2 | 11 | 11 | 7 |
| 5 | 2 | -50 | 50 | 15 |
| 5 | 3 | 35 | 35 | 25 |
Frequently Asked Questions
What is the difference between Stirling numbers of the first and second kind?
First-kind numbers concern permutations classified by their number of cycles. Second-kind numbers count partitions of a set into a specified number of nonempty subsets.
Should I choose signed or unsigned first-kind numbers?
Choose signed s(n,k) when working with algebraic identities that use alternating signs. Choose unsigned c(n,k) when you need the number of permutations with exactly k cycles.
What if k is greater than n?
For nonnegative integers, Stirling numbers are zero when k exceeds n. For a single-value calculation, this page asks you to enter k no greater than n.
Can the calculator handle large integer results?
The calculator uses decimal-string addition and multiplication by small integers, so it does not depend on floating-point arithmetic or the optional BCMath extension. Input limits are provided to keep calculations manageable on shared hosting.
How are the results calculated?
The calculator builds a table from recurrence relations, starting with the value at (0,0). This method reuses earlier results and avoids repeatedly evaluating a large summation.
Related Math Calculators
Explore more calculators on Summe.org: