The Elegant and Simple Relationship Between Mathematics and Music
The Pythagoreans discovered that simple numerical ratios create pure sounds, giving rise to their motto: ‘Everything is number.'

After completing his travels, Pythagoras founded a school in Croton around 530 BC. Among the Pythagorean community, about which little is known, mathematics and music were studied, among other disciplines. In particular, the Pythagoreans experimented with musical instruments. One of their instruments, the monochord, illustrates their discoveries.
A monochord is an instrument with a single taut string, and plucking it produces a note. You can also press the string at a point between the two ends, as if it were a guitar, and then pluck both sides of the string. Obviously, if you press the string exactly in the center, it will produce the same note on both sides.
If, however, you divide the string into two unequal parts, for example in a 2:1 ratio, you will hear two different notes: a lower note from the longer part and a higher one from the shorter part. But with the 2:1 ratio, not two random notes are generated, but exactly one octave, which is the purest sound that two different notes can produce.
By dividing the string so that the ratio between the two parts is 3:2, you obtain a fifth, the interval by which a violin is tuned. Continuing to perform experiments of this kind, the Pythagoreans made an important discovery: that the simpler the numerical ratio, the purer the sound. Conversely, the more complex the ratio, the more impure the sound. Thus, they discovered a relationship between sounds and numerical ratios. This gave rise to the Pythagorean motto: "Everything is number." By "number," they meant a natural number or a ratio between natural numbers, that is, a rational number.
This discovery influenced educational curricula for centuries. Music teaching was essentially the Pythagorean doctrine of numerical ratios and corresponding sounds. The quadrivium, the second component of fundamental studies in the Middle Ages, included arithmetic, geometry, astronomy, and music. However, since music was also fundamentally mathematical, the quadrivium consisted almost exclusively of mathematics.
The philosopher, mathematician and scientist Gottfried Wilhelm Leibniz (1646-1716) formulated the idea behind this in the following terms: "Music is a secret arithmetical exercise of the soul, which deals with numbers without knowing it."
The Pythagoreans' musical theory had a further consequence, born from a mathematical difference. Try to imagine a piano keyboard. If you play a key corresponding to the note C on the left side of the keyboard, the piano produces a very low sound. Now, repeat the same thing seven times, each time moving up an octave to the right. Eventually, you will still get a C, but this time with a very high sound. The seven octaves correspond to applying the ratio 1:2 seven times.
It is also possible to move from the lowest C to the highest C by proceeding in fifths. In this case, you'll need 12 fifths. Each fifth corresponds to a ratio of 2:3.
The resulting numbers differ by very little, and this difference is called the "Pythagorean comma." This "comma" is the cause of the impossibility of tuning a piano so that the sound is pure in every key.
Andreas Werckmeister (1645–1706) was the first to devise well-tempered tunings that allowed the use of all keys. Johann Sebastian Bach (1685–1750) later implemented them in his famous collection The Well-Tempered Clavier.
References
How Philosophy Works: The concepts visually explained by DK (July 4, 2019)
Kleines Mathematikum. Die 101 wichtigsten Fragen und Antworten zur Mathematik by Albrecht Beutelspacher (15 Nov. 2011)