The structural and electronic properties of the recently synthesized ternary crystal Si2CN4 are investigated by means of density functional calculations, in comparison with pure and C-defective β Si3N4. The theoretical equilibrium lattice parameters of Si2CN4 well agree with experimental results, and the optimized atomic positions refine those extracted from diffraction data, permitting a precise description of the atomic structure. According to our calculations, the enthalpy of the reaction of dissociation of crystalline Si2CN4 into silicon nitride, silicon carbide and molecular nitrogen is positive, suggesting that the novel compound should be relatively stable at normal conditions, consistently with the experimental observation. The analysis of CSi:β Si3N4, at low defect concentrations, either for scattered defect distributions or neighboring CSi, reveals the presence of many dilated bonds. The microscopic stress is mainly responsible for the lower stability of carbon defective silicon nitride with respect to Si2CN4.