Phase-variable expression of type 1 fimbriae in Escherichia coli K-12 involves inversion by site-specific recombination of a 314 bp sequence containing the promoter for fim structural gene expression. The invertible sequence is flanked by 9 bp inverted repeats, and each repeat is in turn flanked by non-identical recombinase-binding elements (RBEs) to which the FimB or FimE site-specific recombinases bind. These proteins have distinct DNA inversion preferences: FimB inverts the switch in the ON-to-OFF and OFF-to-ON directions with similar efficiencies, whereas FimE inverts it predominantly in the ON-to-OFF direction. We have found that FimB and FimE invert the switch through a common mechanism. A genetic investigation involving base-by-base substitution combined with a biochemical study shows that the same DNA cleavage and religation sites are used within the 9 bp inverted repeats, and that each recombination involves a common 3 bp spacer region. A comprehensive programme of RBE exchanges and replacements reveals that FimB is much more tolerant of RBE sequence variation than FimE. The asymmetric location of conserved 5'-CA motifs at either side of each spacer region allows the inside and outside of the switch to be differentiated while the RBE sequence heterogeneity permits its ON and OFF forms to be distinguished by the recombinases.