Stars are categorized into seven stellar classes based on their surface temperature, as explained by the HyperPhysics Department at Georgia State University. Each spectral class has its own letter and set of characteristics.
The hottest stars are categorized as "O" stars, and have a temperature upwards of 41,000 Kelvin. Their intrinsic color is blue, as is the next stellar class, "B." These are followed by A, F, G, K and M, and their respective colors are blue-white, white, yellow, orange and red. Surface temperature decreases for each class, with "M" stars being the coolest, at 3,850 Kelvin.
The Astronomy Department at the University of Washington explains that this classification is determined by spectroscopy, which is the analysis of observable light. Spectroscopy examines all wavelengths of the electromagnetic spectrum to obtain a great deal of information about the light source, such as distance, temperature and composition. The outer surface of a star produces absorption lines on a spectrograph when the density of a certain gas is too low to show up on the spectrum. Since different temperatures ionize different gases, the particular spectral lines that show up allow for an accurate star temperature estimate. An early stellar classification scheme was developed using this science by an astronomer named Annie Jump Cannon at Harvard College University near the end of the 19th century. Over time it was refined to become the standard system used by scientists today.