Stars and Bars Calculator
Enter the items and groups to count the distributions.
Result
How it is calculated
The tool counts the ways to share n identical items among k distinct groups, where it matters which group gets what but not which individual item. If groups may be empty: ways = C(n + k − 1, k − 1). If every group must get at least one item: ways = C(n − 1, k − 1), which is 0 when n is smaller than k. Here C(a, b) is the binomial coefficient, a! ÷ (b! × (a − b)!). Items and groups are rounded to whole numbers, items cannot be negative and groups must be at least 1; either count above 10,000,000 returns no result. Results below 1015 are written in full; larger ones appear in scientific notation, such as 4.8376 × 10³⁶, and are approximate.
Worked example
Share 10 identical sweets among 4 children, where a child may get none. Step 1: n = 10, k = 4. Step 2: ways = C(10 + 4 − 1, 4 − 1) = C(13, 3). Step 3: C(13, 3) = 13 × 12 × 11 ÷ 6 = 286. If each child had to get at least one sweet, the formula would be C(9, 3) = 84.
Common mistakes
- Choosing the empty-groups mode when each group must get at least one item, which overcounts (286 instead of 84 here).
- Using it for distinct items; for distinct objects every item chooses its group, giving kn, not a binomial coefficient.
- Using it when the groups are identical too; then you are counting partitions, a different and harder count.
- Swapping the item and group counts, which gives a very different result.
- Forgetting a minimum other than 1: if each group needs at least 2, subtract the guaranteed items first and count what is left.
About this calculator
The stars and bars theorem, a classic result in combinatorics popularized by William Feller, counts the number of ways to partition n identical items among k distinct groups. With empty groups allowed, the count is the binomial coefficient C(n + k − 1, k − 1) — visualized as arranging n stars and k − 1 bars in a row; without empty groups permitted, it becomes C(n − 1, k − 1), since each group must first receive one item before the rest are distributed freely.
This calculator takes your item and group counts, applies the correct binomial coefficient for whichever variant you choose, and returns the number of distinct distributions. Combinatorics students, competitive programmers, and instructors teaching discrete mathematics use it to check homework and contest problems that reduce to "how many ways can identical objects be split among distinct bins" — a pattern that also underlies counting problems in probability, such as distributing indistinguishable balls into labeled urns.
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)
Beyond sharing sweets, this counts multiset choices. Picking 5 donuts from 3 flavours, where repeats are fine and order does not matter, is 5 items in 3 groups with empty groups allowed, which gives 21. It also counts the non-negative whole-number solutions of x + y + z = 5. What counting problem are you trying to fit to it?