Counting and Combinatorics

The Stars and Bars Method

A clear explanation of stars and bars for splitting identical items into groups, with checked examples including how many ways three dice can total ten.

On this page
  1. The kind of problem it solves
  2. The picture
  3. The general formula
  4. Why this is a combinations problem
  5. Dice sums
  6. Another example: repeated items in a multiset
  7. Limits

The kind of problem it solves

Ten identical tokens are to be shared among three players. Tokens are all alike, so only the number each player receives matters, not which token. A player may get zero. How many different distributions are there?

Listing them is possible but tedious: (10, 0, 0), (9, 1, 0), (9, 0, 1), and so on. Stars and bars counts them without listing.

The picture

Draw the 10 tokens as stars in a row:

★ ★ ★ ★ ★ ★ ★ ★ ★ ★

To split them among 3 players, insert 2 dividers (“bars”) somewhere in the row. Stars before the first bar go to player 1, stars between the bars to player 2, and stars after the second bar to player 3. For example:

★★★ | ★★★★★ | ★★

means 3, 5 and 2. And

| ★★★★★★★★★★ |

means 0, 10 and 0, since bars can sit next to each other or at either end.

Every distribution corresponds to exactly one arrangement of 10 stars and 2 bars in a line of 12 symbols, and vice versa. So we only need to count how many ways to choose which 2 of the 12 positions hold bars:

C(12, 2) = 12 × 11 ÷ 2 = 66.

There are 66 distributions.

The general formula

For n identical items shared among k groups, where groups may be empty, there are k − 1 bars and n + k − 1 symbols in total. The count is

C(n + k − 1, k − 1).

With n = 10 and k = 3, that is C(12, 2) = 66, matching the above.

If each group must receive at least one item, first give one item to each group, which leaves n − k items to place freely. The count becomes

C(n − 1, k − 1).

For the tokens, that is C(9, 2) = 9 × 8 ÷ 2 = 36 distributions where every player gets at least one.

Check with a small case: 4 items among 2 groups with at least one each. The splits are (1, 3), (2, 2), (3, 1), so 3. The formula gives C(3, 1) = 3.

Why this is a combinations problem

Once identical items are involved, the factorial-heavy counting of permutations and combinations does not apply directly, because swapping two identical items changes nothing. The trick of choosing bar positions turns the problem into an ordinary “choose which positions” count. This is the same selection-without-order idea explained in the discussion of when order matters.

Dice sums

Roll three six-sided dice. How many of the 216 ordered outcomes total 10?

We want x₁ + x₂ + x₃ = 10 with each xᵢ between 1 and 6. To use stars and bars, shift each value down by 1: let yᵢ = xᵢ − 1, so each yᵢ is between 0 and 5 and y₁ + y₂ + y₃ = 7.

Step 1: ignore the upper limit. Distributions of 7 into 3 non-negative parts: C(7 + 2, 2) = C(9, 2) = 36.

Step 2: remove the ones that break the limit. A part breaks the limit if it is 6 or more. Suppose y₁ ≥ 6. Put 6 in y₁ and distribute the remaining 1 among three parts: C(1 + 2, 2) = C(3, 2) = 3 ways. The same holds for y₂ and y₃, so 3 × 3 = 9 violating cases. Two parts both being at least 6 would need at least 12 in total, which exceeds 7, so no case is counted twice.

Step 3: subtract. 36 − 9 = 27.

So 27 of the 216 outcomes sum to 10, a probability of 27/216 = 1/8 = 12.5 percent. You can verify by listing the combinations of values for three dice summing to 10: {4,4,2}, {4,5,1}, {4,3,3}, {6,3,1}, {6,2,2}, {5,3,2} — six multisets in total, with ordered counts 3 + 6 + 3 + 6 + 3 + 6 = 27. The sizes line up because {4,4,2}, {4,3,3} and {6,2,2} each have 3 orderings, while the other three have all-different values and 6 orderings each.

The subtraction step is a small use of the inclusion-exclusion principle, and the shifting trick generalises to other limits. Seeing the totals this way connects to the general discussion of dice probability.

Another example: repeated items in a multiset

How many different bags of 5 fruits can you make from apples, bananas and cherries, where only the count of each kind matters? This is 5 identical slots shared among 3 kinds: C(5 + 2, 2) = C(7, 2) = 21 bags.

Choosing with repetition allowed and no order is the one case that ordinary permutation and combination formulas do not cover directly, which is why this method is useful.

Limits

Stars and bars counts distributions; it does not say they are equally likely. Distributing 10 tokens by dealing them out randomly, one at a time, does not make each of the 66 distributions equally likely, since (3, 3, 4) can be reached in many more ways than (10, 0, 0). Dividing counts to get a probability is valid only when the counted outcomes are equally likely, as with the 216 ordered dice outcomes above.

It is a counting technique for understanding games and puzzles, not a way to predict or improve results in games of chance, which carry a house edge. Gambling can be harmful, and a local support service can help anyone who is struggling.

The complete guide to counting and combinatorics

Counting Principles Every Probability Learner Needs
Read the guide

Keep exploring

Guides from other topics

All topics →