  Generation of magnetic field during inflation can explain its presence over a
wide range of scales in the Universe. In Ref.\cite{sharma2017}, we proposed a
model to generate these fields during inflation. These fields have nonzero
anisotropic stress which lead to the generation of a stochastic background of
gravitational waves (GW) in the early universe. Here we show that for a
scenario of magnetogenesis where reheating takes place around QCD epoch, this
stochastic GW background lies in the $95\%$ confidence region of the GW signal
probed by NANOGrav collaboration. This is the case when the generated
electromagnetic field (EM) energy density is $3-10\%$ of the background energy
density at the end of reheating. For this case, the values of magnetic field
strength $B_0 \sim (3.8-6.9) \times 10^{-11}$G and its coherence length $\sim
30$ kpc at the present epoch. These values are for the models in which EM
fields are of nonhelical nature. For the helical nature of the fields, these
values are $B_0 \sim (1.1-1.9) \times 10^{-9}$G and its coherence length $\sim
0.8$ Mpc.
