Necklace Counting Calculator

Combinatorics

Necklace count14
All necklaces T14
Aperiodic A9
How this was calculated
  1. Burnside's lemma averages the colourings fixed by each rotation: sum over the divisors d of 6 of phi(d) x 2^(n/d), divided by 6.
  2. That gives T = 14 necklaces in total (rotations of the same string counted once).
  3. The Mobius form of the same sum counts the aperiodic (primitive) necklaces: A = 9.
  4. Selected mode: all necklaces, so the answer is 14.

Take a string of coloured beads on a loop. Two strings that differ only by a rotation - sliding the beads around the loop - are the same necklace. How many genuinely different necklaces of n beads in k colours exist? The answer is not k^n / n, tempting as that division is, because some necklaces are symmetric and have fewer than n distinct rotations. Counting them properly is the classic first application of Burnside's lemma, and it is what this calculator does.

The formula sums over the divisors d of n: total necklaces T = (1/n) x sum of phi(d) x k^(n/d), where phi is Euler's totient. A companion count uses the Mobius function in place of phi and counts the aperiodic (primitive) necklaces - those with no rotational symmetry at all. For 6 beads in 2 colours the answers are T = 14 and A = 9; for 4 beads in 2 colours, T = 6 and A = 3.

Choose the count you want, the number of beads (up to 20) and the colours (up to 6). The calculator shows both counts in its outputs whichever mode you pick, because the relationship between them - the total decomposes into aperiodic necklaces of the divisors - is half the insight.

Worked examples

All necklaces, 6 beads, 2 colours

(All necklaces · 6 · 2)

Necklace count14
All necklaces T14
Aperiodic A9

Aperiodic necklaces, 4 beads, 2 colours

(Aperiodic (primitive) only · 4 · 2)

Necklace count3
All necklaces T6
Aperiodic A3

Aperiodic necklaces, 6 beads, 2 colours

(Aperiodic (primitive) only · 6 · 2)

Necklace count9
All necklaces T14
Aperiodic A9

Why k^n / n is wrong

Dividing by n assumes every necklace has exactly n rotations, all different. That fails for periodic necklaces: the alternating string ABAB (n = 4) rotated by two positions is itself, so it has only 2 distinct rotations, and the monochromatic strings have just 1. Any count that ignores symmetry undercounts exactly the most regular necklaces.

Burnside's lemma fixes this by counting, for each rotation, how many colourings it leaves unchanged, and averaging. A rotation by j positions splits the beads into gcd(j, n) cycles, so it fixes k^gcd(j, n) colourings. Grouping the rotations by their gcd leads directly to the divisor sum with phi(d) counting how many rotations share each cycle structure.

The phi sum, worked

For n = 6, k = 2 the divisors are 1, 2, 3, 6 with phi values 1, 1, 2, 2. The sum is 1 x 2^6 + 1 x 2^3 + 2 x 2^2 + 2 x 2^1 = 64 + 8 + 8 + 4 = 84, and 84 / 6 = 14 necklaces. Every term has a meaning: 64 counts colourings fixed by the identity rotation (all of them), and the small terms count the symmetric colourings fixed by the half-turn, third-turns and sixth-turns.

For n = 4, k = 2: divisors 1, 2, 4 with phi 1, 1, 2 give (16 + 4 + 2 x 2) / 4 = 24 / 4 = 6. The six necklaces can be listed by hand - 0000, 0001, 0011, 0101, 0111, 1111 in binary - which makes n = 4 the perfect sanity check for the formula.

Aperiodic necklaces and the Mobius sum

An aperiodic necklace has least period exactly n: no rotation short of the full loop leaves it unchanged. Replacing phi by the Mobius function mu in the same divisor sum counts them: A = (1/n) x sum of mu(d) x k^(n/d). For n = 6, k = 2 the Mobius values are mu(1) = 1, mu(2) = -1, mu(3) = -1 and mu(6) = 1, giving (64 - 8 - 4 + 2) / 6 = 54 / 6 = 9.

The two counts are linked by a divisor identity: every necklace has some least period d dividing n, and it is an aperiodic necklace of length d repeated. Hence T(n) relates to the sum of A(d) over divisors - the calculator's steps show both numbers so the decomposition can be checked on small cases like n = 4 (A values 1, 1... for divisors 1, 2, 4 the aperiodic counts are 2, 1, 3, and indeed the 6 total necklaces split as those of period 1 (2), period 2 (1 new) and period 4 (3 new), with repetition accounting for the rest).

