Gram staining stains bacteria according to the chemical and physical properties of their cell walls. It stains peptidoglycan, a thick layer in gram-positive bacteria. So, gram-positive bacteria are coloured by the crystal violet dye. A counterstain (commonly safranin or fuchsin) added after the crystal violet gives all gram-negative bacteria a red or pink colour.
The Gram stain is almost always the first step in the identification of a bacterial organism. However, not all bacteria can be classified by this technique. They are called 'gram-variable' or 'gram-indeterminate'.