The regular twinning in ceramics and metals below the temperature of a ferroelastic or ferroelectric structural phase transition is a result of energy minimization. Here homogeneous elastic energy is reduced at the expense of twin wall energy. The twin density depends on the gram size g; under homogeneous stress the total elastic energy of a grain increases ∝g3. Any kind of twin wall, however, increases ∝g2. Below the intersection of these two curves, stress reduction by twinning cannot lower the total energy. Thus there is a critical grain size below which twinning should not occur. Above this limit the width of the twin lamellae increases ∝g1/2. The shape of the grain then adjusts to the surroundings in two dimensions only. Above another larger critical grain size more complex interfaces with higher surface energy are created, which allow stress relief in the third dimension. A semi-quantitative model is developed with the example of BaTiO3 ceramic, of which the domain patterns are well known. It is representative for many ceramics. The high Tc superconductor YBa2Cu3O7-δ also twins according to the same law. For three-dimensional adjustment here a proper interface is missing. © 1990 Chapman and Hall Ltd.