In this study, C/N-containing Fe3O4 oxide films over an inner nitride layer were fabricated on 45# steel by oxynitriding to improve corrosion resistance in chloride-containing environments. The films exhibited a dense polyhedral structure, with nanoscale Fe3O4 precipitates at grain boundaries. Nitrogen and carbon were uniformly distributed within the oxide grains, inducing lattice expansion and modifying the Fe-O bonding environment. First-principles calculations based on C/N substitution models suggested that C/N incorporation may increase the unit cell volume, strengthen lattice bonding, and enhance the theoretical hardness of Fe3O4. The optimally doped films exhibited outstanding corrosion resistance, with a corrosion potential of 0.115 VSCE, a corrosion current density of 3.16 × 10−10 A/cm2 in 3.5 wt.% NaCl solution, and a corrosion-free lifetime of up to 3600 h in neutral salt spray testing. This superior performance is attributed to the synergistic effects of the compact single-phase magnetite layer, grain boundary precipitates, and modified electronic structure, which collectively inhibit chloride ingress and convert localized electrochemical attack into uniform corrosion. The experimental results are consistent with first-principles predictions, which clarified the mechanism of nitrogen doping in material corrosion protection from a mechanistic perspective.