Gram stain is an essential staining technique used to detect the presence of bacteria in a sample and differentiate between gram-positive and gram-negative bacteria based on the reaction between a primary stain and the peptidoglycan present in the cell walls of some bacteria.
Gram staining is comprised of three main process. The first process involves staining the sample with crystal violet. The second involves decolorizing the sample. The third involves counterstaining usually with safranin. In the first process, gram positive bacteria, which have a thicker peptidoglycan layer in the cell membrane, absorb and retain the crystal violet stain during the decolorization process. Gram negative bacteria, on the other hand, are unable to retain the crystal violet stain during decolorization.  Instead, gram negative bacteria are stained by safranin in the final gram staining process.
When viewed under a microscope after the completion of gram staining, gram positive bacteria appear purple or purple-brown in color while gram negative bacteria appear pink in color.