Dynamical extra dimensions break the conformal invariance of Maxwell's equations in four dimensions. A higher dimensional background with $n$ contracting extra dimensions and four expanding dimensions is matched to an effectively four dimensional standard radiation dominated universe. The resulting spectrum for the magnetic field is calculated taking into account also the momenta along the extra dimensions. Imposing constraints from observations an upper limit on the strength of magnetic seed fields is found. Depending on the number of extra dimensions, cosmologically interesting magnetic fields can be created.