Mechanical resonators with high quality factors are widely used in precision experiments, ranging from gravitational wave detection and force sensing to quantum optomechanics. Beams and membranes are well known to exhibit flexural modes with enhanced quality factors when subjected to tensile stress. The mechanism for this enhancement has been a subject of debate, but is typically attributed to elastic energy being "diluted" by a lossless potential. Here we clarify the origin of the lossless potential to be the combination of tension and geometric nonlinearity of strain. We present a general theory of dissipation dilution that is applicable to arbitrary resonator geometries and discuss why this effect is particularly strong for flexural modes of nanomechanical structures with high aspect ratios. Applying the theory to a nonuniform doubly clamped beam, we show analytically how dissipation dilution can be enhanced by modifying the beam shape to implement "soft clamping," thin clamping, and geometric strain engineering, and derive the ultimate limit for dissipation dilution.