Pili are crucial virulence factors for many Gram-negative pathogens. These surface structures provide bacteria with a link to their external environments by enabling them to interact with, and attach to, host cells, other surfaces or each other, or by providing a conduit for secretion. Recent high-resolution structures of pilus filaments and the machineries that produce them, namely chaperone-usher pili, type IV pili, conjugative type IV secretion pili and type V pili, are beginning to explain some of the intriguing biological properties that pili exhibit, such as the ability of chaperone-usher pili and type IV pili to stretch in response to external forces. By contrast, conjugative pili provide a conduit for the exchange of genetic information, and recent high-resolution structures have revealed an integral association between the pilin subunit and a phospholipid molecule, which may facilitate DNA transport. In addition, progress in the area of cryo-electron tomography has provided a glimpse of the overall architecture of the type IV pilus machinery. In this Review, we examine recent advances in our structural understanding of various Gram-negative pilus systems and discuss their functional implications.