In the early 20th century, penicillin seemed like the answer to the problem of infection. Today new strains of antibiotic-resistant bacteria are appearing faster than scientists can discover new antibiotics.
Although we still have a lot to learn about how bacteria develop resistance, it seems that one way is through random mutation.
Antibiotics work by attacking tiny, but important parts of bacterial cells. When you take penicillin for strep throat, for example, the penicillin may interact with any of about three different proteins in the bacterial cell walls to prevent the cell from growing. When the cell can't grow, it dies.
Imagine now, that among the millions of bacteria in your infected throat, two or three spontaneous mutations produce bacteria that use slightly altered proteins in their cell walls.
Ordinarily mutations are harmful. But when most of the bacteria are being killed by penicillin, the two or three mutants with their slightly different proteins may be the only ones to survive. And not only will they survive, but with no competition, the antibiotic-resistant bacteria may reproduce fast enough to start a whole new strain of bacteria.
We usually take antibiotics in large doses and continue even after the symptoms are gone in order to wipe out even the few, slightly resistant mutants. If you stop taking the antibiotic too soon, you may be leaving a few mutant, slightly resistant bacteria. If this happens, the original infection could return with a new population of bacteria resistant to the antibiotic you started with.