We present the history of the theory and practice of musical scales, which culminated in today's universal 12-tone scale. Then we prove that this 12-part division of the octave is optimal. The proof is an application of the theory of continued fractions. Drobisch in \emph{Über musikalische Tonbestimmung und Temperatur} (1852) used continued fractions for subdividing the octave into intervals. It is not clear whether he was the first to use this approach; e.g. Euler was dealing with mathematics of temperament and also wrote a tract on continued fractions, \emph{De Fractionibus Continuis Dissertatio} (1737).sikic.pdf