Why Tuning a Piano is Mathematically Impossible

Perfect harmony is a mathematical impossibility. Here's the beautiful, maddening reason why — and how piano tuners have learned to live with it.

·9 min read

If you've ever noticed that a piano sounds slightly different from a guitar playing the "same" note, you've brushed up against one of the most elegant impossibilities in mathematics. Tuning a piano perfectly is not a practical problem waiting for a clever engineer — it is provably, irrevocably impossible.

The reason sits at the intersection of number theory, acoustics, and thousands of years of musical frustration.

What Does "In Tune" Even Mean?

Two notes are considered consonant — pleasant-sounding together — when their frequencies form simple integer ratios. The reason is physical: simple ratios mean the pressure waves produced by the two strings reinforce each other regularly, creating a stable combined waveform.

The most important intervals, and their ideal frequency ratios:

IntervalRatioExample (from A 440 Hz)
Octave2 : 1A 880 Hz
Perfect fifth3 : 2E 660 Hz
Perfect fourth4 : 3D 586.7 Hz
Major third5 : 4C♯ 550 Hz
Minor third6 : 5C 528 Hz

These are pure or just intervals. When two strings are in a pure interval, you hear no beating — no wobble. Play slightly out of tune and you hear a pulsing amplitude modulation called beats.

Beat Frequencies: The Sound of Imperfection

When two notes with frequencies f1f_1 and f2f_2 are played simultaneously, the combined waveform beats at a rate equal to their difference:

fbeat=f1f2f_{\text{beat}} = |f_1 - f_2|

This follows from the sum-to-product identity:

sin(2πf1t)+sin(2πf2t)=2cos ⁣(2πf1f22t)sin ⁣(2πf1+f22t)\sin(2\pi f_1 t) + \sin(2\pi f_2 t) = 2\cos\!\left(2\pi \frac{f_1 - f_2}{2}\, t\right)\sin\!\left(2\pi \frac{f_1 + f_2}{2}\, t\right)

The sine term is the "average" pitch you hear. The cosine term is a slow amplitude envelope that pulsates at half the difference frequency — so you perceive one full beat per 1f1f2\tfrac{1}{f_1 - f_2} seconds.

Piano tuners exploit this directly. They tune fifths to beat at a specific slow rate (usually 0–2 Hz), rather than aiming for zero beats. This is not sloppiness — it's the whole point, as we'll see.

Beat Frequencies: two near-unison notes

When two frequencies are close but not equal, their sum oscillates in volume at a rate equal to their difference.

Notice how at 1 Hz you hear a slow, clear throb. At 6–8 Hz it sounds rough and dissonant. Piano tuners listen for these beats constantly.

The Pythagorean Comma: Where the Math Breaks

Here is the core problem. Suppose we want to tune a piano so that:

  1. Every octave is a perfect 2:1 ratio, and
  2. Every fifth is a perfect 3:2 ratio.

Start on C. Go up by 12 perfect fifths and you should arrive at C again — seven octaves higher. Let's check:

(32)12=531,441524,2881.01364\left(\frac{3}{2}\right)^{12} = \frac{531{,}441}{524{,}288} \approx 1.01364 27=1282^7 = 128

After 12 fifths: (32)12=531,441524,288\left(\frac{3}{2}\right)^{12} = \frac{531{,}441}{524{,}288}

After 7 octaves: 27=1282^7 = 128

Divide them:

(3/2)1227=531,441524,2881.01364\frac{(3/2)^{12}}{2^7} = \frac{531{,}441}{524{,}288} \approx 1.01364

They don't match. The ratio 531,441524,288\frac{531{,}441}{524{,}288} is called the Pythagorean comma, and in musical units (cents, where 100 cents = one semitone):

Pythagorean comma=1200log2 ⁣(531,441524,288)23.46 cents\text{Pythagorean comma} = 1200 \log_2\!\left(\frac{531{,}441}{524{,}288}\right) \approx 23.46 \text{ cents}

That's nearly a quarter of a semitone — easily audible.

A cent is 1100\frac{1}{100} of an equal-tempered semitone. It's defined so that 1200 cents = one octave. Difference in cents between two frequencies f1f_1 and f2f_2: Δc=1200log2(f2/f1)\Delta c = 1200 \log_2(f_2/f_1).

The Pythagorean Comma: Spiral of Fifths

