On this page
Put five friends, Asha, Bilal, Chitra, Dev and Esha, into three study groups. No group may be empty, and the groups have no names. How many ways are there? The answer, 25, is a Stirling number of the second kind. Once you see where it comes from, many JEE distribution questions become short counts.
What are Stirling numbers of the second kind?
A Stirling number of the second kind, S(n, k), is the number of ways to partition the set {1, 2, …, n} into exactly k non-empty subsets (NIST Digital Library of Mathematical Functions, §26.8). The subsets have no order and no labels, so {1, 2}{3, 4} and {3, 4}{1, 2} are the same partition.
The picture at the top lists all seven ways to split four objects into two groups, so S(4, 2) = 7. Two edge values you can check in your head: S(n, 1) = 1 (everything in one group) and S(n, n) = 1 (everyone alone).
How does the recurrence S(n, k) = kS(n − 1, k) + S(n − 1, k − 1) work?
The recurrence S(n, k) = kS(n − 1, k) + S(n − 1, k − 1) is equation 26.8.22 in the NIST DLMF. The proof is a story about the last object, n.
Object n sits alone. Remove it, and the other n − 1 objects form k − 1 groups: S(n − 1, k − 1) ways.
Object n shares a group. Remove it, and the other n − 1 objects still form k groups. Object n could have joined any one of those k groups: k·S(n − 1, k) ways.
The cases never overlap and cover everything, so you add them. It resembles Pascal's rule, with an extra factor k because the existing groups can be told apart by their members.
What is the table of S(n, k) up to n = 6?
Build each row from the one above with the recurrence. These rows match OEIS A008277, reading k = 1, 2, …, n from left to right:
n = 1: 1
n = 2: 1, 1
n = 3: 1, 3, 1
n = 4: 1, 7, 6, 1
n = 5: 1, 15, 25, 10, 1
n = 6: 1, 31, 90, 65, 15, 1
Check one entry yourself: S(6, 3) = 3·S(5, 3) + S(5, 2) = 3·25 + 15 = 90.
One column has a shortcut: S(n, 2) = 2^(n−1) − 1, because each object picks side A or B (2ⁿ ways), you drop the 2 choices that leave a side empty, then halve because the sides have no names.
Add a whole row and you get a Bell number, the total number of ways to partition an n-element set: 1, 2, 5, 15, 52, 203 for n = 1 to 6 (OEIS A000110).
What is the formula for Stirling numbers of the second kind?
The explicit formula is S(n, k) = (1/k!) Σ (−1)^(k−j) C(k, j) jⁿ, summed from j = 0 to k; it is equation 26.8.6 in the NIST DLMF. It comes from inclusion–exclusion in three steps.
Label the groups 1 to k. Each object picks a group: kⁿ assignments.
Remove the assignments that leave some group empty. Inclusion–exclusion over the empty groups leaves kⁿ − C(k, 1)(k − 1)ⁿ + C(k, 2)(k − 2)ⁿ − … assignments that use every group.
Take the labels off. Each partition was counted k! times, once for each way to name its groups, so divide by k!.
Our inclusion–exclusion walkthrough on a Venn diagram shows why the signs alternate.
Worked check for S(5, 3): (243 − 96 + 3 − 0)/6 = 150/6 = 25, matching the table.
How are Stirling numbers linked to onto functions?
Step 2 above is exactly a count of onto functions. The number of surjections (onto functions) from an n-element set to a k-element set is k!·S(n, k) (OEIS A008277). From a 5-element set onto a 3-element set, that is 3!·25 = 150. Our guide to counting functions from A to B, including one-one and onto works through the JEE versions of this question.
How do you use Stirling numbers for books in boxes?
Take five different books and three boxes. Are the boxes labelled, and may a box stay empty?
Labelled boxes, empties allowed: 3⁵ = 243.
Labelled boxes, none empty: 3!·S(5, 3) = 150.
Identical boxes, none empty: S(5, 3) = 25.
Identical boxes, empties allowed: S(5, 1) + S(5, 2) + S(5, 3) = 1 + 15 + 25 = 41.
If the books were identical too, this would no longer be a Stirling count. Identical objects in identical boxes are partitions of a number, which our explainer on integer partitions covers.
If you mix up "distinct boxes" and "identical boxes" under exam pressure, revisit the idea in the Fermi Concept Library, then try a few distribution problems in the Fermi Problem Library, whose step-by-step solver explains the reasoning rather than printing an answer.



