By analysing cell shape and size of the bacterium Bacillus subtilis under nutrient perturbations, protein depletion, and antibiotic treatments we find that cell geometry is extremely robust, reflected in a well-conserved scaling relation between surface area (S) and volume (V), S~Vγ, with γ=0.85. We develop a molecular model supported by single-cell simulations to predict that the surface-to-volume scaling exponent γ is regulated by nutrient-dependent production of metabolic enzymes that act as cell division inhibitors in bacteria. Using theory that is supported by experimental data, we predict the modes of cell shape transformations in different bacterial species and propose a mechanism of cell shape adaptation to different nutrient perturbations. For organisms with high surface-to-volume scaling exponent γ, such as B. subtilis, cell width is not sensitive to growth rate changes, whereas organisms with low γ, such as A. baumannii, cell shape adapts readily to growth rate changes.