Stack 12 perfect fifths (×3/2 each) and you should return to C — but you overshoot by ~23.5 cents. The grey ring shows equal-tempered positions; the orange path shows where you actually land.

0/12 fifths

Step through the circle one fifth at a time. Notice how the orange dots drift clockwise relative to the grey equal-tempered positions — about 2 cents per fifth. After 12 fifths you've overshot C by 23.46 cents. The circle of fifths doesn't close.

Why This Is Mathematically Inevitable

The deeper reason is this: no positive integer power of 2 can ever equal a positive integer power of 3.

Formally: 2a3b2^a \neq 3^b for any positive integers a,ba, b.

Proof: 2a2^a is divisible only by 2. 3b3^b is divisible only by 3. By the Fundamental Theorem of Arithmetic (unique prime factorisation), they can never be equal. \blacksquare

More generally: an octave (ratio 2/12/1) and a fifth (ratio 3/23/2) are incommensurable — their logarithms have an irrational ratio:

log(3/2)log(2)=log2(3/2)=log2310.58496\frac{\log(3/2)}{\log(2)} = \log_2(3/2) = \log_2 3 - 1 \approx 0.58496\ldots

This is irrational (since log23\log_2 3 is irrational — 3=2x3 = 2^x has no rational solution). So no finite number of perfect fifths will ever stack up to a whole number of octaves. The circle of fifths never closes.

The same argument applies to thirds: log(5/4)log2=log2(5/4)\frac{\log(5/4)}{\log 2} = \log_2(5/4) is irrational. Every pure interval except the octave is incommensurable with the octave.

This is a consequence of the density of the rationals in the reals: you can get arbitrarily close with rational approximations, but never exact. The Stern–Brocot tree gives the best rational approximations to log23\log_2 3, which is why 12-tone, 19-tone, and 31-tone equal temperaments all appear as convergents.

The Three Historical Approaches

Since perfection is impossible, every tuning system is a different philosophical answer to the question: which imperfections are most tolerable?

1. Pythagorean Tuning

Stack 11 perfect fifths, then close the circle by making the 12th fifth absorb the entire Pythagorean comma. That gap lands on one specific fifth — called the wolf fifth — which is reportedly unlistenable (roughly 678 cents instead of 702 — a deviation of ~24 cents, nearly a quarter semitone).

In Pythagorean tuning, all fifths and fourths are pure. The major thirds (81/64 ≈ 407.8 ¢) are noticeably sharp compared to the pure 5:4 (386.3 ¢). Works well for medieval music that stays in a few keys; catastrophic if you modulate.

2. Just Intonation

Choose simple integer ratios for all notes: 98,54,43,32,53,158\frac{9}{8}, \frac{5}{4}, \frac{4}{3}, \frac{3}{2}, \frac{5}{3}, \frac{15}{8}. Within a single key, I'm told this sounds great — every consonant interval is mathematically pure, with no beating at all.

The problem: modulate to a new key and you need entirely different frequencies. On a fixed-pitch instrument like a piano, this limits you to one key. Worse, even within a key, the "D" you get from the major second of C differs from the "D" you get as the minor third of B♭ by a syntonic comma (81/80 ≈ 21.5 ¢).

3. Equal Temperament

Divide the octave into 12 equal semitones, each with ratio 21/122^{1/12}. Every fifth is then:

27/121.4983vs pure 32=1.50002^{7/12} \approx 1.4983 \quad \text{vs pure } \frac{3}{2} = 1.5000

A difference of about 1.955 cents — barely perceptible. Every key sounds identical, and the comma is distributed evenly across all 12 fifths. This is the system used on all modern pianos.

The tradeoff: major thirds in equal temperament are 400 ¢, but the pure 5:4 major third is 386.3 ¢ — a difference of 13.7 cents, which is quite audible on sustained chords. Orchestral players and singers instinctively sharpen their fifths and flatten their thirds toward just intonation; the piano cannot.

Tuning System Comparison (cents vs Equal Temperament)

Each bar shows how far a note deviates from equal temperament in cents (1 semitone = 100 ¢). Positive = sharp, negative = flat. Select a system to highlight it.