Brute force agrees

For small n the formula can be checked by pure enumeration: generate all 2^n binary strings, reduce each to its lexicographically smallest rotation, and count the distinct canonical forms. For n = 4 that gives 6 and for n = 5 it gives 8 - both matching the phi sum exactly. The batch verification for this page did precisely that cross-check.

Enumeration dies quickly (k^n grows fast), which is the formula's reason to exist: at n = 20, k = 6 the count is in the hundreds of trillions, delivered instantly by a sum over the divisors of 20 - of which there are only six.

Lyndon words

Take each aperiodic necklace and cut it at its lexicographically smallest rotation: the resulting strings are the Lyndon words - one per aperiodic necklace. Lyndon words are fundamental objects in algebra and computer science: they index bases of free Lie algebras, they generate the standard factorisation of words, and they appear in the Duval algorithm and in de Bruijn sequence construction.

So the aperiodic count on this page is also the count of binary (or k-ary) Lyndon words of length n - for n = 6, k = 2, the 9 words include 000001, 000011, 000101 and 001111 in their canonical rotations. A bead-counting problem and a cornerstone of algebraic combinatorics turn out to be the same count.

Necklaces with flips: bracelets

This page counts necklaces up to rotation only. If the loop can also be flipped over - the physical reality of an actual necklace - the objects are called bracelets, and the count drops further (for 6 beads in 2 colours, from 14 necklaces to 13 bracelets, the flip identifying exactly one pair). Bracelet counting needs the dihedral group and a slightly longer Burnside average including reflections.

Which count you want depends on the application: chemistry's cyclic structures and Lyndon words use the rotation-only count; physical beadwork uses bracelets. The calculator is explicit about which it computes - a distinction many quick references blur.

Where necklace counts appear

Beyond combinatorics for its own sake: cyclic molecules and their distinct arrangements, periodic patterns in music and design, round-table seating problems (the same Burnside machinery), and the analysis of necklaces in coding theory. The phi-sum formula is also the count of monic irreducible... more precisely, the aperiodic count with k a prime power gives the number of monic irreducible polynomials of degree n over a finite field - one of the prettiest identities in algebra, and the reason the Mobius sum feels inevitable once seen.

That polynomial connection explains the formula's shape: an irreducible polynomial's roots are distinct and cycle with full period, just like an aperiodic necklace's beads.

Using the calculator well

Inputs are capped at n = 20 beads and k = 6 colours so that every intermediate value stays within the browser's exact integer range - the largest, 6^20, is about 3.66 x 10^15, safely below the 2^53 exactness ceiling. Within the caps, every count is exact.

Compare the two modes on the same inputs to see periodicity at work: when n is prime, almost every necklace is aperiodic (for prime p, A = (k^p - k)/p and T = A + k... the only periodic ones being the k monochromatic strings), while highly composite n like 12 or 18 show the biggest gaps between the total and aperiodic counts.

FAQs

How many necklaces of 6 beads in 2 colours are there?

14 in total, of which 9 are aperiodic (primitive).

What is an aperiodic necklace?

One with no rotational symmetry - all n of its rotations are different, so its least period is exactly n.

What formula counts necklaces?

Burnside's lemma gives T = (1/n) x the sum over divisors d of n of phi(d) x k^(n/d); the aperiodic count replaces phi with the Mobius function.

How many necklaces of 4 beads in 2 colours?

6 in total and 3 aperiodic - few enough to list by hand.

Why is the aperiodic count smaller?

Periodic necklaces repeat a shorter pattern; the Mobius sum excludes them, counting only full-period necklaces.

What are Lyndon words?

The lexicographically smallest rotations of aperiodic necklaces - there is exactly one Lyndon word per aperiodic necklace.

Sources

Related calculators

Catalan Number Calculator
The Catalan numbers — C(2n, n) divided by (n + 1) — counting bracketings, binary trees, polygon triangulations and lattice paths that never cross the diagonal.
Stirling Numbers Calculator
Stirling numbers of the second kind S(n, k) - the ways to partition n items into k groups - with the Bell number.
Integer Partition Calculator
Exact partition count p(n) up to n = 200 by Euler's pentagonal recurrence, with p(n-1), the growth ratio and the partitions into distinct parts.