Values are computed exactly for n and k from 0 to 35. The recurrence table and visualization show at most 12 rows.
Stirling and Bell Numbers Calculator
Explore Stirling numbers, Bell numbers, recurrence tables, and what each family counts.
Results are calculated automatically as you enter data.
▼ See explanations and tips below ▼
Related Calculators
What Are Stirling and Bell Numbers?
Stirling and Bell numbers are families of integers used to count structured arrangements of finite sets. They are most useful when ordinary permutation and combination formulas are not enough because the question involves groups, blocks, cycles, or all possible partitions.
The three main families are:
- Stirling numbers of the second kind, written here as \(S(n,k)\), count ways to split \(n\) distinct, labeled items into \(k\) nonempty, unlabeled blocks.
- Unsigned Stirling numbers of the first kind, written here as \(c(n,k)\), count permutations of \(n\) distinct items that have exactly \(k\) disjoint cycles.
- Signed Stirling numbers of the first kind, written here as \(s(n,k)\), are algebraic coefficients related to the same cycle counts, but with signs that alternate according to \(n-k\).
- Bell numbers, written here as \(B(n)\), count all set partitions of \(n\) labeled items, regardless of how many blocks are used.
These numbers are unitless counts. A result such as \(S(6,3)=90\) means there are exactly 90 valid arrangements of the type being counted, not 90 percent or 90 units of measurement.
Why These Numbers Matter
Many counting problems ask more than “how many ways can we choose or order objects?” They ask how objects can be grouped, classified, cycled, or partitioned. Stirling and Bell numbers give a systematic way to answer those questions.
They appear in topics such as:
- grouping distinct objects into unlabeled teams, boxes, categories, or clusters;
- counting permutations by their cycle structure;
- building recurrence tables in combinatorics;
- changing between powers and falling factorials in algebra;
- counting all possible partitions of a finite set.
For students, these numbers are a bridge between basic counting formulas and more advanced enumerative combinatorics. For educators, they are useful because each recurrence has a clear “build the next row from the previous row” interpretation.
Key Terms to Know
- Labeled items: Items are distinct. For example, people named Ana, Ben, and Cara are labeled because swapping Ana and Ben changes the arrangement.
- Unlabeled blocks: The groups themselves have no names. The partition \(\{\{1,2\},\{3\}\}\) is the same as \(\{\{3\},\{1,2\}\}\).
- Set partition: A way to split a set into nonempty blocks so that every item appears in exactly one block.
- Permutation cycle: A cycle notation description of how a permutation moves elements around. Fixed points count as cycles of length 1.
- Recurrence relation: A formula that computes a value from earlier values.
- Falling factorial: The product
with \((x)_0=1\).
How Stirling Numbers of the Second Kind Work
A Stirling number of the second kind, \(S(n,k)\), counts the number of ways to partition \(n\) labeled items into \(k\) nonempty unlabeled blocks.
For example, \(S(3,2)=3\) because the set \(\{1,2,3\}\) can be split into two nonempty blocks in these three ways:
- \(\{1,2\},\{3\}\)
- \(\{1,3\},\{2\}\)
- \(\{2,3\},\{1\}\)
The recurrence is:
This formula has a simple counting explanation. When adding the item \(n\) to a partition:
- it can form a new block by itself, giving \(S(n-1,k-1)\) possibilities;
- or it can join one of the \(k\) existing blocks, giving \(kS(n-1,k)\) possibilities.
The usual boundary value is:
For ordinary nonnegative integer inputs, \(S(n,k)=0\) when \(k>n\) because \(n\) items cannot fill more than \(n\) nonempty blocks.
How Stirling Numbers of the First Kind Work
Stirling numbers of the first kind are about permutation cycles rather than set partitions.
The unsigned value \(c(n,k)\) counts the number of permutations of \(n\) labeled items with exactly \(k\) cycles. Its recurrence is:
The two terms represent two cases when adding the new item \(n\):
- \(n\) can become its own one-element cycle, contributing \(c(n-1,k-1)\);
- or \(n\) can be inserted into one of the existing cycle positions of a permutation of \(n-1\) items, contributing \((n-1)c(n-1,k)\).
The signed first-kind value \(s(n,k)\) uses the related recurrence:
The signed and unsigned versions are connected by:
So the absolute value \(|s(n,k)|\) is the same cycle count as \(c(n,k)\), while the sign is part of the algebraic meaning.
The signed numbers also appear as coefficients when a falling factorial is expanded in powers of \(x\):
This is why signed first-kind values should not be interpreted as ordinary counts when the answer is negative. The sign is meaningful algebraically, but a negative value is not a negative number of arrangements.
How Bell Numbers Work
A Bell number, \(B(n)\), counts all ways to partition \(n\) labeled items into nonempty unlabeled blocks. It does not fix the number of blocks.
Because \(S(n,k)\) counts partitions into exactly \(k\) blocks, the Bell number is the row sum of the second-kind Stirling numbers:
For \(n=3\):
The five partitions of \(\{1,2,3\}\) are:
- \(\{1,2,3\}\)
- \(\{1,2\},\{3\}\)
- \(\{1,3\},\{2\}\)
- \(\{2,3\},\{1\}\)
- \(\{1\},\{2\},\{3\}\)
Examples of Stirling and Bell Numbers in Practice
Example 1: Grouping Labeled Items into Blocks
Suppose you have four distinct students and want to split them into two nonempty unlabeled groups. This is counted by \(S(4,2)\).
Using the recurrence:
Since \(S(3,1)=1\) and \(S(3,2)=3\):
There are 7 ways to split four labeled students into two nonempty unlabeled groups.
Example 2: Counting Permutations by Cycles
For \(n=3\), the unsigned first-kind value \(c(3,2)\) counts permutations of three labeled items with exactly two cycles.
The three possibilities are represented by:
- \((1\ 2)(3)\)
- \((1\ 3)(2)\)
- \((2\ 3)(1)\)
So:
The signed value is:
The negative sign is not a count of arrangements; it is part of the signed coefficient convention.
Example 3: Counting All Partitions
If you want all ways to partition four labeled items into any number of nonempty blocks, use \(B(4)\).
The second-kind row is:
So:
There are 15 total set partitions of four labeled items.
Example 4: The Boundary Case \(k>n\)
A request such as \(S(3,5)\) has no valid set partitions because three items cannot fill five nonempty blocks. Similarly, a permutation of three items cannot have five cycles.
For these ordinary Stirling-number interpretations:
and the corresponding first-kind count is also zero when \(k>n\).
How to Interpret the Result
The meaning of the result depends on the selected number family.
| Selected family | What the result means |
|---|---|
| \(S(n,k)\) | The number of ways to partition \(n\) labeled items into \(k\) nonempty unlabeled blocks. |
| \(c(n,k)\) | The number of permutations of \(n\) labeled items with exactly \(k\) cycles. |
| \(s(n,k)\) | A signed coefficient whose absolute value matches the unsigned cycle count. |
| \(B(n)\) | The total number of set partitions of \(n\) labeled items across all possible block counts. |
A result of 0 usually means the requested structure is impossible under the standard nonnegative-integer interpretation. The most common case is \(k>n\).
For Bell numbers, there is no single \(k\) value because the Bell number already sums over every possible number of blocks. In other words, \(B(n)\) counts all possible \(k\) values at once.
Common Mistakes and Misconceptions
Confusing the Two Kinds of Stirling Numbers
The second kind counts partitions into blocks. The first kind counts permutations by cycles. They are related, but they answer different counting questions.
Treating Signed First-Kind Values as Ordinary Counts
The value \(s(n,k)\) may be negative. Its absolute value corresponds to the unsigned cycle count, but the sign belongs to its algebraic role as a coefficient in falling factorial expansions.
Using \(k\) with Bell Numbers
Bell numbers do not use a fixed \(k\). They add together all second-kind values in a row:
For \(n>0\), the \(S(n,0)\) term is 0, but including it keeps the summation notation consistent.
Expecting a Nonzero Result When \(k>n\)
You cannot split \(n\) items into more than \(n\) nonempty blocks, and a permutation of \(n\) items cannot have more than \(n\) cycles. For standard nonnegative integer inputs, this makes the value 0.
Rounding or Entering Decimal Indices
Stirling and Bell numbers in this setting are defined for nonnegative integer indices. Decimal, fractional, symbolic, and negative indices are not part of the calculator’s supported interpretation.
Confusing the Row Display with the Target Value
The number of rows shown in a table or visualizer is a display choice. It does not change the selected mathematical target value, except that the display must include enough rows to show the chosen entry.
When to Use These Numbers
Use Stirling numbers of the second kind when you need to count ways to divide distinct items into a fixed number of nonempty unlabeled groups.
Use unsigned Stirling numbers of the first kind when you need to count permutations according to how many cycles they have.
Use signed Stirling numbers of the first kind when the algebraic sign matters, especially in formulas involving falling factorials.
Use Bell numbers when you need the total number of partitions of a labeled set and do not want to fix the number of blocks in advance.
Limitations and Things to Keep in Mind
Stirling and Bell numbers grow quickly. Even moderate values of \(n\) can produce large integers, so exact results may be much larger than the small examples used for learning.
This calculator requires whole-number text inputs in the supported ranges. It rejects decimal, negative, blank, and over-limit entries instead of truncating or clamping them. For this calculator:
- \(n\) is limited to the range 0 through 35.
- \(k\) is limited to the range 0 through 35.
- displayed recurrence rows are limited to the range 0 through 12.
- Bell number mode does not use \(k\).
- table values and the main result are exact integer values.
- visual graph labels may abbreviate large values even when the exact result is shown elsewhere.
The calculator is intended for standard nonnegative integer combinatorics. It does not support negative-index Stirling numbers, symbolic parameters, fractional-index extensions, or full enumeration of large set partitions.
How to Use This Calculator
- Choose the number family: \(S(n,k)\), \(c(n,k)\), \(s(n,k)\), or \(B(n)\).
- Enter \(n\) as a nonnegative integer within the supported range.
- Enter \(k\) when using a Stirling number family. Bell number mode does not require \(k\).
- Set the number of rows to control how much of the recurrence table and visualizer is displayed.
- Review the exact result, family summary, recurrence note, table, and visualizer.
- Use the full exact result or recurrence table when graph node labels are shortened.
- If the visualizer allows node selection, click a node to explore another \(n,k\) entry.
Frequently Asked Questions
What is the difference between \(S(n,k)\) and \(c(n,k)\)?
\(S(n,k)\) counts partitions of \(n\) labeled items into \(k\) nonempty unlabeled blocks. \(c(n,k)\) counts permutations of \(n\) labeled items with exactly \(k\) cycles. The same input values can produce completely different answers because the counted structures are different.
Why does \(B(n)\) not use \(k\)?
\(B(n)\) counts all set partitions of \(n\) labeled items, no matter how many blocks there are. It is the sum of \(S(n,k)\) across all possible \(k\) values from 0 to \(n\).
Why is \(S(0,0)=1\)?
The value \(S(0,0)=1\) represents one empty partition of the empty set. This convention is useful because it makes recurrence tables start cleanly and keeps formulas consistent at the boundary.
Why is the result 0 when \(k>n\)?
For standard Stirling-number counting, \(k\) represents the number of nonempty blocks or cycles. With only \(n\) items, there cannot be more than \(n\) nonempty blocks or more than \(n\) permutation cycles.
Why can signed Stirling numbers be negative?
Signed Stirling numbers of the first kind are coefficients in a polynomial expansion. Their signs follow \((-1)^{n-k}\), so they are not simple nonnegative counts even though their absolute values match unsigned cycle counts.
Are the results exact?
The main result and recurrence table are exact integer values within the calculator’s supported range. A visual graph label may be abbreviated for readability, so use the exact result or table if you need the full integer.
Sources and References
Books
- Ronald L. Graham, Donald E. Knuth, and Oren Patashnik. Concrete Mathematics: A Foundation for Computer Science. 2nd ed., Addison-Wesley, 1994. Relevant section: “Stirling Numbers,” §6.1, pp. 257–267. ISBN 9780134389981.
- Richard Grassl and Oscar Levin. More Discrete Mathematics via Graph Theory. Open Math Books. Relevant sections: Chapter 3, “Counting Partitions,” “Stirling Numbers of the Second Kind,” and “Bell Numbers.” https://discrete.openmathbooks.org/more/mdm/ch_advanced.html
Online and Official Sources
- National Institute of Standards and Technology. “DLMF §26.8 Set Partitions: Stirling Numbers.” NIST Digital Library of Mathematical Functions, accessed July 4, 2026. https://dlmf.nist.gov/26.8
- National Institute of Standards and Technology. “DLMF §26.7 Set Partitions: Bell Numbers.” NIST Digital Library of Mathematical Functions, accessed July 4, 2026. https://dlmf.nist.gov/26.7
- Eric W. Weisstein. “Stirling Number of the First Kind.” MathWorld—A Wolfram Resource, accessed July 4, 2026. https://mathworld.wolfram.com/StirlingNumberoftheFirstKind.html
- Eric W. Weisstein. “Stirling Number of the Second Kind.” MathWorld—A Wolfram Resource, accessed July 4, 2026. https://mathworld.wolfram.com/StirlingNumberoftheSecondKind.html