Pressing a string against the fingerboard (fretting) shortens its vibrating length. This reduces the mass of the vibrating portion and increases tension per unit length, causing the string to vibrate at a higher frequency.
Each fret represents a semitone step. Pressing at the 12th fret halves the string length, doubling the frequency—an octave higher. This principle allows a single string to produce many pitches, enabling melodies, chords, and scales on fretted instruments (guitar, violin, cello, etc.) and unfretted ones (where the player's finger acts as the fret).