Abstract Stochastic mechanisms can cause a group of isogenic bacteria, each subject to identical environmental conditions, to nevertheless exhibit diverse patterns of gene expression. The resulting phenotypic subpopulations will typically have distinct growth rates. This behavior has been observed in several contexts, including sugar metabolism and pili phase variation. Under fixed environmental conditions, the net growth rate of the population is maximized when all cells are of the fastest growing phenotype, so it is unclear what fitness advantage is conferred by population heterogeneity. However, unlike ideal laboratory conditions, natural environments tend to fluctuate, either periodically or randomly. Here we use a stochastic population model to show that, during growth in such fluctuating environments, a dynamically heterogenous bacterial population can sometimes achieve a higher net growth rate than a homogenous one. By using stochastic mechanisms to sample several distinct phenotypes, the bacteria are able to anticipate and take advantage of sudden changes in their environment. However, this heterogeneity is beneficial only if the bacterial response rate is sufficiently low. Our results could be useful in the design of artificial evolution experiments and in the optimization of fermentation processes.