Mass spectrometry is an analytical technique used to measure the mass-to-charge ratio of ions. It provides valuable information about the molecular weight and structure of compounds, making it a powerful tool for analyzing nitrogen and phosphorus compounds, among others, by identifying their elemental composition and molecular structure.