Stars and Bars Calculator
Count the ways to split n identical items among k groups with stars and bars, with optional minimum and maximum per group, and list every arrangement.
Stars and bars counts the ways to share out n identical items among k different groups: sweets among children, votes among candidates, or the whole-number solutions of x₁ + x₂ + … + xₖ = n. Picture the items as stars in a row and place k − 1 bars to cut them into groups. This calculator handles empty groups, a minimum per group and an upper limit per group, and lists every arrangement when there are few enough.
How to use this tool
- Enter n, the number of identical items.
- Enter k, the number of distinct groups.
- Set the minimum per group: 0 if a group may be empty, 1 if each must get at least one.
- Optionally enter a maximum per group.
- Read the count, the formula used and, for small cases, every arrangement.
Formula
Ways = C(n + k − 1, k − 1); with at least one per group, C(n − 1, k − 1)
A row of n stars and k − 1 bars has n + k − 1 positions, and choosing which k − 1 are bars fixes the arrangement. A minimum of m per group first hands out k·m items, leaving n − k·m to share freely. With minimum m, let N = n − km and c = maximum − m. Inclusion–exclusion gives Σ (−1)ʲ C(k, j) C(N − j(c + 1) + k − 1, k − 1).
Example
Share 10 identical sweets among 3 children, where a child may get none. That is 10 stars and 2 bars in 12 positions, so the count is C(12, 2) = 12 × 11 / 2 = 66 ways. If every child must get at least one, hand out one each first and share the other 7: C(9, 2) = 36 ways.
Frequently asked questions
What if the items are different from each other?
Then stars and bars does not apply. Each of the n distinct items can go to any of k groups, giving kⁿ ways when groups may be empty.
How is this related to combinations with repetition?
It is the same count. Choosing k items from n types with repetition allowed is C(n + k − 1, k), which is stars and bars with k stars and n − 1 bars.
How many non-negative integer solutions does x + y + z = 10 have?
Use n = 10 and k = 3 with minimum 0: C(12, 2) = 66 solutions. For positive solutions set the minimum to 1: 36.
Why does an upper limit need a different formula?
The basic formula counts arrangements where a group exceeds the limit. Inclusion–exclusion subtracts those, adds back double-counted ones, and so on.
Last updated: 2026-10-30