Stirling Number Calculator

Calculate Stirling numbers of the first or second kind for given values of n and k. Find a single value, generate a complete row, or display a Stirling number triangle using exact integer arithmetic.

Calculate Stirling Numbers

Choose the definition you need.

Choose one value, all values for n, or a table.

For single-value and row modes, use 0–100.

Used for single-value calculations; k must not exceed n.

Triangle mode supports maximum n from 0 to 30.

Select the Stirling number definition and calculation mode. All calculations are performed by PHP on the server.
Reset calculator

What Are Stirling Numbers?

Stirling numbers are used in combinatorics, discrete mathematics, probability, and algebra. There are two principal kinds. The first kind relates to permutations and their cycles; the second kind counts partitions of a set into nonempty subsets.

Stirling Numbers of the First Kind

The signed Stirling number of the first kind, s(n,k), is related to the number of permutations of n elements with exactly k cycles. The unsigned version, c(n,k), counts those permutations without the alternating sign.

Signed recurrence:
s(n,k) = s(n − 1,k − 1) − (n − 1)s(n − 1,k)
Unsigned recurrence:
c(n,k) = c(n − 1,k − 1) + (n − 1)c(n − 1,k)

Stirling Numbers of the Second Kind

The Stirling number of the second kind, S(n,k), counts the number of ways to partition a set of n distinct elements into exactly k nonempty, unlabeled subsets.

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

For both kinds, the usual boundary values include a value of 1 when n = k, and the convention that the zeroth Stirling number is 1: s(0,0) = c(0,0) = S(0,0) = 1.

Example Values

These examples can help you verify that you selected the intended definition.

n k Signed first kind s(n,k) Unsigned first kind c(n,k) Second kind S(n,k)
31221
32-333
4211117
52-505015
53353525

Frequently Asked Questions

What is the difference between Stirling numbers of the first and second kind?

First-kind numbers concern permutations classified by their number of cycles. Second-kind numbers count partitions of a set into a specified number of nonempty subsets.

Should I choose signed or unsigned first-kind numbers?

Choose signed s(n,k) when working with algebraic identities that use alternating signs. Choose unsigned c(n,k) when you need the number of permutations with exactly k cycles.

What if k is greater than n?

For nonnegative integers, Stirling numbers are zero when k exceeds n. For a single-value calculation, this page asks you to enter k no greater than n.

Can the calculator handle large integer results?

The calculator uses decimal-string addition and multiplication by small integers, so it does not depend on floating-point arithmetic or the optional BCMath extension. Input limits are provided to keep calculations manageable on shared hosting.

How are the results calculated?

The calculator builds a table from recurrence relations, starting with the value at (0,0). This method reuses earlier results and avoids repeatedly evaluating a large summation.

Related Math Calculators

Explore more calculators on Summe.org: