"pointed pin of wood, metal, or other material," mid-15c., pegge, from Middle Dutch pegge "peg," or a similar Low German word (Low German pigge "peg," German Pegel "gauge rod, watermark," Middle Dutch pegel "little knob used as a mark," Dutch peil "gauge, watermark, standard"); of uncertain origin; perhaps from PIE *bak- "staff used as support" (see bacillus).
To be a square peg in a round hole (or the reverse) "be inappropriate for one's situation" is attested by 1836; to take someone down a peg "humble, lower the esteem of" is from 1580s, but the original literal sense is uncertain (most of the sensibly plausible candidates are not attested until centuries later). Peg leg "wooden leg of the simplest form" is attested from 1765.
"fasten with or as if on a peg, drive pegs into for the purpose of fastening," 1590s, from peg (n.). Meaning "fix the market price" is by 1882. Slang sense of "identify, classify" is recorded by 1920. Related: Pegged; pegging.