One contribution of 12 to a theme issue 'The bacterial cell envelope'. The flagellum and the injectisome are two of the most complex and fascinating bacterial nanomachines. At their core, they share a type III secretion system (T3SS), a transmembrane export complex that forms the extracellular appendages, the flagellar filament and the injectisome needle. Recent advances, combining structural biology, cryo-electron tomography, molecular genetics, in vivo imaging, bioinformatics and biophysics, have greatly increased our understanding of the T3SS, especially the structure of its transmembrane and cytosolic components, the transcriptional, post-transcriptional and functional regulation and the remarkable adaptivity of the system. This review aims to integrate these new findings into our current knowledge of the evolution, function, regulation and dynamics of the T3SS, and to highlight commonalities and differences between the two systems, as well as their potential applications.