Starting from Nb2O5, NaN3 and different metallic reductants such as magnesium or aluminum, cubic NbN and hexagonal NaNbN2 were selectively synthesized in a stainless steel autoclave at 400-700 degrees C. When magnesium was used as a metallic reductant, NbN can be synthesized at 400 degrees C for 10 h. If the metallic reductant was replaced by aluminum, NaNbN2 was obtained at 700 degrees C for 40 h. The structures and morphologies of the samples were derived from X-ray powder diffraction (XRD), transmission electron microscopy (TEM) and field emission-scanning electron microscopy (FE-SEM). FE-SEM images showed that the NbN sample consisted of particles with an average size of about 100 nm, and the NaNbN2 sample is composed of with an average size of 500 nm. Furthermore, the electric resistivity of the obtained samples reveals the obtained NbN sample is a superconductor with transition temperature of 17 K, and the obtained NaNbN2 sample can be classified as a semiconductor.