Stirling Number of the Second Kind Calculator

Count the ways to split n labeled objects into k nonempty unlabeled groups, with the Bell total alongside.

Math and PercentUpdated 2026-11-183 min read
Stirling Number of the Second Kind Calculator
A whole number from 0 to 60.
A whole number from 0 through n.
Stirling number S(n, k)
...
Bell number B(n)...

What it does

The Stirling numbers of the second kind answer a more precise question than the Bell numbers. Instead of counting all partitions of a set, they count only those with exactly k groups. The groups are unlabeled, so swapping two groups makes no new partition, but the elements themselves are distinct.

The numbers are named after James Stirling, an eighteenth century mathematician, and the label second kind distinguishes them from the Stirling numbers of the first kind that arise when expanding falling factorials. Both families appear in algebra, combinatorics and the analysis of algorithms.

The standard recurrence is short. A partition of n objects into k groups either leaves the nth object alone in a new group, which can happen in S(n - 1, k - 1) ways, or joins it to one of k existing groups, giving k times S(n - 1, k). Adding the two cases gives the answer.

This page applies that recurrence with exact integer arithmetic and also reports the Bell number for the same n. The Bell value is the sum of the whole row, so it acts as a built in check: if the individual S(n, k) values were added across k, they would reach exactly the number shown alongside.

The input limit is 60, well beyond the point where listing partitions by hand is possible. Every digit of the result is printed, and inputs with k greater than n are rejected before calculation.

How to use

  1. Enter the object count n from 0 to 60.
  2. Enter the group count k from 0 through n.
  3. Read S(n, k) from the main result box.
  4. Check the Bell number shown beside it as the row total.
  5. The page opens with n = 4 and k = 2 for the worked example.
  6. Try n = 5 and k = 3 to confirm the value 25.

Formula

S(n, k) = S(n - 1, k - 1) + k x S(n - 1, k), with S(0, 0) = 1
n
The number of distinct objects being partitioned.
k
The exact number of nonempty groups required.
S(n, k)
The Stirling number of the second kind.

The boundary cases are S(n, 0) = 0 for n greater than zero, S(n, n) = 1, and S(n, 1) = 1. The recurrence only uses addition and multiplication, so results stay exact integers. Setting k greater than n is rejected because there cannot be more nonempty groups than objects.

Worked example

Example: S(4, 2)

Use n = 4 and k = 2, the defaults on this page.

  1. Write the recurrence for the chosen inputs: S(4, 2) = S(3, 1) + 2 x S(3, 2).
  2. Find S(3, 1) = 1, since three objects in one group make a single partition.
  3. Find S(3, 2) = 3, from three ways to choose the pair.
  4. Substitute: S(4, 2) = 1 + 2 x 3 = 7.
  5. The tool reports 7 for S(4, 2).
  6. The Bell number shown beside it is B(4) = 1 + 7 + 6 + 1 = 15.
  7. The row for n = 4 is 1, 7, 6, 1 for k = 1 through 4.

Reference table

Stirling numbers of the second kind by row
nk = 1k = 2k = 3k = 4k = 5Row total B(n)
2110002
3131005
41761015
51152510152

Limits

  • Groups are unlabeled; ordered groupings use ordered Bell numbers instead.
  • Empty groups are not allowed, so k cannot exceed n.
  • Inputs above 60 are rejected to keep the computation quick.
  • The tool returns counts only, not the partitions themselves.

Common mistakes

  • Treating the groups as labeled and multiplying by k factorial.
  • Forgetting the boundary value S(n, n) = 1.
  • Using S(n - 1, k) without multiplying by k.
  • Adding the two recurrence terms as if they were the same case.
  • Expecting the row total to equal n factorial rather than the Bell number.

Try it yourself

Quick checks. Answers sit tucked under each question.

What is S(5, 3)?

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

What is S(4, 1)?

It is 1, because putting all four objects in one group can be done in exactly one way.

What is the row total for n = 5?

Adding 1 + 15 + 25 + 10 + 1 gives 52, the Bell number B(5).

Questions

What does second kind mean?

It distinguishes these numbers from Stirling numbers of the first kind, which count permutations by cycles.

Why is S(0, 0) equal to 1?

The empty set has one partition into zero groups, the empty partition.

What happens when k equals n?

Every object must be alone, so S(n, n) = 1.

How does this relate to Bell numbers?

The Bell number for n is the sum of S(n, k) over every allowed k.

Are the results exact?

Yes. Only integer addition and multiplication are used, with no floating point steps.

What is the largest n accepted?

Sixty. Larger inputs return a clear message instead of a number.

Sources

How this page was checked. The formula above was matched against the cited sources, and the worked example was run through the tool on this page before publishing. If you spot an error, contact us so we can fix it and note the correction.