First-principles electronic structure and positron-state calculations for transition-metal carbides and nitrides are performed. Perfect NaCl structures as well as structures with metal or carbon/nitrogen vacancies are considered. The positron affinities and lifetimes are determined. The trends are discussed and the results are compared with recent positron lifetime measurements for group-IV and -V refractory metal carbides. The present analysis suggests, contradictory to an earlier interpretation, that positrons are trapped and annihilated at both carbon and metal vacancies. The concentration of metal vacancies detected by positron annihilation methods is probably very low, below the sensitivity limit of other experimental methods.