Stars and Bars Calculator
- Stars and bars counts the ways to split 10 identical items among 4 distinct boxes: lay the items in a row and choose where the 3 dividers fall among 13 slots.
- Allowing empty boxes, the count is C(13, 3) = 286 distributions.
- If every box must get at least one item, give each box one item first and distribute the rest: C(9, 3) = 84 distributions.
- With a per-box cap the count comes from inclusion-exclusion - subtract the distributions where a box overflows, add back the double overflows: 286 distributions are uncapped (same as the total).
The Stars and Bars Calculator answers a classic counting question: in how many ways can you split a fixed number of identical items among a fixed number of labeled groups? Enter the number of items and the number of groups, and the calculator returns the count. The items are treated as indistinguishable, so only how many land in each group matters, not which item goes where. Splitting 10 identical candies among 4 children, with empty hands allowed, can be done in 286 ways, but only 84 ways if every child must get at least one. The formula rests on a simple structure: the dividers separating the groups always number one fewer than the groups themselves, so 4 boxes need 3 dividers and 6 boxes need 5. Counting the arrangements of items and dividers together gives the total.
This divider-based method is the accepted standard for this kind of calculation because it counts every valid distribution exactly once, with no double counting and no missed cases. The results show how fast the counts grow: 12 balls into 5 boxes allow 1,820 distributions, and 20 tokens among 6 players explode to 53,130, growing combinatorially rather than linearly. The same method handles extra constraints. Capping each of the 5 boxes at 4 balls cuts the 1,820 distributions to 320, slightly fewer than the 330 ways that simply give every box at least one. This page shows the formula, step-by-step workings, worked examples and sources so you can follow each count yourself.
Worked examples
10 identical candies among 4 children, no cap
(10 · 4 · 0)
| Distributions (empty boxes allowed) | 286 |
| Distributions (every box gets at least one) | 84 |
| Distributions with the per-box cap | 286 |
| Dividers to place | 3 |
12 identical balls into 5 boxes, at most 4 per box
(12 · 5 · 4)
| Distributions (empty boxes allowed) | 1,820 |
| Distributions (every box gets at least one) | 330 |
| Distributions with the per-box cap | 320 |
| Dividers to place | 4 |
20 identical tokens among 6 players, no cap
(20 · 6 · 0)
| Distributions (empty boxes allowed) | 53,130 |
| Distributions (every box gets at least one) | 11,628 |
| Distributions with the per-box cap | 53,130 |
| Dividers to place | 5 |
How stars and bars is calculated
A stars and bars calculator works by turning a sharing problem into a choosing problem. Picture the items as stars in a row and the boundaries between groups as bars. If you are splitting 10 identical candies among 4 children, you line up 10 stars and place 3 dividers between them. The first child gets everything before the first divider, the second child gets everything between the first and second, and so on. Every possible arrangement of stars and dividers corresponds to exactly one way of handing out the candy, so counting arrangements counts distributions.
The number of dividers is always one less than the number of boxes: 3 dividers for 4 boxes, 5 for 6 boxes. That single rule drives the whole calculation. With 10 candies and 4 children you have 10 stars plus 3 bars, for 13 positions total. Choosing where the 3 bars go fixes the whole layout, so the answer is C(10 + 4 - 1, 4 - 1) = C(13, 3) = 286. This is the case where empty hands are allowed — a child can receive nothing if two dividers sit side by side.
If every child must get at least one candy, the picture changes. Hand out one candy to each child first, then share the remaining 6 freely among 4 children. That gives C(6 + 4 - 1, 4 - 1) = C(9, 3) = 84 ways. The same logic explains why capping each box can pull the total down: 12 balls into 5 boxes allow 1,820 distributions with no restrictions, but capping each box at 4 cuts that to 320 — slightly fewer than the 330 ways that simply give every box at least one. A stars and bars calculator handles these variants by adjusting the stars, the bars, or both before doing the combination.
The numbers grow fast because the count is combinatorial, not linear. Putting 20 tokens among 6 players explodes to 53,130 distributions. Doubling the tokens does not double the answer; it multiplies the pool of positions from which the dividers are chosen, so each added item or box lifts the total sharply. That is why a small change in the rules — allowing empty groups, requiring at least one, or capping a group — can move the result by a large amount.
- Count the items as stars and the boundaries as bars.
- Dividers equal boxes minus one: 3 for 4 boxes, 5 for 6 boxes.
- Empty groups allowed: C(10 + 4 - 1, 4 - 1) = 286 for 10 candies among 4 children.
- Every group nonempty: give one item to each group first, then C(9, 3) = 84.
- Restrictions matter: 12 balls into 5 boxes give 1,820 unrestricted, 320 with each box capped at 4, and 330 when every box gets at least one.
- Totals climb fast: 20 tokens among 6 players give 53,130 distributions.
Empty boxes or guaranteed shares
The two standard versions of the stars and bars method differ in one small rule, and that rule changes the answer a lot. In the first version, a box is allowed to stay empty. In the second, every box must receive at least one item. A stars and bars calculator handles both, but you have to know which one your problem is asking for before you trust the number it returns.
Take 10 identical candies split among 4 children with empty hands allowed. That can be done in 286 ways. Now add the requirement that every child must get at least one candy, and the count drops to 84. Same candies, same children, very different answer. The only change is whether a child can walk away with nothing. That gap between 286 and 84 is the whole point of the empty-box distinction, and it is why the first question to ask about any distribution problem is whether zero is allowed.
The same split shows up with larger numbers. Putting 12 balls into 5 boxes allows 1,820 distributions when boxes may be empty. Capping each box at 4 cuts that to 320, which is slightly fewer than the 330 ways that simply give every box at least one. Notice that the cap and the minimum are different constraints pulling in the same direction: one limits how many a box can hold, the other sets how few. Both reduce the total, but they are not interchangeable, and the numbers 320 and 330 sit close enough that mixing them up is easy.
Size makes the effect more dramatic. Distributing 20 tokens among 6 players explodes to 53,130 distributions. That count grows combinatorially, not linearly, so small changes in the rules produce large changes in the result. This is exactly where a stars and bars calculator earns its place: the arithmetic is simple in form but the totals get big fast, and hand-counting stops being realistic long before 20 tokens.
One structural fact stays fixed across all of these problems. The divider count is always boxes minus one: 3 dividers for 4 boxes, 5 for 6 boxes. The stars are the items and the bars are the dividers, so the number of bars never depends on how many items you have, only on how many boxes you are filling. That is the part of the setup you can always check by eye before you worry about the final total.
- 10 candies, 4 children, empties allowed: 286 ways
- 10 candies, 4 children, at least one each: 84 ways
- 12 balls, 5 boxes, empties allowed: 1,820 distributions
- 12 balls, 5 boxes, each box at least one: 330 ways
- 12 balls, 5 boxes, each box capped at 4: 320 ways
- 20 tokens, 6 players: 53,130 distributions
- Dividers = boxes minus one: 3 for 4 boxes, 5 for 6 boxes
Adding a per-box cap
A per-box cap changes the problem from a simple divider count into a subtraction problem. Take 12 balls into 5 boxes: with no restriction, the standard divider count gives 1,820 distributions. That figure comes from arranging 12 balls and 4 dividers, since the divider count is always boxes minus one — 4 dividers for 5 boxes. Now suppose each box may hold no more than 4 balls. Most of those 1,820 arrangements break the rule, and the true count drops to 320. That is slightly fewer than the 330 ways that simply give every box at least one ball, a useful sanity check that the cap is doing real work.
The tool for this is inclusion-exclusion. First count every distribution as if no cap existed. Then subtract the distributions in which at least one box exceeds the cap. But subtracting alone overcorrects, because a distribution with two overflowing boxes gets removed twice. So you add back the cases where two boxes overflow at once, then subtract the cases where three overflow, and continue alternating until no box combination is left. Each round treats an overflowing box as if it had already been filled past its limit, hands out the remaining balls freely, and counts the results with the same divider method. A stars and bars calculator automates that alternating sum, which is where hand work usually goes wrong.
The 12-into-5 example shows the size of the correction. The raw 1,820 includes every arrangement, capped or not. Subtracting the single-box overflows removes far more than the excess, and restoring the double overflows brings the total back up to the correct 320. Skipping that restore step is the classic error: you would land well below the true answer and never notice, because the result still looks like a plausible number.
The same logic scales to larger inputs, and the arithmetic grows quickly. Putting 20 tokens among 6 players gives 53,130 distributions before any cap is applied — 5 dividers for 6 players. The count grows combinatorially, not linearly, so a cap on a problem that size produces a much larger inclusion-exclusion sum. That is the practical reason to let a calculator handle the capped case rather than tracing the alternating terms by hand.
- Start from the uncapped divider count: arrange the identical items and boxes-minus-one dividers.
- Subtract distributions where one box exceeds the cap, treating that box as pre-filled past its limit.
- Add back cases where two boxes overflow together, subtract cases where three do, and keep alternating.
- Check the result against a simpler known count — 320 for 12 balls in 5 boxes capped at 4 sits just under the 330 ways to give every box at least one.
Reading your result
The stars and bars calculator returns three counts, and each one answers a different fairness question. The first count treats the boxes as open: any box may receive nothing. The second count requires every box to get at least one item. The third count adds a capacity cap, so no box can hold more than a set limit. Looking at all three side by side tells you how much your rules actually change the outcome, rather than leaving you to guess.
The gap between the first two counts is often the most striking. Splitting 10 identical candies among 4 children, with empty hands allowed, can be done in 286 ways, but only 84 ways if every child must get at least one. That drop reflects a real change in the problem: once each box needs a minimum, those items are effectively set aside before the rest are distributed. The divider count explains part of the structure here — the divider count is always boxes minus one, so 3 dividers for 4 boxes and 5 for 6 boxes. The rest of the arithmetic comes from arranging items and dividers together, which is why the totals climb so quickly.
The capped count is the one to watch when your boxes have real capacity. Twelve balls into 5 boxes allow 1,820 distributions, but capping each box at 4 cuts that to 320 — slightly fewer than the 330 ways that simply give every box at least one. That comparison is useful: a cap can constrain the result more tightly than a minimum requirement does, even though the two rules sound similar in spirit. If your boxes are shelves, seats, or bins with a physical limit, read the capped figure as your answer and treat the uncapped counts as context for how much the limit matters.
Scale makes the same point louder. Twenty tokens among 6 players explode to 53,130 distributions — the count grows combinatorially, not linearly. Doubling the items does not double the answer, so a result that looks large is not a sign of an error. When you read your own output, check which rule set you entered, then compare the three counts to see how much each restriction moved the total. The capped count is the fairest guide whenever capacity is real; the open and minimum counts show what you would have faced without that limit.
- Open count: boxes may be empty — the loosest fairness rule.
- Minimum count: every box gets at least one item.
- Capped count: no box exceeds its capacity — use this when boxes have real limits.
- Dividers always equal boxes minus one: 3 for 4 boxes, 5 for 6 boxes.
FAQs
What is stars and bars?
Stars and bars is a counting method for distributing identical items into distinct boxes. You picture the items as stars and separate the boxes with bars. For example, 10 items placed in 4 boxes give C(13, 3) = 286 different distributions. It counts arrangements of identical units across labeled containers, not arrangements of different objects.
How many ways can 10 candies be split among 4 children?
Using stars and bars, 10 identical candies split among 4 children can be distributed in 286 ways when empty hands are allowed. If every child must receive at least one candy, the count drops to 84 ways. Both answers come from the same method, with the second adjusting for the minimum each child gets.
Why subtract one divider per box boundary?
The dividers mark the boundaries between boxes, and you need one fewer divider than boxes. Four boxes need only 3 dividers to separate them, so the divider count is always boxes minus one. That is why the formula uses 3 bars for 4 boxes, giving C(13, 3) = 286 for 10 items.
How does a per-box cap change the count?
A maximum per box lowers the total, and inclusion-exclusion removes the arrangements where a box overflows. For example, 12 balls in 5 boxes fall from 1,820 distributions to 320 when a cap of 4 is applied. The correction subtracts the overfull cases rather than recounting every arrangement by hand.
Does the method work for different items?
No. Stars and bars requires the items to be identical. If the items were distinct, you would multiply the 286 distributions by the permutations of the items themselves, because each distribution could be filled in many orders. The method counts only how many items land in each box, not which item goes where.
Where does stars and bars show up?
Stars and bars appears anywhere identical units are allocated into distinct groups. The 53,130 ways to split 20 tokens among 6 players is the same structure as counting integer solutions to an equation. The same counting pattern applies to tokens, candies, votes, or any identical units placed into labeled boxes.