A spectrometer ( /spɛkˈtrɒmɪtər/) is a scientific instrument used to separate and measure spectral components of a physical phenomenon. Spectrometer is a broad term often used to describe instruments that measure a continuous variable of a phenomenon where the spectral components are somehow mixed. In visible light a spectrometer can separate white light and measure individual narrow bands of color, called a spectrum. A mass spectrometer measures the spectrum of the masses of the atoms or molecules present in a gas. The first spectrometers were used to split light into an array of separate colors. Spectrometers were developed in early studies of physics, astronomy, and chemistry. The capability of spectroscopy to determine chemical composition drove its advancement and continues to be one of its primary uses. Spectrometers are used in astronomy to analyze the chemical composition of stars and planets, and spectrometers gather data on the origin of the universe.
Examples of spectrometers are devices that separate particles, atoms, and molecules by their mass, momentum, or energy. These types of spectrometers are used in chemical analysis and particle physics.
Optical spectrometers (often simply called "spectrometers"), in particular, show the intensity of light as a function of wavelength or of frequency. The different wavelengths of light are separated by refraction in a prism or by diffraction by a diffraction grating. Ultraviolet–visible spectroscopy is an example.
These spectrometers utilize the phenomenon of optical dispersion. The light from a source can consist of a continuous spectrum, an emission spectrum (bright lines), or an absorption spectrum (dark lines). Because each element leaves its spectral signature in the pattern of lines observed, a spectral analysis can reveal the composition of the object being analyzed. 
A spectrometer that is calibrated for measurement of the incident optical power is called a spectroradiometer. 
Optical emission spectrometers (often called "OES or spark discharge spectrometers"), is used to evaluate metals to determine the chemical composition with very high accuracy. A spark is applied through a high voltage on the surface which vaporizes particles into a plasma. The particles and ions then emit radiation that is measured by detectors (photomultiplier tubes) at different characteristic wavelengths.
Some forms of spectroscopy involve analysis of electron energy rather than photon energy. X-ray photoelectron spectroscopy is an example.
A mass spectrometer is an analytical instrument that is used to identify the amount and type of chemicals present in a sample by measuring the mass-to-charge ratio and abundance of gas-phase ions. 
The energy spectrum of particles of known mass can also be measured by determining the time of flight between two detectors (and hence, the velocity) in a time-of-flight spectrometer. Alternatively, if the velocity is known, masses can be determined in a time-of-flight mass spectrometer.
When a fast charged particle (charge q, mass m) enters a constant magnetic field B at right angles, it is deflected into a circular path of radius r, due to the Lorentz force. The momentum p of the particle is then given by
where m and v are mass and velocity of the particle. The focusing principle of the oldest and simplest magnetic spectrometer, the semicircular spectrometer,  invented by J. K. Danisz, is shown on the left. A constant magnetic field is perpendicular to the page. Charged particles of momentum p that pass the slit are deflected into circular paths of radius r = p/qB. It turns out that they all hit the horizontal line at nearly the same place, the focus; here a particle counter should be placed. Varying B, this makes possible to measure the energy spectrum of alpha particles in an alpha particle spectrometer, of beta particles in a beta particle spectrometer,  of particles (e.g., fast ions) in a particle spectrometer, or to measure the relative content of the various masses in a mass spectrometer.
Since Danysz' time, many types of magnetic spectrometers more complicated than the semicircular type have been devised. 
Generally, the resolution of an instrument tells us how well two close-lying energies (or wavelengths, or frequencies, or masses) can be resolved. Generally, for an instrument with mechanical slits, higher resolution will mean lower intensity.