Stirling Numbers Calculator

Find the number of ways to split n objects into k nonempty groups, plus the Bell number.

Math and PercentUpdated 2026-11-203 min read
Stirling Numbers Calculator
Stirling number S(n,k)
...
Bell number B(n)...
Expression...

What it does

Stirling numbers of the second kind answer a counting question: in how many ways can n distinct objects be divided into k nonempty groups when the groups themselves have no labels? The answer is written S(n,k) and it appears in combinatorics, probability and the study of random allocations.

The recurrence is easy to justify. Look at one distinguished object. Either it joins one of the k groups already used by the other n minus one objects, giving k times S(n minus one, k), or it forms a new group on its own, giving S(n minus one, k minus one). Adding the two cases gives the rule the tool applies.

The boundary values matter. There is one way to put every object in its own group, so S(n,n) is 1. There is one way to partition zero objects into zero groups, so S(0,0) is 1, but no way to put positive objects into zero groups. The tool follows this standard convention.

Summing S(n,k) over all values of k gives the Bell number B(n), which counts every possible partition of n objects regardless of the number of groups. The tool prints it alongside S(n,k) so the two ideas can be compared.

The groups here are unlabeled. If the boxes were labeled, each partition could be assigned to boxes in k factorial ways, so the count would be k factorial times S(n,k). That distinction is a common source of off by a factor errors in counting problems. The tool uses exact integer arithmetic, so even values far beyond ordinary floating point precision stay unrounded.

How to use

  1. Enter the number of distinct objects n.
  2. Enter the number of nonempty groups k, which cannot exceed n.
  3. Read S(n,k), the number of unlabeled partitions.
  4. Read the Bell number, which sums over every possible number of groups.
  5. Check the boundary cases S(n,n) and S(n,1), which are both 1.
  6. Multiply by k factorial if your boxes are labeled rather than unlabeled.

Formula

S(n,k) = k x S(n-1,k) + S(n-1,k-1), with S(0,0) = 1, S(n,0) = 0 for n > 0 and S(n,n) = 1.
n
Number of distinct objects being partitioned.
k
Number of nonempty unlabeled groups.
S(n,k)
Stirling number of the second kind.
B(n)
Bell number, the sum of S(n,k) over all k.

The tool builds the whole triangle up to n, so each value comes from the two entries above it rather than from a closed form. Big integer arithmetic keeps the result exact. If k is greater than n, the answer is zero by convention, but the tool asks for k within range so the input is explicit.

Worked example

Example: ten objects into three groups

Defaults: n = 10 and k = 3.

  1. The recurrence is S(n,k) = k x S(n-1,k) + S(n-1,k-1).
  2. Build the rows from S(0,0) = 1 up to n = 10.
  3. At the tenth row and third column the value is 9,330.
  4. Summing across the whole tenth row gives the Bell number 115,975.
  5. The tool shows 9,330, 115,975 and S(10, 3).

Reference table

A small Stirling triangle
nS(n,1)S(n,2)S(n,3)
3131
4176
511525
1015119,330

Limits

  • Accepts n only up to 60 to keep the exact integer computation manageable.
  • Counts unlabeled groups, not assignments to labeled boxes.
  • Computes only Stirling numbers of the second kind.
  • Does not expand the result into a formula in factorials or powers.

Common mistakes

  • Forgetting that k cannot exceed n.
  • Using labeled boxes but reading the unlabeled count.
  • Assuming S(n,0) is 1 for positive n.
  • Confusing Stirling numbers of the first and second kind.
  • Expecting a floating point result for a large partition count.

Try it yourself

Quick checks. Answers sit tucked under each question.

How many ways can five objects be split into two groups?

S(5,2) is 15. The Bell number for five objects is 52.

What is S(0,0) and what Bell number does the tool show?

S(0,0) is 1 by convention and B(0) is also 1, the empty partition.

What happens if k is larger than n?

The tool returns the error Enter a whole k between 0 and n, because a partition cannot have more nonempty groups than objects.

Questions

What does S(n,k) count?

The number of ways to divide n distinct objects into k nonempty groups when the groups have no labels.

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

The only partition with as many groups as objects puts each object on its own.

What is a Bell number?

The total number of partitions of n objects, which is the sum of S(n,k) over all k.

How do labeled boxes change the answer?

Multiply by k factorial, because each unlabeled partition can be assigned to labeled boxes in that many ways.

Which Stirling numbers does this page use?

The second kind, based on set partitions. The first kind counts permutations by number of cycles.

Why use exact integers?

These counts grow very quickly, so floating point arithmetic would lose precision for moderate n.

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.