AbstractMost bacteria swim in liquid environments by rotating one or several flagella. The long external filament of the flagellum is connected to a membrane-embedded basal-body by a flexible universal joint, the hook, which allows the transmission of motor torque to the filament. The length of the hook is controlled on a nanometer-scale by a sophisticated molecular ruler mechanism. However, why its length is stringently controlled has remained elusive. We engineered and studied a diverse set of hook-length variants ofSalmonella enterica. Measurements of plate-assay motility, single-cell swimming speed and directional persistence in quasi 2D and population-averaged swimming speed and body angular velocity in 3D revealed that the motility performance is optimal around the wild type hook-length. We conclude that too short hooks may be too stiff to function as a junction and too long hooks may buckle and create instability in the flagellar bundle. Accordingly, peritrichously flagellated bacteria move most efficiently as the distance travelled per body rotation is maximal and body wobbling is minimized. Thus, our results suggest that the molecular ruler mechanism evolved to control flagellar hook growth to the optimal length consistent with efficient bundle formation. The hook-length control mechanism is therefore a prime example of how bacteria evolved elegant, but robust mechanisms to maximize their fitness under specific environmental constraints.Author summaryMany bacteria use flagella for directed movement in liquid environments. The flexible hook connects the membrane-embedded basal-body of the flagellum to the long, external filament. Flagellar function relies on self-assembly processes that define or self-limit the lengths of major parts. The length of the hook is precisely controlled on a nanometer-scale by a molecular ruler mechanism. However, the physiological benefit of tight hook-length control remains unclear. Here, we show that the molecular ruler mechanism evolved to control the optimal length of the flagellar hook, which is consistent with efficient motility performance. These results highlight the evolutionary forces that enable flagellated bacteria to optimize their fitness in diverse environments and might have important implications for the design of swimming micro-robots.