The bacterial flagellar filament has long been studied to understand how a polymer composed of a single protein can switch between different supercoiled states with high cooperativity. Here we present near-atomic resolution cryo-EM structures for flagellar filaments from both Gram-positive Bacillus subtilis and Gram-negative Pseudomonas aeruginosa. Seven mutant flagellar filaments in B. subtilis and two in P. aeruginosa capture two different states of the filament. These reliable atomic models of both states reveal conserved molecular interactions in the interior of the filament among B. subtilis, P. aeruginosa and Salmonella enterica. Using the detailed information about the molecular interactions in two filament states, we successfully predict point mutations that shift the equilibrium between those two states. Further, we observe the dimerization of P. aeruginosa outer domains without any perturbation of the conserved interior of the filament. Our results give new insights into how the flagellin sequence has been "tuned" over evolution.