We investigate the atomic structure of various N-H complexes in GaAs and GaAs1-xNx alloys through first-principles pseudopotential calculations within the local-density-functional approximation. For GaAs with low H concentrations, we suggest that nitrogen forms a N-H(BC) complex, where H is positioned at a bond-center site between a substitutional N and one of the neighboring Ga atoms. For very high H concentrations, an optically inactive N-H-2*(BC-ABN) complex, which corresponds to a configuration of H-2(*) in the vicinity of N, is suggested to be an energetically favorable structure. These atomic models explain many experimental features observed in GaAs and GaAs1-xNx alloys, which contain both N and H.