The bacterial flagellum is a macromolecular protein complex that harvests energy from ion-flow across the inner membrane to power bacterial swimming in viscous fluids via rotation of the flagellar filament. Bacteria such as Salmonella enterica are capable of bi-directional flagellar rotation even though ion flow is uni-directional. How uni-directional ion-movement through the inner membrane is utilized by this macromolecular machine to drive bi-directional flagellar rotation is not understood, but a chemotactic response regulator in the cytoplasm is known to reverse the direction of rotation. We here present cryo-EM structures of intact Salmonella flagellar basal bodies, including the cytoplasmic complexes required for power transmission, in conformations representing both directions of rotation. The structures reveal that the conformational changes required for switching the direction of rotation involve 180 degree rotations of both the N- and C-terminal domains of the FliG protein. Combining these models with a new, high-resolution, cryo-EM structure of the MotA5B2 stator, in complex with the C-terminal domain of FliG, reveals how uni-directional ion-flow across the inner membrane is used to accomplish bi-directional rotation of the flagellum.