A mass spectrometer is an analytical instrument used to measure the masses and relative abundances of atoms or molecules in samples. It works by ionizing the sample, separating ions based on their mass-to-charge ratio, and detecting them with sensors.