The site preference of N atom for R2Fe14BNx (R= Pr, Nd) and the interstitial nitrogen effect on the magnetic properties have been studied by the first-principles method. It was found that the nitrogen is more likely to occupy the 4e site for Pr2Fe14BNx compound, while 4f site for Nd2Fe14BNx. When N atoms entering some specific crystal sites (such as 2a and 4f), the total magnetic moments of these compounds are not reduced, but slightly increased. Although the doping of N may reduce the total magnetic moments of some R2Fe14B compounds in the cases of optimal occupancy, the volumetric effect caused by N doping can still change the electron density distributions of Fe near the Fermi level, improving the magnetic ordering temperature of such compounds.