We study the magnetocrystalline anisotropy (MCA) energy of Fe16-nXnN2 (n = 1, 2), where X = Ti, V, Cr, Mn, Co, Ni, Cu. To understand the microscopic origin and basic mechanism controlling the MCA energy of Fe16-nXnN2, we first examined the behavior of the MCA energy of Fe16N2, focusing on the spin-orbit coupling (SOC), and compared the behavior with other alloy systems (FeCo, FePt and CoPt) with L1(0) structure. We find that whereas the MCA energy of FeCo is determined by the spin-conserved terms of the SOC energy, the MCA energy of Fe16N2 is determined by mutual competition between spin-conserved and spin-flip terms. We then studied the effect of the transition element X on the phase stability and MCA of Fe16-nXnN2. The MCA energy and cohesive energy are calculated to determine the most stable configuration for each choice of X and n, and compared with those of Fe16N2. For X = V and Cu, both the MCA and phase stability improved noticeably. For X = Co, the MCA energy improves, but Fe16-nConN2 is less stable than Fe16N2. The microscopic mechanism underlying the MCA energy enhancement due to X = V, Cu and Co in Fe16-nXnN2 was studied by examining the data for spin- and site-resolved projected density of states (PDOS), as well as each spin-conserved and spin-flip terms contributing to the SOC energy.