A mass spectrometer operates in three main stages: ionization, mass analysis, and detection. During ionization, the sample is ionized to produce charged particles. These ions are then separated based on their mass-to-charge ratio using a mass analyzer, and finally, they are detected and quantified. The resulting spectrum provides information about the molecular weight and structure of the sample components.