Stirling Number Calculator
Calculate Stirling numbers of the first and second kind, plus Bell numbers for set partitions.
About this calculator
This calculator computes Stirling numbers — a family of counts used in combinatorics for grouping n distinct elements — in two variants selected by Kind, plus the associated Bell Number, the total count of ways to partition an n-element set into any number of non-empty, unlabeled blocks. Kind 2 (the default) computes S(n, k), the number of ways to partition n elements into exactly k non-empty subsets, using the recurrence S(n,k) = k·S(n-1,k) + S(n-1,k-1) in stirlingSecond(). Kind 1 instead computes unsigned Stirling numbers of the first kind, counting permutations of n elements with exactly k cycles, via a different recurrence in stirlingFirst(). n dominates both outputs: because k defaults to 3 and Kind defaults to 2, a ten percent sensitivity nudge moves each to 2.7/3.3 and 1.8/2.2, and Math.round() sends every one of those four probe points straight back to 3 and 2 respectively — so k and Kind look inert even though picking Kind 1 instead of 2, or a different k, produces a completely different number.
The engine also silently protects itself rather than erroring: k is clamped with Math.min(Math.round(inputs.k ?? 3), n) so it can never exceed n, and n itself is capped at 25 specifically "to avoid overflow," per the input's own help text — above that both the exact count and the Bell-number sum would exceed safe integer precision.
Inputs
Results
Stirling Number S(n,k)
25
Bell Number B(n)
52
How to Use This Calculator
- Enter n and k — the Stirling number S(n, k) counts a specific combinatorial structure.
- Select Kind: First (unsigned cycle decompositions) or Second (partitions into non-empty subsets).
- Review the Stirling Number S(n, k) for the selected kind.
- Check Bell Number B(n) — the sum of all Stirling numbers of the second kind for a given n.
- Use Stirling numbers in combinatorics, probability, and the analysis of divide-and-conquer algorithms.
How the result changes with n
| n | Stirling Number S(n,k) | Bell Number B(n) |
|---|---|---|
| 2.5 | 1 | 5 |
| 3.75 | 6 | 15 |
| 7.5 | 966 | 4,140 |
| 13 | 261,625 | 27,644,437 |
What each input means
- n
- Size of the set (max 25 to avoid overflow)
- k
- Number of cycles (1st kind) or blocks/partitions (2nd kind)
- Kind (1=First, 2=Second)
- Stirling number kind: 1st (permutation cycles) or 2nd (set partitions)
How this is calculated
Worked example, using the default values
- Identify Input Parametersn = 5, k = 3, Kind (1=First, 2=Second) = 2 = 3 input(s) provided
- Calculate Stirling Number SStirling Number S25 = 25
- Calculate Bell Number BBell Number B52 = 52
Engine last updated . Checked against 7 independently-derived tests — how we verify calculators. Built by Paul Gunder, a software engineer, not a licensed financial, medical, or legal professional.
Frequently Asked Questions
Why does moving k from 3 to 3.3 leave the Stirling Number completely unchanged?
The engine rounds k to the nearest whole number with Math.round(inputs.k ?? 3) before using it in the recurrence, since a fractional number of partition blocks makes no combinatorial sense. Nudging 3 up to 3.3 or down to 2.7 both round straight back to 3, so nothing in the calculation changes until the input actually crosses the next whole integer boundary.
What's the real difference between Kind 1 and Kind 2?
Kind 2, the default, counts partitions of an n-element set into exactly k non-empty, unordered subsets — the value used to build the Bell Number. Kind 1 instead counts permutations of n elements that decompose into exactly k disjoint cycles, an entirely different combinatorial structure computed by a separate recurrence, stirlingFirst(), so switching Kind does not scale the result — it replaces the formula outright.
What is the Bell Number B(n), and how is it computed?
Bell Number is the total number of ways to partition an n-element set into any number of non-empty blocks, regardless of k. The engine computes it by summing the Kind-2 Stirling number S(n, j) for every j from 0 to n, so it always reflects Kind 2's partition-counting recurrence even when the Kind selector is set to 1 for the main result.
Why is n capped at 25?
The engine clamps n with Math.min(Math.round(inputs.n ?? 5), 25), and its own help text explains why: values above 25 would make exact factorial-based results overflow standard floating-point precision, since Stirling and Bell numbers grow extremely fast — the calculator's own default row already reaches into the billions and quadrillions well before n hits its ceiling.
Related Calculators
The questions that sit next to this one — chosen by subject, including calculators filed under a different category.
Integer Partition Calculator
Count the number of integer partitions of n with optional constraints on maximum part size and distinctness.
Discrete MathematicsPermutations & Combinations Calculator
Calculate permutations and combinations with or without repetition for any n and r values.
Discrete MathematicsBinomial Coefficient Calculator
Calculate nCr and nPr values with Pascal's triangle row visualization.
More in Math & Statistics.