In this work, first of all, polypyrrole (PPy) nanowires have been successfully prepared using template synthesis technique at room temperature by chemical polymerisation of pyrrole within the pores of anodic alumina template. Secondly, the effect of 4 h annealing on morphological, optical and ammonia gas sensing device properties has been studied at 200 °C and 300 °C. The characterization of unanealed and annealed samples was done by using scanning electron microscopy (SEM), X-ray diffraction (XRD), fourier transform infrared spectroscopy (FTIR) and time resolved photoluminescence. IV measurements are done for studying gas sensing device. The SEM confirms the flexible wire-like morphology of unannealed and annealed nanowires whereas XRD investigation shows the amorphous nature of unannealed and annealed nanowires. Characteristic peaks of FTIR confirm the formation of PPy nanowires synthesized at room temperature and transition from polypyrrole to carbon nitride nanowires after annealing PPy nanowires at 200 and 300 °C. The transition from PPy to CNx nanowires after annealing is proved by the characteristic FTIR peaks corresponding to C=C and C=N bond and the time resolved photoluminescence spectra recorded at different wavelengths corresponding to polypyrrole and carbon nitride well known transitions. I–V studies of nanowires show the increase in sensitivity of annealed nanowires towards NH3 at about thousand times than that of unannealed nanowires.