Stack twelve perfect fifths on top of one another and you should land exactly seven octaves above where you began. Every musician learns this as the circle of fifths. It closes.
It does not close.
A perfect fifth is a frequency ratio of 3:2. Do it twelve times and you have multiplied by 129.746. Seven octaves is 2 to the power of seven, which is 128. Those two numbers are not equal, and no amount of careful tuning will ever make them equal, because no power of three can land on a power of two. The gap is 23.46 cents — about a quarter of a semitone, and easily loud enough to hear.
It is called the Pythagorean comma, which is a small historical injustice. The earliest surviving description is in a Greek text from around 300 BCE, and Chinese mathematicians had it written down by 122 BCE.
For most of musical history the fix was to cheat in one spot. Tune eleven fifths pure and pour the entire error into the twelfth, producing an interval so ugly it was called the wolf. Composers simply avoided the keys that used it.
Equal temperament, which is what your piano is tuned to now, spreads the error instead. Divide the octave into twelve steps of exactly 2^(1/12) — an irrational number, so no two notes on the instrument are in a whole-number ratio — and each fifth comes out roughly 2 cents flat.
For comparison:
- Twelve fifths give 129.746; seven octaves give 128. That difference is arithmetic, not sloppiness
- The gap is 23.46 cents, roughly a quarter of a semitone
- Every fifth on a modern piano is about 2 cents flat, deliberately
- Around 50 BCE, Ching Fang worked out that a cycle of 53 fifths closes the gap far more neatly than twelve
That is the bargain Western music struck. A piano can play in any key you like, and in exchange it plays no key perfectly.
Every piece of music you have ever heard on a keyboard was a compromise with arithmetic.