Our western system of well-tempered musical instruments is in fact a system of slight mistuning. Our ears easily recognize what we call octaves, notes that vibrate at exactly twice the frequency of a given note. This comes directly from the physics of sound production. A string or column of air that vibrates primarily at a given frequency is also capable of vibrating at twice that frequency.

For example, we perceive a C that is an octave above middle C as the same note in the scale, a C, but higher. The second most important note in the scale, the fifth, or G, is similarly hardwired in the brain, with a G vibrating, in theory at least, at a ratio of 3:2 to the tonic.

Any musical system must preserve what we call an octave absolutely at a ratio of 2:1, and our system strives to preserve the fifth as close as possible to 3:2, the fourth as close as possible to 4:3, the major third to 5:4, and so on.

Observe that if we proceed up the piano keyboard by fifths from the lowest C, it takes 12 such intervals (C, G, D, A, E, B, F♯, C♯, G♯, D♯, A♯, F, C) to reach C again. In the meantime, we've cycled through all 12 half tones in the scale, and the highest C will be seven octaves above the lowest C.

Here's the math: (3/2)^{12} ≈ 2^{7}. That is, 3^{12} ≈ 2^{19}, or 531,441 ≈ 524,288. We know from the Fundamental Theorem of Arithmetic that no positive power of 2 will ever equal a power of 3.

To correct for the difference, we set the ratio of the frequency of the fifth above to that of the tonic (an interval of seven half tones) at 2^{7/12}:1, or about 1.4983:1, instead of the aural ideal of 1.5:1. In a similar manner, we set the ratio of the fourth above (five half tones) at 2^{5/12}:1, or about 1.3348:1, instead of the ideal of 1.3333:1. The major third above (four half tones) to the tonic is 2^{4/12}:1 or about 1.2599:1, instead of 1.2500:1.

Note: In general, the ratio of the frequency of a note that is n half steps above the tonic to the frequency of the tonic itself is 2^{n/12}:1. The ratio of a note m full steps above the tonic to the tonic is given by 2^{m/6}:1. That is, if the interval in question is 12 half steps or 6 full steps — a full octave — then the ratio will be 2:1, as desired.

Close enough not only for rock-'n'-roll, but for Bach-'n'-Beethoven as well!

Source: wikipedia.org