Stirling Numbers (Second Kind) Calculator
Compute the Stirling number of the second kind S(n, k), counting the ways to partition n labeled items into k non-empty unlabeled subsets.
Ways to partition n labeled items into k non-empty subsets
How does this calculator work?
The Stirling number of the second kind S(n, k) counts the ways to partition n labeled items into k non-empty unlabeled subsets. It follows the recurrence S(n,k) = k·S(n−1,k) + S(n−1,k−1) with S(0,0)=1. Summing over all k yields the Bell number B(n), the total number of set partitions.
Formula
How this is calculated
Enter two non-negative integers: n, the number of distinct (labeled) items, and k, the number of non-empty subsets you want to split them into. The subsets themselves are unlabeled, so only the grouping matters, not the order of the groups.
The calculator uses the classic recurrence S(n, k) = k · S(n−1, k) + S(n−1, k−1). Intuitively, when adding the nth item you either place it into one of the k existing subsets (k · S(n−1, k) ways) or start a brand-new subset with it alone (S(n−1, k−1) ways). The base cases are S(0,0) = 1 (one way to partition nothing into nothing) and S(n,0) = 0 for n > 0, and S(n,k) = 0 whenever k > n. The recurrence is evaluated with dynamic programming over a single row for efficiency.
The bar chart shows S(n, k) for every k from 1 to n, and their sum is the Bell number B(n), the total number of partitions of an n-element set. Results are exact integers; inputs are capped at n ≤ 170 so the counts stay within double-precision range. Non-integer entries are rounded to the nearest integer.
Frequently asked questions
It counts the number of ways to split n distinct items into exactly k non-empty groups, where the groups have no order or labels.
You cannot place one or more items into zero subsets while keeping every subset non-empty, so there are no valid partitions.
Summing S(n, k) over all k from 0 to n gives the Bell number B(n), the total count of all set partitions of n items.
Also known as
TG we-Calculate Editorial Team. (2026). Stirling Numbers (Second Kind) Calculator [Online calculator]. TG we-Calculate. https://we-calculate.com/calculator/stirling-second-kind-calculator
TG we-Calculate Editorial Team. "Stirling Numbers (Second Kind) Calculator." TG we-Calculate. 2026. https://we-calculate.com/calculator/stirling-second-kind-calculator.
TG we-Calculate Editorial Team, "Stirling Numbers (Second Kind) Calculator," TG we-Calculate, 2026. [Online]. Available: https://we-calculate.com/calculator/stirling-second-kind-calculator
@misc{wecalculate_stirling_second_kind_calculator, title = {Stirling Numbers (Second Kind) Calculator}, author = {{TG we-Calculate Editorial Team}}, howpublished = {\url{https://we-calculate.com/calculator/stirling-second-kind-calculator}}, year = {2026}, note = {TG we-Calculate} }
Did this calculator help you?
