The elastic properties of the B1-structured transition-metal nitrides and their carbide counterparts are studied using the ab initio density functional perturbation theory. The linear response results of elastic constants are in excellent agreement with those obtained from numerical derivative methods, and are also consistent with measured data. We find the following trends: (1) Bulk moduli B and tetragonal shear moduli G ′ = (C11 − C12)/2, increase and lattice constants a0 decrease rightward or downward on the Periodic Table for the metal component or if C is replaced by N; (2) The inequality B > G ′ > G > 0 holds for G = C44; (3) G depends strongly on the number of valence electrons per unit cell (ZV ). From the fitted curve of G as a function of ZV , we can predict that MoN is unstable in B1 structure, and transition-metal carbonitrides (e.g. ZrCxN1−x) and di-transition-metal carbides (e.g. HfxTa1−xC) have maximum G at ZV ≈ 8.3.PACS numbers: 62.20. Dc, 71.15.Mb, 74.70.Ad Elasticity describes the response of a crystal under external strain and provides key information of the bonding strength between nearest-neighbor atoms. The information obtained from accurate calculation of elasticity is essential for understanding the macroscopic mechanical properties of solids and for the design of hard materials. Nowadays it is possible to calculate elasticity using ab initio quantum-mechanical techniques, and ab initio calculations have proven to be very powerful in not only providing accurate elastic constants or moduli in good agreement with measurements [1] but also predicting elasticity at extreme conditions of high temperatures and high pressures [2,3], which are not easily accessible to experiment but have wide applications in the fields ranging from solid-state physics to seismology. Most previous ab initio calculations of elasticity used finite strain methods within the framework of the density-functional theory (DFT). The development of density-functional perturbation theory (DFPT) makes it possible now to obtain elastic constants directly and more accurately [4,5].Transition-metal nitrides and carbides in the rocksalt (B 1 ) structure are widely used for cutting tools, magnetic storage devices, generators and maglev trains due to their high hardness, high melting points and oxidation resistance [6]. These excellent properties are associated with their unusual electronic bonding. The relatively high superconducting transition temperature in some of these compounds, reaching nearly 18 K in NbC 1−x N x [8], indicates a strong electron-phonon interaction. Many theoretical studies of their electronic structure [7,9,10,11,12,13] have revealed an unusual mixture of covalent, metallic, and ionic contributions to bonding which must ultimately lie at the root of their unusual properties. Specifically, it was found [11] that the hardness enhancement of these materials can be understood on a fundamental level in terms of their electronic band structures. But the general trends of elasticity and electronic structure amon...