N-doped ZnO nanowires are synthesized at a relatively low growth temperature of 500 degrees C by directly heating zinc powder using NH(3) as the dopant. The incorporation of N into the ZnO nanowires is experimentally confirmed by x-ray photoelectron spectroscopy, Raman spectra and photoluminescence measurements. By combining post annealing experiments after growth with first-principles calculations, the detailed migration mechanism of N and compensation mechanism in N-doped ZnO nanowires are systematically studied. The larger aspect ratio of nanowires favors the formation of oxygen vacancy and out-diffusion of substitutional N (N(O)), making N(O) in ZnO nanowires always compensated by hydrogen interstitials (H(I)). Our results can help to explain the challenge in getting p-type ZnO and shed new light on the possible realization of p-type doping of ZnO in the future.