Maths & numbers

Stars and bars distribution calculator

Count nonnegative allocations of identical items to distinct boxes.

Your numbers

Calculated on your device. Your inputs aren’t sent to us.

Your result

Ready when you are

Enter your inputs and select Calculate.

Report an issue

Behind the numbers

How this calculation works

If each box must receive at least one item, assign those items first and use the remaining items in the nonnegative allocation.

THE FORMULAC(items + boxes − 1, boxes − 1)

A worked example

Seven items into four labeled boxes yield C(10,3) = 120 allocations.

Good to know

Empty boxes are allowed.

Represent allocations with stars and separators

Distributing seven identical items among four labelled boxes can be represented by seven stars and three bars. The string with groups of sizes 2, 0, 3 and 2 uses adjacent bars for the empty second box. Reading from left to right recovers the allocation uniquely.

Every allocation corresponds to a length-ten string formed from seven identical stars and three identical bars. Choose the three bar positions in C(10,3) = 120 ways. This is the formula C(items + boxes − 1, boxes − 1). Bars may appear at the beginning or end, allowing the first or last box to be empty.

Seven stars and three bars encode the box counts two, zero, three and two★ ★ | | ★ ★ ★ | ★ ★A: 2B: 0C: 3D: 2Choose 3 bar positions from 10
Adjacent bars leave box B empty. The seven stars are identical, while the four box positions have distinct labels.

Check whether empty boxes and labels are allowed

The boxes are distinguishable. Sending all seven items to box A differs from sending them all to box B. If the boxes were unlabelled, this calculation would overcount. The Integer partition count calculator describes a related setting in which the order of positive parts is ignored.

If every box must contain at least one item, first reserve one item per box. Seven items across four nonempty boxes leave three items to distribute freely, giving C(6,3) = 20. This differs from the default 120 because the default allows zeros. Distinct items would require a different model as well, since the identities of the assigned items would matter.

A few questions, answered

What happens with zero items?

There is one allocation: every box receives zero. This remains true for any accepted positive number of boxes.

Can there be more boxes than items?

Yes. Empty boxes are permitted, so the allocation remains valid.

Find your calculator

Start typing to explore the library.