Look down the neck of any guitar and the metal frets crowd together as they head toward the body. The first gap is roughly twice as wide as the one at the 12th fret. That squeeze isn't a style choice: it is what a musical scale looks like when you draw it with a ruler.
A plucked string's pitch depends on three things: how tight it is, how heavy it is, and how long the vibrating part is. The French friar Marin Mersenne wrote these rules down in 1636, in his book Harmonie universelle. For a guitarist only the last one changes while playing. Press a string against a fret and you shorten the part that can vibrate, which raises the pitch. Frequency goes as one over length: halve the length and the frequency doubles.
A doubling of frequency is an octave, the same note one "level" higher. So the 12th fret, which is one octave up, sits at exactly the middle of the string. On a Fender Stratocaster, whose scale length (nut to bridge) is 25.5 inches or about 648 mm, the 12th fret is about 324 mm from the nut. Tap it above and watch the dashed halfway line.
Western music splits the octave into 12 semitones. Our ears hear pitch by ratio, not by difference: going from 110 Hz to 220 Hz sounds like the same jump as 220 Hz to 440 Hz. So in the modern tuning system, called 12-tone equal temperament, each semitone multiplies the frequency by the same number, the twelfth root of two:
That means every fret removes about 5.6% of whatever string is left, not 5.6% of the whole string. Near the nut there is a lot of string, so 5.6% is a big chunk: the first fret on a 648 mm scale sits about 36.4 mm from the nut. By the 12th fret only half the string remains, so the gap to the 13th fret is half as wide, about 18.2 mm. Every 12 frets the spacing halves again. The frets aren't evenly spaced because the notes aren't evenly spaced in length; they're evenly spaced in ratio.
Try Evenly spaced in the interactive to see what goes wrong otherwise. If every gap stayed at 36.4 mm, each fret would shave off a bigger and bigger fraction of the remaining string. The notes run steadily sharp, and the 12th fret would come out roughly 740 cents too high: more than seven semitones past the octave.
Instrument makers needed fret positions long before anyone could calculate a twelfth root easily. The old workshop trick was the rule of 18: measure the remaining string, divide by 18, and put the next fret that far along. Each fret then leaves 17/18 of the string. Vincenzo Galilei, the lutenist father of Galileo, used this 18:17 ratio for fretting the lute in the 16th century.
It is close, but not exact. The true divisor is about 17.817. Dividing by 18 puts every fret slightly too close to the nut, so the notes creep flat. After 12 frets the "octave" lands about 12.5 cents low, around an eighth of a semitone. Switch to Rule of 18 and look at the bars: a gentle slope rather than a disaster, which is why the rule survived for centuries. Mathematicians had meanwhile worked out the exact answer: the Chinese prince Zhu Zaiyu published equal temperament based on the twelfth root of two in 1584, and the Flemish engineer Simon Stevin described it around 1605.
Equal spacing in ratio buys a huge convenience: every key works the same, so you can slide a chord shape anywhere on the neck. The price is that most intervals are slightly off the "pure" whole-number ratios that sound smoothest. A pure major third has a frequency ratio of 5:4, which is about 386 cents. The equal-tempered major third is 400 cents, about 14 cents wide. A perfect fifth fares much better: 700 cents against a pure 702. Guitar frets bake that compromise permanently into metal, which is why a guitar can't bend its tuning chord by chord the way a singer or violinist can.
Real guitars add one more tweak. Pressing a string down stretches it a little, raising its tension and nudging the note sharp. So builders set the bridge saddles slightly further back than the nominal scale length, a fix called compensation. That's why saddles on many electric guitars sit in a staggered line rather than a straight one.
If you have a guitar nearby, lightly touch (don't press) a string right above the 12th fret and pluck it. You get a bell-like harmonic an octave up, because you've forced a still point at the exact middle of the string. Then measure: nut to 12th fret should equal 12th fret to bridge saddle, give or take the compensation. The crowding frets are just the octave, cut in half again and again.