Stars & Bars

Count ways to split identical items among labeled groups.

What is it?

Stars and bars counts the solutions of in non-negative integers by arranging stars and bars in a row.

Why is it useful?

Distribution and integer-solution questions are common counting warm-ups, and the lower-bound trick turns many variants into the same formula.

When should you think of it?

Think of it when identical objects go into distinct boxes, or when you count integer solutions to a sum.

Think of this method when…

  • Objects are identical (balls, coins, units) but boxes are labeled
  • You count solutions of
  • Constraints like "each box gets at least "
  • Choosing items with repetition from types

Core idea

Each distribution is a string of stars and bars; choose the bar positions. Lower bounds are handled by pre-filling each box.

Step-by-step playbook

  1. 1Confirm the items are identical and the boxes are distinct.
  2. 2Subtract any lower bounds: if , set .
  3. 3Apply to the reduced total .
  4. 4For upper bounds, combine with inclusion-exclusion.

Worked example

Worked example

18 identical balls go into 5 labeled boxes, each box getting at least 2. How many ways?

  1. 1

    Pre-fill 2 balls in each box: balls remain.

  2. 2

    Distribute 8 identical balls freely into 5 boxes.

  3. Answer:

Common mistakes

  • Using it when the objects are distinct (then it is ).
  • Forgetting to subtract lower bounds before applying the formula.
  • Mixing up with — they are equal, but mixing and is not.

Would you use this method?

How many ways can 5 distinct books be given to 3 students?

Practice this method

15 QuantSolve questions are tagged with this method.

Practice this method

Related lessons & methods