"nailhead, knob," late 13c., from Old English studu "pillar, prop, post," from Proto-Germanic *stud- (source also of Old Norse stoð "staff, stick," properly "stay," Middle High German stud, Old English stow "place"), from PIE *stu-, variant of root *sta- "to stand, make or be firm." Sense expanded by late 14c. to include ornamental devices fixed in and projecting from a surface. From the Old English meaning comes the specific sense "one of the small beams of a building which form a basis for the walls."
"horse used for breeding," Old English stod "herd of horses, place where horses are kept for breeding," from Proto-Germanic *stodo (source also of Old Norse stoð, Middle Low German stod, Old High German stuot "herd of horses," German Stute "mare"), from PIE root *sta- "to stand, make or be firm," with derivatives meaning "place or thing that is standing" (source also of Old Church Slavonic stado "herd," Lithuanian stodas "a drove of horses").
Sense of "male horse kept for breeding" is first recorded 1803; meaning "man who is highly active and proficient sexually" is attested from 1895; that of "any young man" is from 1929. Stud-poker (1864) is said to be from stud-horse poker, but that phrase is not found earlier than 1879.
c. 1500, "set with studs;" 1560s in studded with "as though sprinkled with nails with conspicuous heads;" from stud (n.1).