Previous work has demonstrated that the radio frequency surface resistance of niobium resonators is dramatically reduced when nitrogen impurities are dissolved as interstitial in the material. This effect is attributed to the lowering of the Mattis-Bardeen surface resistance with increasing accelerating field; however, the microscopic origin of this phenomenon is poorly understood. Meanwhile, an enhancement of the sensitivity to trapped magnetic field is typically observed for such cavities. In this paper, we conduct a systematic study on these different components contributing to the total surface resistance as a function of different levels of dissolved nitrogen, in comparison with standard surface treatments for niobium resonators. Adding these results together, we are able to show which is the optimum surface treatment that maximizes the Q-factor of superconducting niobium resonators as a function of expected trapped magnetic field in the cavity walls. These results also provide insights on the physics behind the change in the field dependence of the Mattis-Bardeen surface resistance, and of the trapped magnetic vortex induced losses in superconducting niobium resonators.