Stirling Numbers Calculator

Enter n and k to get the Stirling numbers of the first and second kind.

Result

15
50

How it is calculated

Both numbers are built from small cases with exact integer arithmetic. Second kind, the ways to split n items into k non-empty groups: S(n,k) = k·S(n−1,k) + S(n−1,k−1). First kind, the permutations of n items with exactly k cycles: c(n,k) = (n−1)·c(n−1,k) + c(n−1,k−1). Both start from S(0,0) = c(0,0) = 1.

The first-kind value is the unsigned one; the signed Stirling number of the first kind has the sign (−1)n−k. The inputs n and k are rounded to whole numbers and must be between 0 and 25; values outside that range return no result. If k is larger than n, or k is 0 with n above 0, both results are 0. Big values are printed in full with thousands separators, for example n = 25 and k = 10 gives numbers with 19 and 22 digits.

Worked example

Take n = 5 and k = 2. Second kind: S(5,2) = 2·S(4,2) + S(4,1) = 2·7 + 1 = 15, so five labelled items can be split into two non-empty groups in 15 ways. First kind: c(5,2) = 4·c(4,2) + c(4,1) = 4·11 + 6 = 50, so 50 of the 120 permutations of five items consist of exactly two cycles. The tool shows second kind 15 and first kind 50.

Try this example →

Common mistakes

  • Mixing up the two kinds: the second-kind value (15 here) counts set partitions, while the first-kind value (50) counts permutations by cycles. They match only in trivial cases such as k = n, where both are 1.
  • Expecting the signed first-kind number: the tool returns the unsigned count, so no minus sign appears even when n − k is odd.
  • Treating groups as ordered: partitions counted by S(n,k) are unordered, so splitting into {1,2} and {3,4,5} is the same as the reverse order. Multiply by k! to count ordered, onto assignments.
  • Using n above 25: the tool stops at 25 to keep every digit exact, so larger values return no result rather than a rounded number.
  • Entering k = 0 for n above 0 and expecting 1: there is no way to place items into zero non-empty groups, so both results are 0. Only n = 0 and k = 0 gives 1.

About this calculator

Stirling numbers come in two families that both decompose n objects around the integer k, but they count different things. Stirling numbers of the first kind, s(n,k), count permutations of n elements that break into exactly k disjoint cycles; Stirling numbers of the second kind, S(n,k), count the ways to partition a set of n elements into exactly k non-empty, unordered subsets. Both satisfy simple recurrence relations — S(n,k) = k·S(n−1,k) + S(n−1,k−1), for instance — which is how this calculator builds them up from smaller cases.

Combinatorics and discrete math students use these numbers to solve counting problems on permutation cycle structure and set partitioning, while computer scientists apply Stirling numbers of the second kind in analyzing algorithms that group or bucket data, and in formulas that convert between falling factorials and ordinary powers.

Was this helpful?

You can pick up to 3 reactions.

Comments (1)

  • Editorial team

    Two quick sanity checks: for k equal to 2 the second kind is 2^(n-1) - 1, and for k equal to 1 the unsigned first kind is (n-1) factorial. For n = 6 these give 31 and 120. The tool covers n and k up to 25 and returns 0 when k is larger than n. Do you need the signed first-kind values, or a whole row of the table at once?

Popular calculators

All Calculators