Once upon a time, people noticed that certain sounds are pleasant to hear, while others are not. They began to experiment with it. The most important early discovery in this vein was the notion that sound is vibration. This is the fundamental principle of all musical theory, modern or ancient. The next discovery was that of the octave: If you make two vibrations, one at double the frequency of the other, they sound... the same, in some way. The faster one is clearly higher pitched, but they're harmonically equivalent.
The Ancient Greeks built upon this discovery, and eventually produced what we now call Pythagorean tuning. Pythagorean tuning is built around simple frequency ratios; systems like this are called "just intonations." The most important ratio other than the octave is the so-called "perfect fifth," which describes a gap of five staff positions in modern musical notation. It spans a gap of seven semitones; there are a total of twelve semitones per octave in "conventional" systems such as Pythagorean tuning. In Pythagorean tuning, a perfect fifth is a ratio of 3:2, meaning the faster vibration oscillates thrice for every two oscillations of the slower vibration. So far, this is all very nice, and fits in well with the Pythagorean mathematical ideals of rationality. But there's a problem. I told you that a perfect fifth has a ratio of 3:2, is composed of seven semitones, twelve of which make up an octave, and the octave is 2:1. Suppose we start at middle C (or C4), and move a perfect fifth up. We arrive at G4, at 3:2 times our original frequency. We continue to D5, at 9:4. Next comes A6, at 27:8. Then E6, at 81:16, B7, at 243:32, F♯7, at 729:64, C♯8, at 2187:128, and finally G♯8 at 6561:256. Now suppose we go down from C4. We find ourselves at F3 at 2:3, B♭3 at 4:9, E♭2 at 8:27, and A♭1 at 16:81. The ratio from C4 to A♭1 is 81:16, and the ratio from G♯8 to C4 is 6561:256. Multiplying, we see that the ratio from G♯8 to A♭1 is 531441:4096. But A♭ and G♯ are supposed to be the same note. Going by octaves, we should get 128:1. The other ratio is rather large and unwieldy, because we have seven octaves of space, so if we divide those out, we get a ratio from G♯ to A♭ of precisely 531441:524288. This interval is called the Pythagorean comma. It's the difference (remember, in music, we never add or subtract frequencies, so this is actually the ratio) between a chromatic and a diatonic semitone, among other things.
So what does this actually mean? It means Pythagorean octaves overlap, if only a little, since G♯ is a little sharper than A♭. That's a problem for perfect fifths. One of the twelve "perfect" fifths is ruined by spanning this overlap, being flattened to a rather dissonant diminished sixth. So Pythagorean tuning, for all its beauty and simplicity, is not perfect.
Updated: In part two, we discuss quarter-comma meantone, a derivative of Pythagorean tuning.