Generation of magnetic field during inflation can explain its presence over a wide range of scales in the Universe. In [Sharma et al Phys. Rev. D 96, 083511 (2017)], 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 stochastic common spectrum process 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 B0∼(0.7–1.4)×10−11 G and its coherence length ∼3 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 B0∼(2.1–3.8)×10−10 G and its coherence length ∼90 kpc.