Music theory as we know it, at least in the Western world, was first developed by the Pythagoreans of Ancient Greeks. They investigated the physical and mathematical properties of music and harmony, such as how plucking a wire under tension would produce a sustained sound (just like a guitar), and how this sound would change when either the tension or length of the wire was changed.
One of the first discoveries was how two stretched wires, under equal tension but one being twice as long as the other, would produce the same note (i.e. the type or pitch of sound) but the longer one would be much lower (what we now refer to as an octave lower). A similar situation can be shown by pressing two keys on a piano keyboard that are seven white keys apart (see the picture below for the two keys called C). The resultant sound is harmonious or “pleasurable to the ears”, and you can hear that the two notes are the same but one is lower than the other.
The Pythagoreans experimented building wires of varying lengths, which produced harmonious or “pleasurable” sounds when plucked together. You can get a feel to how they decided what was “pleasurable” by playing the notes C and E on a keyboard at the same time, and then comparing that to the sound produced when you play C, C# and D together. You notice quite clearly that the former pair “blend” their sound together while the latter group seem to work against eachother (making an “eurghghrr!!” type-noise).
Using wires of varying lengths and tensions, it soon becomes possible to build simple instruments for creating music. Eventually, a standard was reached using 13 notes that gradually increased their pitch in equal increments played in order; today we call these increments semitones. If you look back up at the keyboard diagram you will see that going from one C to another C (inclusive) requires 13 keys (white and black).
N.B. Beginners often do not realize that the difference between a white key and a black key that are next to each other (e.g. C and C#) is the same as two white keys that are next to each other (but without a black key in the middle, e.g. B and C, E and F); they are all one semitone apart. It took me 13 years of playing music to realize that: no one had ever actually explained it to me.