Soaps are mixtures of sodium or potassium salts derived from fatty acids and alkali solutions in a process called saponification. Each soap molecule is made of a long, non-polar, hydrophobic (repelled by water) hydrocarbon chain (the "tail") capped by a polar, hydrophilic (water-soluble) "salt" head. Because soap molecules have both polar and non-polar properties, they're great emulsifiers, which means they can disperse one liquid into another.

When you wash your dirty hands with soap and water, the tails of the soap molecules are repelled by water and attracted to oils, which attract dirt. The tails cluster together and form structures called micelles, trapping the dirt and oils. The micelles are negatively charged and soluble in water, so they repel each other and remain dispersed in water—and can easily be washed away.

So, yes, soap does indeed get dirty. That's sort of how it gets your hands clean: by latching onto grease, dirt and oil more strongly than your skin does. Of course, when you're using soap, you're washing all those loose, dirt-trapping, dirty soap molecules away, but a bar of soap sitting on the bathroom counter or liquid soap in a bottle can also be contaminated with microorganisms.

This doesn't seem to be much of a problem, though. In the few studies that have been done on the matter, test subjects were given bars of soap laden with E. coli and other bacteria and instructed to wash up. None of the studies found any evidence of bacteria transfer from the soap to the subjects' hands. (It should be noted that two of these studies were conducted by Procter & Gamble and the Dial Corp., though no contradictory evidence has been found.)

Dirty soap can't clean itself, though. A contaminated bar of soap gets cleaned via the same mechanical action that helps clean you up when you wash your hands: good ol' fashioned scrubbing. The friction from rubbing your hands against the soap, as well as the flushing action of running water, removes harmful microorganisms from both your hands and the soap and sends them down the drain.