1520s, originally, "lowest note in the medieval musical scale," in the system of notation devised by Guido d'Arezzo, contraction of Medieval Latin gamma ut, from gamma, the Greek letter, indicating a note below A, + ut (later do), the low note on the six-note musical scale that took names from corresponding syllables in a Latin hymn for St. John the Baptist's Day:
Ut queant laxis resonare fibris
Mira gestorum famuli tuorum
Solve polluti labii reatum,
etc. Gamut came to be used for "the whole musical scale;" the figurative sense of "entire scale or range" of anything is first recorded 1620s.