What is a mass spectrometer?

Scientists routinely analyse samples to find out what chemicals they contain; this often involves a mass spectrometer. But what is a mass spectrometer, and how do they work?

Media Images: 
Close-up of using a mass spectrometer. [Gordon Brailsford]