There is a way to derive the number of tones in one octave using only basic physics and mathematics. This derivation uses the circle of fifths. By picking an initial tone and progressing through the tones, going up a perfect fifth each time, we will eventually arrive back at the same tone. The sequence of tones we cycle through is called the circle of fifths, and its number of tones can be calculated to be twelve.
Out of all the intervals we use, why use the perfect fifth? Pythagoras discovered that notes sounded together with a simple ratio of frequencies will sound harmonious together (because the partials overlap). The perfect fifth has the ratio of 3/2, which is the simplest possible after 2/1 (octave) and 1/1 (unison). The perfect fifth is therefore a very consonant interval, so it is a natural choice to build the scale with.
Suppose we choose an arbitary tone to start with. To transpose a tone upwards by a fifth, we multiply its frequency by 3/2. Transposing up one fifth gives a tone with a frequency that makes a ratio of 3/2 with the original frequency. Transposing up two fifths gives us the ratio 9/4. However, this note is more than one octave above the original note - the tone one octave above the original tone has the ratio 2, which is smaller than 9/4. To transpose it down to the same octave, we multiply the frequency by 1/2 to get 9/8. Three fifths up gives 27/16. Four fifths up and a second octave down gives 81/64 and so on.
The table below shows what happens after we do this twelve times. As an example, the table also shows what tones we would get if the starting tone was A. (The frequency of middle A is defined as 440 Hz.)
Fifths Octaves Ratio Tone
0 0 1/1 A
1 0 3/2 E
2 1 9/8 B
3 1 27/16 F#/Gb
4 2 81/64 C#/Db
5 2 243/128 G#/Ab
6 3 729/512 D#/Eb
7 3 2187/2048 A#/Bb
8 4 6561/4096 F
9 5 19683/16384 C
10 5 59049/32768 G
11 6 177147/131072 D
12 7 531441/524288 A
After 12 fifths up and 7 octaves down, we obtain the ratio 531441/524288 = 1.0136, which is really close to to 1. The difference between those two tones is hardly noticable by the untrained ear. The twelve tones produced above are the twelve tones of the scale. Tada!
Notice that there is one problem -- the ratio isn't exactly 1. It is obvious by basic number theory that it is impossible to make it 1. The ratio will always a fraction in the form 2a/3b, and the numerator and denominator are relatively prime. However, it is possible for the ratio to approximate 1 arbitarily closely by transposing up more fifths. 53 fifths up and 31 octaves down gives us 1.0021, a better approximation than 12 tones, disregarding the fact that a 53-tone scale is very complicated. Scales used in microtonal music (i.e. scales with intervals smaller than semitones) also tend to use numbers that give good approximations. Examples include the 24-tone scale (used in Arab music) and the aforementioned 53-tone scale.
The Pythagorean tuning system is based on this derivation. It has a few advantages -- it is a type of well-tempered tuning (the ratios between each interval remains unchanged when transposing between keys) and all the fifths sound nice (all of them being 3/2 ratios). However there are huge drawbacks that make it impractical for acutal tuning. Octaves sound terrible (tuning by fifths means that the octaves will draft away from the 1/2 ratio as we progress up the scale). Other intervals like the perfect fourth sound terrible too, compared to other tunings like just temperament. (Simple ratios such as 5/4 sound nice, but Pythagorean tuning has ugly ratios such as 177147/131072.)
Although Pythagorean tuning has been largely surplanted by equal temperament, it's still good to keep in mind that this is where the twelve-tone scale comes from.