  We constrain a stochastic background of primordial magnetic field (PMF) by
its contribution to the angular power spectrum of cosmic microwave background
anisotropies. We parametrize such stochastic background by a power-law spectrum
with index $n_B$ and by its Gaussian smoothed amplitude $B_\lambda$ on a
comoving length $\lambda$. We give an approximation for the spectra of the
relevant correlators of the energy-momentum of the stochastic background of PMF
for any $n_B$. By using the WMAP 7 year data in combination with ACBAR, BICEP
and QUAD we obtain the constraint $B_{1 {\rm Mpc}} < 5.0$ nG at 95% confidence
level for a stochastic background of non-helical PMF. We discuss the relative
importance of the scalar and vector contribution to CMB anisotropies in
obtaining these constraints. We then forecast {\sc Planck} capabilities in
constraining $B_{1 {\rm Mpc}}$.
