Stirling Numbers Calculator
Introduction to Stirling numbers of the second kind
Stirling numbers of the second kind answer one precise counting question: given n labeled objects, in how many ways can they be divided into exactly k nonempty groups? The answer is written S(n,k). A group is also called a block. The calculator returns an exact integer, not a probability, percentage, estimate, or measurement with units.
For example, if five distinct people must be arranged into two nonempty committees and the committee names do not matter, the relevant count is S(5,2). The people are labeled because each person is distinguishable; the blocks are unlabeled because swapping the two committee descriptions does not create a new partition. This distinction is the central idea behind this calculator.
Use this page to check a homework calculation, explore a row of the Stirling triangle, or compare possible numbers of groups for the same collection of objects. The row option also supplies a Bell number, which counts all partitions of a labeled set when the number of blocks is allowed to vary.
What this Stirling number calculator counts
This calculator applies to set partitions only. Every object belongs to one and only one block, every block must contain at least one object, and the order of blocks does not matter. Thus, splitting the set {a, b, c} as {a, b} and {c} is the same partition as {c} and {a, b}. By contrast, putting the objects into named boxes, allowing empty boxes, or arranging them in an ordered sequence is a different combinatorics problem.
The output can therefore grow surprisingly quickly even for modest input values. It represents every valid grouping of distinct elements under these rules. Before using a result, make sure that your objects are genuinely distinct and that you need exactly k groups. If group labels matter, a related counting method rather than a second-kind Stirling number may be appropriate.
How to use the Stirling numbers calculator
Enter n, the number of labeled elements, and k, the required number of nonempty blocks. Then select Compute. The result panel will show the single value S(n,k). Both inputs are counts, so use whole numbers rather than decimals or units.
If you select Show all k for this n, the calculator builds the complete row from S(n,0) through S(n,n). In this view the individual k value is not needed for the computation, although it remains available in the form for the next single-value calculation. The final line gives the Bell number for that row.
A quick check is useful: for a normal nonempty set, S(n,1)=1 because all elements can go in one block, and S(n,n)=1 because every element can stand alone. A request outside 0 โค k โค n has no valid set partitions, so the form asks for a valid pair before calculating.
Inputs for labeled elements and nonempty blocks
The two fields have simple, separate jobs. n is the size of the original set. It might be the number of students, tasks, colors, or symbols, provided those items are distinguishable. k is the exact number of groups after the split. There are no hidden conversion factors and no implied units.
When the row checkbox is selected, the sequence starts with S(n,0). For any positive n, that first entry is zero because a nonempty set cannot be partitioned into zero nonempty blocks. The rest of the row shows how the count changes as the requested number of blocks moves from one through n. This is often more revealing than looking at one value alone.
Formulas: the Stirling recurrence and Bell total
The calculator uses a recurrence that mirrors the act of adding one new labeled element. Either that newest element forms a block by itself, leaving a partition of the other nโ1 elements into kโ1 blocks, or it joins one of the k blocks in a partition of the other elements. Those mutually exclusive choices create the two terms below.
The boundary values make the recurrence usable: S(0,0)=1; S(n,0)=0 when n>0; and both S(n,1) and S(n,n) equal 1 for positive n. The page calculates with these exact base cases, rather than an approximation.
Adding every entry in a row removes the restriction on the number of blocks. The resulting Bell number counts all set partitions of n labeled elements:
Worked example: partitioning five labeled items into two blocks
Suppose five distinct items must be split into exactly two nonempty unlabeled groups. Enter n = 5 and k = 2. The recurrence first uses S(4,2)=7, then gives S(5,2)=S(4,1)+2ยทS(4,2)=1+2ยท7=15. The calculator should therefore display 15.
Checking the full row for n=5 produces 0, 1, 15, 25, 10, 1. Summing these entries gives B(5)=52. In plain language, there are 52 ways to partition five labeled objects if any positive number of unlabeled groups is allowed, while only 15 of those partitions have exactly two groups. This comparison is a useful reminder that the chosen k is part of the question, not an afterthought.
Interpreting a Stirling row and its Bell number
Read a single result as a count of valid partitions, not as a number of possible group labels. In a full row, position k corresponds to the exact number of blocks. The Bell number is the total of that row, so it is useful when you want every possible nonempty partition of a set of fixed size.
For a reliable sanity check, try a smaller nearby case. Holding k=2, the values S(4,2)=7, S(5,2)=15, and S(6,2)=31 show the fast growth caused by adding only one labeled element. This growth is normal. It does not mean the result has been converted into a percentage or that a unit has been omitted.
The Copy Result button copies the text currently shown in the result panel. Keep the input pair with that text when recording work, especially if you later compare several rows or use the result in a proof.
Limitations of this set-partition count
This page assumes the conventional second-kind definition throughout: elements are labeled, blocks are nonempty, and blocks are unlabeled. It does not count partitions of an infinite set, fractional numbers of objects, ordered groupings, or assignments to pre-named categories. It also uses ordinary JavaScript numbers, so exceptionally large inputs can eventually exceed exact integer precision even though the recurrence itself is mathematically exact.
For ordinary educational and exploratory inputs, the calculator is a quick verification tool. For very large combinatorics calculations, use a big-integer implementation or symbolic mathematics system, and state the convention being used. That small bit of context prevents most misunderstandings about Stirling numbers.
Stirling Sprint: build nonempty partitions
Take a short optional partition-building challenge. Tap a numbered element, then tap a block to place it. Fill every block before the timer ends; quick valid partitions build a streak and a bigger score.
Educational takeaway: a completed round is one example of a partition counted by S(n,k); the calculator counts every possible valid partition, not just the one you built.
