Using a recently developed first-principles approach, we show that the variation in the superconducting behavior of group IVb and Vb transition metal carbides is associated with a significant nesting of the Fermi surfaces in group Vb compounds, while their phonon anomalies and density of states at the Fermi level play a minor role. The superconducting pairing arises from the coupling of metal $d$ states to acoustic phonons, and is therefore at variance with the interaction leading to the exceptional mechanical hardness where carbon $p$ states play a substantial role. We provide insight into how to optimize the transition temperature by varying the Fermi surface properties through substitutional doping.