The elastic properties and electronic properties of MxNy (M = Ti, Zr) TiN, Ti2N, Zr3N4, ZrN with different structures have been investigated using density functional theory. Through the calculation of the elastic constants, it was found that all of these structures meet the mechanical stability except for ZrN with space group P63mc. Their mechanical properties are studied by a comparison of various parameters. The stiffness of TiN is larger than that of ZrN with space group Fm3¯m. Ti2N’s stiffness with space group I41/amdz is larger than Ti2N with space group P42/mnm. Zr3N4’s stiffness with space group Pnam is largest in three structures of Zr3N4. TiN, Ti2N and ZrN are non-central force, Zr3N4 is central force. TiN and ZrN with space group Fm3¯m are brittle, and TiN is brittler than ZrN with space group Fm3¯m. The two kinds of Ti2N are brittle and Ti2N with space group I41/amdz is larger. Three structures of Zr3N4 are tough and Zr3N4 with space group I4¯3d is the toughest. Meanwhile, the electronic properties of TiN, Ti2N, Zr3N4 and ZrN were calculated, possible superconducting properties of the studied materials were predicted.