Stirling Numbers Calculator
Enter n and k to get the Stirling numbers of the first and second kind.
Result
How it is calculated
Both numbers are built from small cases with exact integer arithmetic. Second kind, the ways to split n items into k non-empty groups: S(n,k) = k·S(n−1,k) + S(n−1,k−1). First kind, the permutations of n items with exactly k cycles: c(n,k) = (n−1)·c(n−1,k) + c(n−1,k−1). Both start from S(0,0) = c(0,0) = 1.
The first-kind value is the unsigned one; the signed Stirling number of the first kind has the sign (−1)n−k. The inputs n and k are rounded to whole numbers and must be between 0 and 25; values outside that range return no result. If k is larger than n, or k is 0 with n above 0, both results are 0. Big values are printed in full with thousands separators, for example n = 25 and k = 10 gives numbers with 19 and 22 digits.
Worked example
Take n = 5 and k = 2. Second kind: S(5,2) = 2·S(4,2) + S(4,1) = 2·7 + 1 = 15, so five labelled items can be split into two non-empty groups in 15 ways. First kind: c(5,2) = 4·c(4,2) + c(4,1) = 4·11 + 6 = 50, so 50 of the 120 permutations of five items consist of exactly two cycles. The tool shows second kind 15 and first kind 50.
Common mistakes
- Mixing up the two kinds: the second-kind value (15 here) counts set partitions, while the first-kind value (50) counts permutations by cycles. They match only in trivial cases such as k = n, where both are 1.
- Expecting the signed first-kind number: the tool returns the unsigned count, so no minus sign appears even when n − k is odd.
- Treating groups as ordered: partitions counted by S(n,k) are unordered, so splitting into {1,2} and {3,4,5} is the same as the reverse order. Multiply by k! to count ordered, onto assignments.
- Using n above 25: the tool stops at 25 to keep every digit exact, so larger values return no result rather than a rounded number.
- Entering k = 0 for n above 0 and expecting 1: there is no way to place items into zero non-empty groups, so both results are 0. Only n = 0 and k = 0 gives 1.
About this calculator
Stirling numbers come in two families that both decompose n objects around the integer k, but they count different things. Stirling numbers of the first kind, s(n,k), count permutations of n elements that break into exactly k disjoint cycles; Stirling numbers of the second kind, S(n,k), count the ways to partition a set of n elements into exactly k non-empty, unordered subsets. Both satisfy simple recurrence relations — S(n,k) = k·S(n−1,k) + S(n−1,k−1), for instance — which is how this calculator builds them up from smaller cases.
Combinatorics and discrete math students use these numbers to solve counting problems on permutation cycle structure and set partitioning, while computer scientists apply Stirling numbers of the second kind in analyzing algorithms that group or bucket data, and in formulas that convert between falling factorials and ordinary powers.
Was this helpful?
You can pick up to 3 reactions.
Popular calculators
Loan Calculator
Monthly payment, total interest and full amortization schedule.
Percentage Calculator
Percent change, percent of, and ratio calculations.
Discount Calculator
Calculate final price, savings, and discount amount.
BMI Calculator
Body mass index from height and weight (metric or imperial).
Age Calculator
Compute your exact age in years, months and days from a birth date.
Compound Interest Calculator
Calculate the final amount and interest earned with compounding.
All Calculators
- Loan Calculator
- Profit Calculator
- Discount Calculator
- BMI Calculator
- Percentage Calculator
- Ideal Weight Calculator
- Age Calculator
- Pregnancy Due Date Calculator
- Compound Interest Calculator
- BMR Calculator (Basal Metabolic Rate)
- Tip Calculator
- Fuel Cost Calculator
- Date Difference Calculator
- Sleep Cycle Calculator
- Daily Water Intake Calculator
- Simple Interest Calculator
- Heart Rate Zones Calculator
- Running Pace Calculator
- Pet Age Calculator
- Calories Burned Calculator
- Macro Calculator
- TDEE Calculator (Total Daily Energy Expenditure)
- Waist-to-Hip Ratio Calculator
- Honor Roll Calculator
- One Rep Max (1RM) Calculator
- Ovulation Calculator
- Electricity Cost Calculator
- Unit Price Calculator
- Savings Goal Calculator
- Break-Even Point Calculator
- Paint Calculator
- Course Grade Average Calculator
- Business Days Calculator
- Time Duration Calculator
- Fuel Economy Calculator
- Temperature Converter
- Tile Calculator
- Aspect Ratio Calculator
- Roman Numeral Converter
- Goal Weight Timeline Calculator
- Salary Converter (Hourly to Annual)
- Credit Card Validator (Luhn)
- Body Surface Area (BSA) Calculator
- Feels-Like Temperature Calculator
- Ohm’s Law Calculator
- PPI (Pixel Density) Calculator
- Molar Mass Calculator
- Zodiac Sign Calculator (Western + Chinese)
- IBAN Validator
- Shoe Size Converter
- Country Info & Dialing Code Lookup
- Time Zone Difference (World Clock)
- CAGR (Compound Annual Growth Rate) Calculator
- Rule of 72 Calculator
- Blood Alcohol Content (BAC) Calculator
- Lean Body Mass (LBM) Calculator
- Pythagorean Theorem Calculator
- Speed Converter
- Download Time Calculator
- Date Calculator (Add/Subtract)
No calculators found
Comments (1)
Two quick sanity checks: for k equal to 2 the second kind is 2^(n-1) - 1, and for k equal to 1 the unsigned first kind is (n-1) factorial. For n = 6 these give 31 and 120. The tool covers n and k up to 25 and returns 0 when k is larger than n. Do you need the signed first-kind values, or a whole row of the table at once?