Here's why:
* Gram-positive bacteria have a thick peptidoglycan layer in their cell wall. This layer traps the crystal violet dye used in the staining process, making the bacteria appear purple.
* Gram-negative bacteria have a thinner peptidoglycan layer and an outer membrane. The thinner peptidoglycan layer doesn't retain the crystal violet dye as well, so it's washed away during the decolorization step. However, these bacteria then take up the counterstain (safranin), which makes them appear pink.
Therefore, the gram staining technique differentiates bacteria based on their cell wall structure, specifically the thickness of the peptidoglycan layer.