Stars and Bars Calculator

Enter the items and groups to count the distributions.

Result

286
C(n+k-1, k-1)

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.

Try this example →

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.

Comments (1)

  • Editorial team

    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?

Popular calculators

All Calculators