The Salmonella enterica opvAB operon is a horizontally-acquired locus that undergoes phase variation under Dam methylation control. The OpvA and OpvB proteins form intertwining ribbons in the inner membrane. Synthesis of OpvA and OpvB alters lipopolysaccharide O-antigen chain length and confers resistance to bacteriophages 9NA (Siphoviridae), Det7 (Myoviridae), and P22 (Podoviridae). These phages use the O-antigen as receptor. Because opvAB undergoes phase variation, S. enterica cultures contain subpopulations of opvABOFF and opvABON cells. In the presence of a bacteriophage that uses the O-antigen as receptor, the opvABOFF subpopulation is killed and the opvABON subpopulation is selected. Acquisition of phage resistance by phase variation of O-antigen chain length requires a payoff: opvAB expression reduces Salmonella virulence. However, phase variation permits resuscitation of the opvABOFF subpopulation as soon as phage challenge ceases. Phenotypic heterogeneity generated by opvAB phase variation thus preadapts Salmonella to survive phage challenge with a fitness cost that is transient only.