Abstract The ferromagnetic (FM)/MgO structure multilayers with perpendicular magnetic anisotropy (PMA) play a crucial role in magnetic random-access memory. It is essential to explore the methods for modulating magnetic anisotropy and to clarify the underlying mechanisms. We study the regulation of the magnetic anisotropy with nitrogen (N) doping concentration (CN) in two samples: Ta/CoFe(N)/MgO/Ta (S1) and Ta/MgO/CoFe(N)/Ta (S2) with different deposition sequences. The S1 sample exhibits in-plane magnetic anisotropy (IMA) without N doping. And the sample presents PMA when CN = 15%. The S2 sample shows weak PMA without N doping, and the sample converts to IMA when CN = 15%. X-ray photoelectron spectroscopy is performed to evaluate the oxidation level of Fe at the CoFe/MgO interface by the peak area ratio of Fe oxide to Fe (ϵ). It is believed that excessively high and low ϵ values correspond to over-oxidation and under-oxidation of Fe, respectively. For films deposited in different sequences, both over-oxidation and under-oxidation lead to IMA, while moderate oxidation facilitates the formation of PMA. The microstructure analysis reveals that the N doping does not affect the crystallization of the films, indicating that magnetocrystalline anisotropy has a minor influence on the changes of K eff.