As any guitar player will tell you, the concept of an octave is intuitive and grounded in physics. An octave is what you get when you shorten the length of a plucked string by half thus doubling the frequency of the sound. But in principle you should be able to divide up the frequency space in an octave into any number of intervals, not just twelve.
(As it happens, there are two recent articles on the math of music that are worth reading: a Physics Today article about Richard Feynman's interest in piano tuning (pdf) and this one from Slate.)
The historical meaning of 12 is that the Greek philosopher Pythagoras had some strong religious beliefs about pure numbers and constructed the early version of our musical scale out of 3/2 intervals (i.e. out of the next simplest whole number fraction after the octave). As the Slate article explains, constructing a twelve-note scale out of 3/2 intervals doesn't quite bring you back round to an octave. The Pythagorean system works because the quantity (3/2)^12 * (1/2)^6 = 2.0273 is approximately equal to two -- a quantity known as the Pythagorean comma.
But this caused some problems for musicians. For example, the octave sounded perceptibly out of tune and you had to re-tune your instrument in order to play songs in different keys. So during the Renaissance, musicians came up with the concept of equal temperament, where the octave was divided into twelve logarithmically equal intervals of 2^(1/12) and each Pythagorean interval was thus re-tuned by a tiny amount. Bach was so psyched by this innovation that he went out and wrote the Well-Tempered Clavier in celebration.
So far, so good, but this still doesn't quite answer the question of why twelve? Clearly you can create equal tempered scales with any number of intervals, but is it possible to create a Pythagorean system with different numbers of intervals?
The algorithm to find out is pretty simple.
- Start with a base frequency of A=440 Hz.
- Step upwards by factors of 3/2 ... so 440, 660, 990, etc.
- If we go above an octave (880) then we need to divide by 2 to bring it back into the same octave range. So 990 becomes 495, and then we step upwards again by 3/2.
- The goal is to get as close as possible (either high or low) to 880 and then stop.
So for most N, it is not really possible to craft a Pythagorean scale - either you don't land close enough to an octave or else you have oddly spaced intervals - but for a few N, the formula seems to work. N=5 (pentatonic scale) is not too bad and old, familiar N=12 works better.
But the winner is definitely N=53 which falls almost exactly on the red line - much more exactly than the familiar twelve tone scale. This scale, with 53 (barely distinguishable) intervals, is virtually equal tempered to begin with. Apparently this very bizarre musical system was first discovered by the Chinese mathematician Ching Fang thousands of years ago and was later rediscovered by various westerners (including Newton). And people have allegedly written music for it! Go figure.
So: a fairly interesting answer to the question posed. And if you're interested in spending time on wikipedia be warned that there are a truly ridiculous number of baroque music theory articles lurking there.