The study of microbial communities often leads to arguments for the evolution of cooperation due to group benefits. However, multilevel selection models caution against the uncritical assumption that group benefits will lead to the evolution of cooperation. We analyze a microbial social trait to precisely define the conditions favoring cooperation. We combine the multilevel partition of the Price equation with a laboratory model system: swarming in Pseudomonas aeruginosa. We parameterize a population dynamics model using competition experiments where we manipulate expression, and therefore the cost-to-benefit ratio of swarming cooperation. Our analysis shows that multilevel selection can favor costly swarming cooperation because it causes population expansion. However, due to high costs and diminishing returns constitutive cooperation can only be favored by natural selection when relatedness is high. Regulated expression of cooperative genes is a more robust strategy because it provides the benefits of swarming expansion without the high cost or the diminishing returns. Our analysis supports the key prediction that strong group selection does not necessarily mean that microbial cooperation will always emerge.