Sit down at a piano and count the keys in one octave. Twelve. Seven white, five black, twelve total pitch classes before the pattern repeats. Ask a musician why twelve and they will probably say something about Western tradition, the church modes, or maybe vaguely gesture at the circle of fifths. Ask a musicologist and you might hear about Pythagoras, or the development of equal temperament in the Baroque period, or the well-tempered tuning systems of J. S. Bach. All of that history is real and worth knowing. But none of it explains why the number 12 works, and why every serious attempt at a usable keyboard instrument across widely separated cultures converges on the same cardinality.
The real answer is in number theory. Specifically, it is in the continued fraction expansion of a single irrational number: $\log_2(3/2)$. The number 12 is not a cultural choice. It is the smallest integer that gives a genuinely good rational approximation to that number — subject to the constraint that a human hand can navigate the resulting keyboard. Once you see the argument, the feeling of contingency evaporates completely. Twelve is forced on us.
Along the way, the same mathematical structure — the cyclic group $\mathbb{Z}_{12}$ — explains why Messiaen’s modes of limited transposition exist, why the circle of fifths closes exactly, and why certain chord types (augmented triads, diminished seventh chords, the whole-tone scale) have a strange self-similar quality that composers have exploited for centuries. If you want the full treatment of the Messiaen connection, I wrote a dedicated post: Messiaen, Modes, and the Group Theory of Harmony. Here I want to build the foundations from scratch, starting with the one interval that makes all of this necessary.
The interval that started everything
The perfect fifth has a frequency ratio of exactly 3:2. Play two strings in that ratio and the sound is stable, open, and unmistakably consonant — second only to the octave (2:1) in the hierarchy of simple intervals. The reason is physics: the overtone series of any vibrating string includes the fundamental frequency $f$, then $2f$, $3f$, $4f$, and so on. Two notes a perfect fifth apart share the overtone at $3f$ (for the lower note) and $2f'$ (for the upper note, where $f' = 3f/2$): those are the same frequency, $3f$. Shared overtones mean the two notes reinforce rather than fight each other. This is why the fifth sounds stable: it is literally built into the harmonic structure of physical vibration.
Humans discovered the fifth independently in ancient Greece, China, India, and Mesopotamia. It is not a cultural artifact [4]. Given that stability, it is natural to ask: can we build a complete pitch system by stacking fifths? Take a starting note, go up a fifth, up another, up another, and keep going. The notes you produce — C, G, D, A, E, B, F♯, … — are acoustically related to the starting point in a simple way, and they sound good together. This is the Pythagorean tuning system, and it underlies the construction of diatonic scales.
But here is the problem. A fifth raises the pitch by a factor of 3/2. An octave raises it by a factor of 2. These are independent: one is a power of 3 and the other a power of 2, and no power of 3/2 will ever equal a power of 2 exactly. In the language of modern mathematics, $\log_2(3/2)$ is irrational — this follows directly from the fundamental theorem of arithmetic, since no product of powers of 2 can equal a product of powers of 3. Whether it is also transcendental is an open question; a proof would follow from Schanuel’s conjecture, but that conjecture remains unresolved. What matters for tuning is the irrationality alone. Stacking pure fifths and stacking octaves are incommensurable operations. The circle of fifths can never close in pure Pythagorean tuning. We will always end up slightly sharp or flat relative to where we started.
This incommensurability is the central problem of musical tuning. Everything else — equal temperament, just intonation, meantone tuning, the Pythagorean comma, the whole apparatus of tuning theory — is a response to it.
Equal temperament and the approximation problem
In an equal temperament with $N$ notes per octave, we divide the octave into $N$ equal logarithmic steps. Each step corresponds to a frequency ratio of $2^{1/N}$. We then ask: how many steps $k$ gives the best approximation to a perfect fifth?
The condition is simply that $2^{k/N}$ should be close to $3/2$, which means $k/N$ should be close to $\log_2(3/2)$. So we need a good rational approximation to
$$\log_2\!\left(\frac{3}{2}\right) = \log_2 3 - 1 \approx 0.584962\ldots$$The classical tool for finding best rational approximations is the continued fraction. Any real number $x$ can be written as
$$x = a_0 + \cfrac{1}{a_1 + \cfrac{1}{a_2 + \cfrac{1}{a_3 + \cdots}}}$$where the $a_i$ are non-negative integers (positive for $i \geq 1$), called the partial quotients. For $\log_2(3/2)$ the expansion is
$$\log_2\!\left(\frac{3}{2}\right) = [0;\, 1,\, 1,\, 2,\, 2,\, 3,\, 1,\, 5,\, 2,\, 23,\, 2,\, \ldots]$$The truncated continued fractions — the convergents — give the sequence of best rational approximations:
$$\frac{0}{1},\quad \frac{1}{1},\quad \frac{1}{2},\quad \frac{3}{5},\quad \frac{7}{12},\quad \frac{24}{41},\quad \frac{31}{53},\quad \frac{179}{306},\quad \ldots$$Each convergent $k/N$ corresponds to a tuning system: the denominator $N$ is the number of equal steps per octave, and the numerator $k$ is the number of steps that best approximates a fifth. So we get: 1-TET (trivial), 2-TET (trivial), 5-TET, 12-TET, 41-TET, 53-TET, 306-TET, and so on [1], [2].
The key property of convergents is that they give uniquely good approximations. No rational number with a smaller denominator comes closer to the true value than a convergent does. So 7/12 is not merely a decent approximation to $\log_2(3/2)$ — it is provably the best approximation with denominator at most 12. To do better with a denominator below 41, you cannot.
To put numbers on it: in 12-TET, the fifth is $2^{7/12} \approx 1.498307\ldots$, while the true fifth is exactly $1.500000$. The error is about 0.11%, or roughly 2 cents (hundredths of a semitone). In 53-TET, the fifth is $2^{31/53} \approx 1.499941\ldots$, an error of less than 0.004%, about 0.07 cents — essentially indistinguishable from pure. Both 12 and 53 are convergents. Intermediate values like 19-TET or 31-TET are not convergents (they are not best approximations), and their fifths, while sometimes used in experimental or microtonal music, are less accurate relative to their complexity.
Why does this matter? Because a tuning system that approximates the fifth poorly will produce harmonies that beat visibly — the slight mistuning causes the sound to waver in a way that trained ears find uncomfortable in sustained chords. A good fifth approximation is not a luxury; it is the condition for the system to be musically usable in the harmonic practice that most of the world’s music assumes.
The Pythagorean comma
Before equal temperament became standard (roughly the 18th century in Western Europe), instruments were tuned using pure Pythagorean fifths: exact 3:2 ratios, stacked on top of each other. This gives beautiful, stable individual fifths, but it collects a debt.
After stacking 12 pure fifths, you have climbed in frequency by $(3/2)^{12}$:
$$(3/2)^{12} = \frac{3^{12}}{2^{12}} = \frac{531441}{4096} \approx 129.746\ldots$$Meanwhile, 7 octaves is $2^7 = 128$. The ratio between these is
$$\frac{(3/2)^{12}}{2^7} = \frac{3^{12}}{2^{19}} = \frac{531441}{524288} \approx 1.01364$$This is the Pythagorean comma: roughly 23.46 cents, or about a quarter of a semitone [4]. In Pythagorean tuning, the circle of fifths never closes. After 12 fifths you arrive at a note that is nominally the same pitch class as the starting point — but sharp by 23.46 cents. That final fifth, the one that “should” close the circle, sounds badly out of tune. It was historically called the “wolf fifth” because it howls.
Equal temperament solves this by distributing the comma across all 12 fifths. Each fifth is flattened by $23.46/12 \approx 1.955$ cents. The individual fifths are no longer pure, but the error is small enough to be acceptable — and crucially, it is uniform, so every key sounds equally good (or equally impure, depending on your perspective).
The Pythagorean comma being small — about 1.96% of the octave — is precisely why 12-TET works. It is small because 7/12 is an unusually good convergent of $\log_2(3/2)$. The two facts are the same fact. The comma is the numerator of the error when you approximate $\log_2(3/2)$ by $7/12$, multiplied up by 12 fifths’ worth of accumulation. When the approximation is good, the comma is small, and the distribution is imperceptible. This is why the piano is tuned the way it is.
The group theory
We are now ready for the algebra. In 12-TET, pitch classes form the set $\{0, 1, 2, \ldots, 11\}$ where we identify 0 with C, 1 with C♯, 2 with D, 3 with D♯, 4 with E, 5 with F, 6 with F♯, 7 with G, 8 with G♯, 9 with A, 10 with A♯, and 11 with B. Addition is modulo 12: after 11 comes 0 again, because after B comes C in the next octave (same pitch class). This is $\mathbb{Z}_{12}$, the integers mod 12, and it is a group under addition [1].
Transposition by a semitone is addition of 1. Transposition by a perfect fifth is addition of 7, because the fifth is 7 semitones in 12-TET. Start from C (0) and repeatedly add 7, always reducing modulo 12:
$$0 \to 7 \to 14 \equiv 2 \to 9 \to 16 \equiv 4 \to 11 \to 18 \equiv 6 \to 13 \equiv 1 \to 8 \to 15 \equiv 3 \to 10 \to 17 \equiv 5 \to 12 \equiv 0$$In note names: C, G, D, A, E, B, F♯, C♯, G♯, D♯/E♭, A♯/B♭, F, C. That is the circle of fifths — all 12 pitch classes visited exactly once before returning to the start. The circle of fifths is the orbit of 0 under repeated addition of 7 in $\mathbb{Z}_{12}$.
Why does the orbit visit all 12 elements? Because $\gcd(7, 12) = 1$. This is Bézout’s theorem applied to cyclic groups: an element $g$ generates $\mathbb{Z}_n$ (i.e., its orbit under repeated addition covers all of $\mathbb{Z}_n$) if and only if $\gcd(g, n) = 1$. The generators of $\mathbb{Z}_{12}$ are exactly the elements coprime to 12: that is $\{1, 5, 7, 11\}$. Musically: transposition by 1 semitone (chromatic scale), by 5 semitones (perfect fourth), by 7 semitones (perfect fifth), or by 11 semitones (major seventh) each generates all 12 pitch classes. Transposition by 2 (a whole tone) does not — it produces only the 6-element whole-tone scale. Transposition by 3 (a minor third) produces only the 4-element diminished seventh chord.
This is not a curiosity; it is the algebraic skeleton of tonal music. The circle of fifths closes because 7 and 12 are coprime. That coprimality is guaranteed by the continued fraction structure: the numerator and denominator of a convergent in lowest terms are always coprime (as they must be, being a reduced fraction), and 7/12 is such a convergent.
Now consider the subgroups of $\mathbb{Z}_{12}$. By Lagrange’s theorem, subgroups of a finite group must have orders dividing the group order. The divisors of 12 are 1, 2, 3, 4, 6, and 12, so these are the only possible subgroup orders. For cyclic groups there is exactly one subgroup of each order dividing $n$, and it is generated by $n/d$ where $d$ is the subgroup order. The full list:
The trivial subgroup of order 1 is just $\{0\}$. The subgroup of order 2 is $\{0, 6\}$, generated by 6 — that is, the tritone axis, the interval of exactly half an octave. The subgroup of order 3 is $\{0, 4, 8\}$, generated by 4 — this is the augmented triad, three notes equally spaced around the octave by major thirds. The subgroup of order 4 is $\{0, 3, 6, 9\}$, generated by 3 — the diminished seventh chord, four notes equally spaced by minor thirds. The subgroup of order 6 is $\{0, 2, 4, 6, 8, 10\}$, generated by 2 — the whole-tone scale. And the full group of order 12 is all of $\mathbb{Z}_{12}$.
Each of these has a musical life. The augmented triad ($\{0, 4, 8\}$) sounds ambiguous because it maps onto itself under transposition by a major third — there are only 4 distinct augmented triads total, not 12. Composers exploit this ambiguity when they want harmonic instability without committing to a direction. The diminished seventh ($\{0, 3, 6, 9\}$) is similarly ambiguous: it has only 3 distinct forms and can resolve to any of several keys, which is why it appears so often at structural pivots in Romantic music. These properties are direct consequences of the subgroup structure of $\mathbb{Z}_{12}$.
Messiaen’s modes as cosets
Olivier Messiaen described his “modes of limited transposition” in his 1944 treatise Technique de mon langage musical. He identified seven scales — including the whole-tone scale and the octatonic scale — that have the peculiar property of mapping onto themselves under some transposition strictly smaller than an octave. He found them by ear, by introspection, and by exhaustive search at the keyboard. He did not have the group theory. But the group theory makes their existence not merely explainable but inevitable.
Here is the key definition. A scale $S \subseteq \mathbb{Z}_{12}$ is a mode of limited transposition if there exists some $t \in \{1, 2, \ldots, 11\}$ such that $S + t \equiv S \pmod{12}$ (as a set). In other words, transposing the scale by $t$ semitones maps the scale onto itself. The integer $t$ is called a period of the scale.
Now, the set of all periods of $S$ — together with 0 — forms a subgroup of $\mathbb{Z}_{12}$ (it is closed under addition modulo 12, since if both $t_1$ and $t_2$ are periods then so is $t_1 + t_2$). Call this subgroup $H$. The condition for $S$ to be a mode of limited transposition is simply that $H$ is nontrivial — that is, $H \neq \{0\}$.
Moreover, if $H$ is the period subgroup of $S$, then $S$ must be a union of cosets of $H$ in $\mathbb{Z}_{12}$. This follows immediately from the fact that $H$ acts on $S$ by translation and maps $S$ to itself: every element of $S$ belongs to exactly one coset of $H$, and $S$ is a union of whole cosets. The size of $S$ must therefore be a multiple of $|H|$.
The whole-tone scale $\{0, 2, 4, 6, 8, 10\}$ is itself the unique subgroup of order 6 in $\mathbb{Z}_{12}$. Its period subgroup is the whole-tone scale itself. Transposing by any even number (2, 4, 6, 8, or 10) maps it to itself. Transposing by an odd number gives the complementary whole-tone scale $\{1, 3, 5, 7, 9, 11\}$. There are therefore only 2 distinct transpositions of the whole-tone scale, not 12.
The octatonic (diminished) scale $\{0, 1, 3, 4, 6, 7, 9, 10\}$ has period subgroup $\{0, 3, 6, 9\}$ — the subgroup of order 4. It is a union of two cosets: $\{0, 3, 6, 9\}$ itself and $\{1, 4, 7, 10\}$. Transposing by 3 maps it onto itself. There are only 3 distinct transpositions. Messiaen calls this his Mode 2.
The general formula is clean: a mode of limited transposition with period subgroup of order $d$ has exactly $12/d$ distinct transpositions. For the whole-tone scale, $d = 6$ gives $12/6 = 2$ transpositions. For the octatonic scale, $d = 4$ gives $12/4 = 3$ transpositions.
What Messiaen found by ear was the complete classification of subsets of $\mathbb{Z}_{12}$ that are unions of cosets of a nontrivial subgroup [5]. The group theory makes their existence a theorem rather than a discovery. I find this genuinely beautiful: a composer’s intuition about harmonic symmetry turns out to be an exercise in the theory of cosets of cyclic groups. For the full analysis of each of Messiaen’s seven modes in these terms, see Messiaen, Modes, and the Group Theory of Harmony.
Why not 53?
Given that 53-TET approximates the fifth with an error of less than 0.004% — compared to 12-TET’s 0.11% — one might ask why we do not simply use 53-TET. The mathematical case is overwhelming. In addition to the nearly perfect fifth, 53-TET gives excellent approximations to the just major third (frequency ratio 5:4) and the just minor third (6:5). It was seriously advocated by the 19th-century theorist Robert Holford Macdowall Bosanquet, who even built a 53-key harmonium to demonstrate it. The Chinese theorist Jing Fang described a 53-note system in the 1st century BC. The Arabic music theorist Al-Farabi considered 53-division scales in the 10th century. Everyone who has ever thought carefully about tuning arrives at 53 eventually.
And yet no 53-TET instrument has ever entered widespread use. The reason is anatomical, not mathematical. A piano with 53 keys per octave spans more than 2 metres per octave at any reasonable key size — impossible to play. A guitar with 53 frets per octave has frets spaced roughly 3–4 millimetres apart in the upper register: no human fingertip is narrow enough to press a single fret without touching its neighbours. Even if you could play it, reading 53-TET notation would require an entirely new theoretical and pedagogical apparatus.
The constraint is: we want the largest $N$ such that (a) $N$ is a convergent denominator of $\log_2(3/2)$, so the fifth approximation is genuinely good, and (b) $N$ is small enough to navigate with human hands and readable at a glance. The convergent denominators are 1, 2, 5, 12, 41, 53, 306, … Of these, 12 is the largest that satisfies condition (b). The next convergent, 41, already strains human dexterity — 41-TET keyboard instruments have been built experimentally but never mass-produced. At 53 the case is closed.
One might argue about where exactly the cutoff is, and reasonable people might draw it at 19 or 31 (which are not convergents but have other virtues). But the point is that 12 is not merely a local optimum found by trial and error. It is the specific value where the continued fraction and human physiology intersect.
Closing
There is something I find genuinely satisfying about this argument. Music feels like the most human of activities — expressive, cultural, steeped in history and tradition. And yet the number 12, which lies at the foundation of so much of the world’s music, is not a human choice at all. It is the continued-fraction convergent of an irrational number that was fixed by the physics of vibrating strings long before any human struck a tuning fork.
The circle of fifths closes because $\gcd(7, 12) = 1$: a fact about integers, not about culture. Messiaen’s modes exist because $\mathbb{Z}_{12}$ has nontrivial proper subgroups: a fact about cyclic groups, not about 20th-century French aesthetics. The augmented triad sounds ambiguous because it is a coset of the order-3 subgroup of $\mathbb{Z}_{12}$: a fact about quotient groups, not about Romantic harmony conventions.
I came to music theory sideways — through acoustics, then signal processing, then the mathematics of scales. What surprised me, when I finally worked through the continued fraction argument properly, was not that the math existed but that it was so tight. There is essentially no freedom in the answer. Given the constraint that a musical scale should be built around the most consonant interval (after the octave), should form a closed group structure, and should be navigable by a human performer, the answer is 12. Not approximately 12, not 12 as a historical compromise. Exactly 12.
The number is not a tradition. It is a theorem.
For more on related themes: the Fibonacci sequence and golden ratio in music appear in Fibonacci, Lateralus, and the Golden Ratio. The Euclidean algorithm and rhythmic structure are explored in Euclidean Rhythms — a sister post to this one in the math-and-music thread. And for the physics of audio sampling rates, where a similar interplay of number theory and practical constraints forces another specific number, see Why 44,100 Hz?.
References
[1] Balzano, G. J. (1980). The group-theoretic description of 12-fold and microtonal pitch systems. Computer Music Journal, 4(4), 66–84.
[2] Carey, N., & Clampitt, D. (1989). Aspects of well-formed scales. Music Theory Spectrum, 11(2), 187–206.
[3] Milne, A., Sethares, W. A., & Plamondon, J. (2007). Isomorphic controllers and dynamic tuning. Computer Music Journal, 31(4), 15–32.
[4] Lloyd, L. S., & Boyle, H. (1978). Intervals, Scales and Temperaments. St. Martin’s Press.
[5] Douthett, J., & Steinbach, P. (1998). Parsimonious graphs: A study in parsimony, contextual transformations, and modes of limited transposition. Journal of Music Theory, 42(2), 241–263.
Changelog
- 2025-11-20: Updated the spelling of “Robert Holford Macdowall Bosanquet” (previously rendered as “Macdowell”).
- 2025-11-20: Changed “about 1.36% of the octave” to “about 1.96% of the octave.” The 1.36% figure is the frequency ratio above unity (531441/524288 ≈ 1.01364); the logarithmic fraction of the 1200-cent octave is 23.46/1200 ≈ 1.96%.
- 2025-11-20: Changed “12 octaves’ worth of accumulation” to “12 fifths’ worth of accumulation.” The Pythagorean comma accumulates over 12 stacked fifths (which span approximately 7 octaves), not 12 octaves.