Stirling Numbers and Bell Numbers Calculator

Calculate s(n,k), |s(n,k)|, S(n,k), and B(n) together. Results use exact integer arithmetic and include the recurrence substitutions and complete row for the selected n.

Enter n and k

n is the number of labeled elements. k is the number of permutation cycles or nonempty set blocks. Use integers satisfying 0 ≤ k ≤ n ≤ 300.

Whole number from 0 to 300.

Whole number from 0 to n.

Private by design: n and k are validated and calculated on this device. Inputs are not uploaded, saved, or added to the page URL.

Exact results

The n = 6, k = 3 example is calculated below.

Advertisement

What Stirling and Bell numbers count

First kind: permutation cycles

The unsigned number |s(n,k)|, also written c(n,k) or [n k], counts permutations of n labeled elements with exactly k disjoint cycles. The signed convention is s(n,k) = (−1)ⁿ⁻ᵏ|s(n,k)|.

Second kind: nonempty blocks

S(n,k), also written {n k}, counts ways to partition a set of n labeled elements into exactly k nonempty, unlabeled blocks.

Bell number: every set partition

B(n) counts all partitions of an n-element set. It does not fix the number of blocks, so it is the sum of the complete second-kind row.

Empty and impossible cases

The empty set has one empty partition, giving s(0,0) = S(0,0) = B(0) = 1. For positive n, values at k = 0 are zero. Values with k > n are mathematically zero, but the calculator asks for k ≤ n so the requested row entry is explicit.

Stirling and Bell number formulas

The calculator starts with s(0,0) = |s(0,0)| = S(0,0) = 1 and treats missing row entries as zero.

Signed first kind

s(n,k) = s(n−1,k−1) − (n−1)s(n−1,k)

Adding the nth element either creates a new one-element cycle or inserts it into one of the n−1 positions, with the signed convention supplying the minus sign.

Unsigned first kind

|s(n,k)| = |s(n−1,k−1)| + (n−1)|s(n−1,k)|

The recurrence counts both cycle constructions without alternating signs.

Second kind

S(n,k) = S(n−1,k−1) + kS(n−1,k)

The nth element either forms a new singleton block or joins one of the k existing blocks.

Bell number

B(n) = ∑ₖ₌₀ⁿ S(n,k)

Summing over every possible number of nonempty blocks counts every set partition exactly once.

Worked example: n = 5 and k = 2

Signed first kind

s(5,2) = s(4,1) − 4s(4,2)
= −6 − 4(11) = −50

The corresponding unsigned cycle count is 50.

Second kind

S(5,2) = S(4,1) + 2S(4,2)
= 1 + 2(7) = 15

There are 15 partitions of five labeled elements into two nonempty blocks.

Bell number

B(5) = 0 + 1 + 15 + 25 + 10 + 1 = 52

There are 52 set partitions of a five-element set across all possible block counts.

Method, notation, and limits

The calculator builds the three triangular recurrences row by row through the requested n. It uses JavaScript BigInt values throughout: no floating-point approximation or scientific notation is used. The computation requires O(n²) integer operations and stores only the current and previous rows while calculating.

The first-kind notation varies between sources. This page follows the NIST convention in which lowercase s(n,k) is signed; the nonnegative permutation-cycle count is shown separately as |s(n,k)|. Uppercase S(n,k) denotes the second kind. Inputs are limited to 300 to keep exact row rendering and CSV export responsive on typical phones.

Definitions, recurrence signs, and tabulated values follow the NIST Digital Library of Mathematical Functions section on Stirling numbers. The Bell identity and definition follow its Bell numbers section.

Editorial review: Recurrences, empty-case conventions, and representative outputs checked against NIST DLMF tables. Last reviewed: .

Stirling numbers and Bell numbers FAQ

What is the difference between the two kinds of Stirling numbers?

First-kind numbers describe permutations by their number of cycles. Second-kind numbers describe set partitions by their number of nonempty blocks. They use the same inputs but count different objects.

Why are there signed and unsigned first-kind numbers?

The unsigned value is the actual permutation count. The signed value multiplies that count by (−1)ⁿ⁻ᵏ and appears naturally in algebraic identities involving falling factorials. Because notation is inconsistent across references, this calculator labels and reports both.

How are Bell numbers related to Stirling numbers of the second kind?

Each set partition has some number of blocks from 0 through n. Therefore B(n) = S(n,0) + S(n,1) + ··· + S(n,n).

What is S(n,0)?

S(0,0) = 1 because the empty set has one partition into zero blocks. For every positive n, S(n,0) = 0 because a nonempty set cannot be divided into zero blocks.

What happens when k equals n?

All three Stirling forms equal 1. The identity permutation is the only permutation with n one-element cycles, and the singleton partition is the only partition into n blocks.

Are Stirling numbers the same as Stirling's approximation?

No. Stirling numbers are combinatorial arrays involving cycles and set partitions. Stirling’s approximation estimates factorials; it is a different result named after James Stirling.

Are the very large results exact?

Yes. The calculator uses integer recurrences with arbitrary-precision BigInt arithmetic. Commas are display separators and do not indicate rounding.

Why is n limited to 300?

The values grow rapidly, and a complete row has n + 1 large integers. The limit keeps the exact calculation, display, copying, and CSV download practical on mobile devices.

Does the calculator store my inputs?

No. The calculation, copy action, and CSV creation run locally in your browser.

Explore more tools