C (1)Unison
0.0 ¢
D (2)Major 2nd
+3.9 ¢
E (3)Major 3rd
-13.7 ¢
F (4)Perfect 4th
-2.0 ¢
G (5)Perfect 5th
+2.0 ¢
A (6)Major 6th
-15.6 ¢
B (7)Major 7th
-11.7 ¢
C' (8)Octave
0.0 ¢
Show exact ratios for Just Intonation (5-limit)
NoteRatioCentsvs ET
C (1)1.0000000.00±0.00 ¢
D (2)1.125000203.91+3.91 ¢
E (3)1.250000386.31-13.69 ¢
F (4)1.333333498.04-1.96 ¢
G (5)1.500000701.96+1.96 ¢
A (6)1.666667884.36-15.64 ¢
B (7)1.8750001088.27-11.73 ¢
C' (8)2.0000001200.00±0.00 ¢

Toggle between systems above. Notice that just intonation has the purest thirds and fifths (zero cents deviation for the ones it targets) but introduces large errors elsewhere. Equal temperament distributes the error evenly but no interval except the octave is pure.

4. Meantone Temperament (Bonus)

Quarter-comma meantone, used extensively from the 15th to 18th centuries, splits the difference differently: it tunes the major third pure (5:4) and shrinks each fifth by a quarter of the syntonic comma (~5.4 ¢). The result: pure thirds in the "home" keys (I'm told these sound noticeably better than equal temperament), but an even worse wolf fifth than Pythagorean (about 737.6 ¢, nearly 40 ¢ flat).

Bach's Well-Tempered Clavier was written in a well temperament — not equal temperament, but a specific unequal temperament where each key has a different character. The famous "key colours" come from the varying amounts of comma distributed to each interval.

Stretch Tuning: Even Equal Temperament Isn't Enough

Even if we accept equal temperament, there's another wrinkle: real piano strings don't vibrate in perfect harmonics.

An ideal vibrating string produces harmonics at exactly f,2f,3f,4f,f, 2f, 3f, 4f, \ldots. A real string has nonzero stiffness, which causes inharmonicity — the overtones are stretched slightly sharp:

fn=nf11+B(n21)f_n = n \cdot f_1 \cdot \sqrt{1 + B(n^2 - 1)}

where BB is the inharmonicity coefficient (larger for short, thick bass strings). The 2nd partial is slightly sharper than 2f12f_1, the 3rd is sharper still.

This means that if you tune the octave using the 2nd partial of the lower note (as a tuner naturally would, listening for the beat to vanish), you'll end up with the higher octave sharp of equal temperament. This compound effect across 7 octaves requires stretch tuning — treble notes are tuned progressively sharp, bass notes progressively flat.

The resulting curve (octave width vs. note number) is called the Railsback curve, named after O.L. Railsback who measured it in the 1930s. A piano tuned with a flat Railsback curve apparently sounds dull and unclear; one tuned to strict equal temperament sounds thin at the extremes. The "right" amount of stretch is an aesthetic judgment the tuner makes for each individual piano.

Summary: Three Layers of Impossibility

Layer 1 (Number Theory): 2a3b2^a \neq 3^b for any positive integers a,ba, b. Octaves and fifths are incommensurable. No finite equal division of the octave can make all intervals pure.

Layer 2 (Analysis): log23\log_2 3 is irrational, so the circle of fifths never closes. No rational tuning can simultaneously purify all intervals.

Layer 3 (Physics): Real strings are inharmonic. Even if you solved layers 1 and 2, the overtones of real strings don't align with those of any tempered scale.

Each layer would individually make perfect tuning impossible. Together they guarantee that every piano is a carefully engineered compromise — a machine for making music despite what the mathematics demands.

The next time you hear a piano, know that the tuner has made hundreds of tiny peace treaties with the irrationality of log23\log_2 3. Every note is slightly wrong in a carefully chosen way — and apparently that's good enough.

Further Reading

  • Ross W. Duffin, How Equal Temperament Ruined Harmony (and Why You Should Care)
  • Harry Partch, Genesis of a Music — the case for just intonation taken to its logical extreme
  • Owen Jorgensen, Tuning: Containing the Perfection of Eighteenth-Century Temperament — exhaustive historical survey
  • The Railsback curve: O. L. Railsback, "Scale Temperament as Applied to Piano Tuning," Journal of the Acoustical Society of America (1938)

Related Articles

·17 min read

Automatic Differentiation

A deep-dive into automatic differentiation: symbolic vs. numerical vs. AD, AST transformation, dual numbers, tapes, hybrid methods, and a generic C++ implementation that computes gradients and solves optimisation problems.