When companies develop antibacterial drugs, the Gram stain still draws an essential dividing line for judging the effectiveness of each type of compound. This is because the test reveals the makeup of the cell wall and so the penetrability of the wall by various drug types. Some antibacterials act against gram-positive bacteria and others against gram-negative, while those that act against both types are called wide-spectrum. A variation on the Gram technique gives a division between bacteria that are "acid-fast" or not.

Danish physician Hans Christian Joachim Gram was doing postdoctoral study at the University of Berlin in 1884 when he devised his differential staining of bacteria. In the first step, he dried a fluid smear on a glass slide over a burner flame and poured Gentian violet solution over it. After a water wash, he added potassium triiodide solution, which acted as a mordant to fix the dye if possible. Then he poured ethanol over the slide to wash away the dye. Bacteria cells that remained purple were positive, and those that did not retain the color were negative.
A few years later, pathologist Carl Weigert, director of the Senckenberg Foundation in Frankfurt, Germany, added a final step of staining with safranine. Today, bacteria are judged gram-negative if they retain the red color of safranine but not the first purple color of Gentian violet.
Gram-positive bacteria have thick cell walls of cross-linked polysaccharide that take Gentian violet well. Gram-negative bacteria have thin polysaccharide cell walls overlaid by lipid layers that resist staining by Gentian violet but that can be stained by safranine. In the acid-fast bacteria that cause tuberculosis and leprosy, the lipid layers are so waxy that only an etching stain like carbol fuschin can color them, but once colored, even ethanolic hydrogen chloride cannot decolorize them. Non-acid-fast bacteria take up a methylene blue secondary stain as a confirmation test.