Gram staining is a differential staining technique used to classify bacteria into two groups, Gram positive and Gram negative, based on their ability to retain or lose crystal violet stain. The Gram staining procedure involves staining a heat-fixed bacterial smear with crystal violet, iodine, decolorizing with alcohol, and counterstaining with safranin or carbolfuchsin, then examining under a microscope to determine if bacteria appear purple or red, indicating Gram positive or Gram negative respectively.