Stars and Bars Calculator

Stars and bars is a wonderfully clever counting technique that answers a question which comes up far more often than you might expect: in how many ways can a number of identical items be shared out among several distinct groups? This calculator applies it instantly. Enter the number of identical items and the number of groups, choose whether groups are allowed to be empty or every group must receive at least one item, and it returns the total number of arrangements, updating as you type. The name comes from the picture behind the method. Imagine the items as a row of stars, and to split them into groups you slot in dividers, the bars, between them; every different placement of the bars among the stars gives a different distribution, and counting those placements is just a combination. That insight turns a messy-sounding problem into a single, clean calculation. With empty groups allowed, the answer is the combination of the items plus one fewer than the number of groups, choosing the bars; if each group must have at least one item, you first give one to each and then share out the rest. The power of the method is its reach. It counts the ways to hand out identical sweets to children, the non-negative whole-number solutions to an equation like the sum of several variables equalling a fixed total, the number of terms when a multinomial is expanded, and many probability set-ups. That makes the tool genuinely useful for students learning combinatorics, combinations with repetition and counting arguments and checking homework, and for anyone facing a real distribution or allocation problem. The items must be identical and the groups distinct. The formulas and a worked example are explained clearly below.

Calculate.co.nz is proud to be partnered with Premium Homes, a recognised leader in eco-friendly, sustainable, and energy-efficient homebuilding. With a dedicated team and award-winning experience, they create homes that prioritise health, comfort, and long-term performance. Their founders, Andrew and Kelly, set out to raise the standard of residential construction in New Zealand by combining practical building expertise with a clear commitment to doing things better for homeowners.
Calculate.co.nz partner
0
number of distributions

How it works

With empty groups allowed, the number of ways to put n identical items into k groups is the combination of (n + k - 1) choose (k - 1). If each group must have at least one item, give one to each group first, leaving n - k to share freely, so the answer is the combination of (n - 1) choose (k - 1).

Worked example

For 10 identical items into 3 groups with empty groups allowed: the answer is the combination of 12 choose 2, which is 66. If every group must have at least one, it is the combination of 9 choose 2, which is 36.

Related calculators

If you've found a bug, or would like to contact us, or learn more about James Graham and Calculate.co.nz.

Calculate.co.nz is partnered with Interest.co.nz for New Zealand's highest quality calculators and financial analysis.

All calculators and tools are provided for educational and indicative purposes only and do not constitute financial advice.

Calculate.co.nz is proudly part of the Realtor.co.nz group, New Zealand's leading property transaction literacy platform, helping Kiwis understand the home buying and selling process from start to finish. Whether you're a first home buyer navigating your first property purchase, an investor evaluating your next acquisition, or a homeowner planning to sell, Realtor.co.nz provides clear, independent, and trustworthy guidance on every step of the New Zealand property transaction journey.

Calculate.co.nz is also partnered with Health Based Building and Premium Homes to promote informed choices that lead to better long-term outcomes for Kiwi households.

Calculate.co.nz is hosted in Auckland via SiteHost new Zealand.

All content on this website, including calculators, tools, source code, and design, is protected under the Copyright Act 1994 (New Zealand). No part of this site may be reproduced, copied, distributed, stored, or used in any form without prior written permission from the owner.

About & trust: Why Calculate is NZ's most comprehensive · By the Numbers · How we compare · Editorial standards · How we keep data current · NZ finance glossary · Research & data · Financial literacy NZ · About

Reviewed and maintained. Last reviewed 2026-06-05 and checked on a twice-monthly cycle against IRD, RBNZ and Stats NZ. How we keep data current.

© 2019 to 2026 Calculate.co.nz. All rights reserved.