Bacterial flagella self-assemble a strong, multi-component drive shaft that couples rotation in the inner membrane to the microns-long flagellar filament that powers bacterial swimming in viscous fluids. We solved structures of the intact Salmonella flagellar basal body, using cryo-electron microscopy to resolutions between 2.2 and 3.7 Å. The structures reveal molecular details of how 173 protein molecules of 13 different types assemble into a complex spanning two membranes and a cell wall. The helical drive shaft at one end is intricately interwoven with the inner membrane rotor component, and at the other end passes through a molecular bearing that is anchored in the outer membrane via interactions with the lipopolysaccharide. The in situ structure of a protein complex capping the drive shaft provides molecular insight into the assembly process of this molecular machine.