Stirling Numbers Calculator
Introduction: what Stirling numbers of the second kind count
Stirling numbers of the second kind turn a set-partition question into an exact count: if you have n labeled elements and want exactly k nonempty groups, the value S(n,k) tells you how many ways that split can happen. This calculator is built for that specific counting problem, so the output is not a rough score or a weighted estimate. It is the exact number of partitions under the standard Stirling-number convention.
That makes the page useful whenever you want to compare grouping choices, check a combinatorics homework answer, or confirm the size of a partition row before you use it in a proof. Instead of chasing a formula through a textbook each time, you can enter the pair n and k, let the recurrence do the work, and inspect the result in one place.
The sections below explain what the inputs mean, how the recurrence builds the count, how to read the single-value and row views, and which assumptions define the result. If you are trying to count partitions rather than measure something physical, this is the right kind of calculator to use.
What this Stirling number calculator solves
The question behind Stirling Numbers Calculator is very specific: “How many ways can I partition a labeled set into exactly k nonempty blocks?” That is why the inputs are integers rather than measurements with units. A value such as S(7,3) counts partitions of seven distinct items into three unlabeled groups, with every item assigned to one and only one block.
This makes the result different from a probability, a percentage, or a rate. You are not estimating how often something happens; you are counting how many valid arrangements exist under a fixed rule. If you want to model assignments, groupings, or partitions, the output helps you compare one choice of n and k against another without changing the counting convention in the middle of the problem.
For that reason, the most important question to answer before you compute is whether your situation really is a Stirling-number problem. If the items are distinct, the groups are nonempty, and the blocks are unlabeled, this calculator matches the structure you need.
How to use this Stirling numbers calculator
- Enter n as the number of labeled elements in the set you want to partition.
- Enter k as the exact number of nonempty blocks you want in each partition.
- Check Show all k for this n if you want the whole row and the Bell number for that n.
- Click Compute to recalculate the partition count and refresh the result panel.
- Confirm that the output is a whole-number count and that 0 ≤ k ≤ n before comparing different scenarios.
There are no unit conversions on this page because the inputs are counts, not measurements. If you are comparing multiple cases, write the pair n and k down before you change them so you can reproduce the same partition count later.
Inputs: what n, k, and Show all k mean
The form only asks for the values that define the partition count, so each field has a direct combinatorial meaning. The cleaner your interpretation of those fields, the easier it is to trust the result.
- n: the number of labeled objects in the set you are splitting.
- k: the number of nonempty groups the objects must be divided into.
- Show all k for this n: when checked, the calculator prints the full row S(n,0) through S(n,n) and the corresponding Bell number.
- Whole numbers: enter integers only; Stirling numbers count exact arrangements, not measured quantities.
There are no hidden defaults here. The empty fields are just starting points, so replace them with the set size and block count from your own problem before you rely on the output. If you are unsure about the right pair, start with a very small case you can verify by hand, then move up to the size you actually care about.
Formulas: the Stirling recurrence behind the calculator
Stirling numbers of the second kind are easy to build recursively. Once you know the smaller rows, each new value can be formed by deciding whether the newest labeled element begins a new block or joins one of the existing blocks. That logic is exactly what the calculator follows.
The recurrence used by the page is:
The base cases are the standard ones: S(0,0)=1, S(n,0)=0 for n>0, S(n,1)=1, and S(n,n)=1. Those values anchor the first row and the edges of the triangle, which is why the calculator can safely build every valid entry from smaller ones.
When you check the row view, the page sums those entries to show the Bell number for that n:
So the formula section is not about approximations or weighted sums. It is about the exact combinatorial rule that creates the row the calculator displays.
Worked example: S(5,2) and the n=5 row
A concrete Stirling-number example makes the recurrence easier to trust. Suppose you enter n=5 and k=2. The calculator is counting the ways to split five labeled items into two nonempty unlabeled blocks.
Using the recurrence, you can build the answer from smaller entries:
- S(3,2)=3, because three labeled items can be split into two blocks in three ways.
- S(4,2)=S(3,1)+2·S(3,2)=1+2·3=7.
- S(5,2)=S(4,1)+2·S(4,2)=1+2·7=15.
That means the calculator should return 15 for S(5,2). If you check Show all k for this n, the row for n=5 is 0, 1, 15, 25, 10, 1, and the Bell number for that row is 52. The row view is helpful because it shows how the same set size produces very different counts as the block count changes.
This example also shows why the input pair matters so much. A small change in k changes which partitions are valid, while a small change in n opens the door to many more arrangements. In partition counting, the numbers can grow faster than intuition suggests, which is exactly why it helps to verify a small case before scaling up.
Comparison table: how the count changes when n shifts by one
Stirling counts are more informative when you compare neighboring integer inputs than when you try to force them into percentage scenarios. The table below keeps k=2 fixed so you can see what happens when the set size changes by one element.
| Scenario | n | k | S(n,k) | Interpretation |
|---|---|---|---|---|
| Fewer elements | 4 | 2 | 7 | One fewer labeled item leaves fewer ways to split the set into two blocks. |
| Baseline | 5 | 2 | 15 | This is the reference case used in the worked example above. |
| More elements | 6 | 2 | 31 | Adding one labeled item creates many more valid partitions, so the count rises quickly. |
If you want to test sensitivity in this calculator, adjust one integer at a time and compare the exact counts. That is the most honest way to read a Stirling-number result, because the output responds to combinatorial structure rather than to percentage-style perturbations.
How to interpret a Stirling-number result
The result panel is designed to show the exact partition count in the simplest possible format. When you see a single value, read it as S(n,k); when you use the row option, read the output as the whole Stirling row for that n plus the Bell number that totals the row.
To sanity-check a result, ask whether the value is a whole number, whether k is within the valid range, and whether nearby inputs move the count in the direction combinatorics predicts. That is a better test here than checking a unit or a conversion factor, because Stirling numbers are counts of arrangements, not measured quantities. If a value looks odd, compare it with a smaller row or a nearby k to see whether the change is consistent.
You can also use the Copy Result button to paste the answer into notes, homework, or a message. It copies the displayed text only, so if you need the exact input pair later, keep your own record of the n and k values alongside the output.
Limitations when counting set partitions
This calculator follows the standard Stirling-number rules, so its assumptions are the same ones used in ordinary combinatorics. It counts labeled elements, nonempty blocks, and unlabeled partitions, and it does not try to reinterpret those choices for you.
- Integer-only inputs: n and k must be whole numbers.
- Valid range: when you ask for a single entry, the calculator expects 0 ≤ k ≤ n.
- Rapid growth: the counts can rise quickly as n increases, so rows may get large even though each value is exact.
- Counting convention: the page uses the standard second-kind Stirling convention, not a weighted or approximate variant.
There are no unit conversions because the inputs are counts rather than measurements. If you are using the output for teaching, checking homework, or building a proof, confirm the indexing convention before you quote a value. Once the convention is clear, the calculator is a quick way to verify a single number or an entire row of partition counts.
