Specificity in MS is achieved through the precise measurement of the mass-to-charge ratio of ions. By using techniques like tandem mass spectrometry (MS/MS), which involves multiple stages of mass analysis, MS can distinguish between compounds with similar masses, reducing the likelihood of false positives.