A generic formula for the Hausdorff and box counting dimensions of self-affine fractals is presented. Extensions to the non-linear situation and to repellers in discrete dynamical systems are discussed.