An antibiotic stops working when the bacteria it treats become resistant. Resistance grows from two things: rare chance changes in bacterial DNA, and the antibiotic itself picking out the bacteria that carry them.
A bacterium multiplies by splitting in two, and each time it copies its DNA. The copying is very accurate, with fewer than one wrong base in every billion, and bacteria multiply fast: in a warm, rich broth, the gut bacterium Escherichia coli can split every 20 minutes. An infection can hold billions of bacteria, so new changes turn up all the time. Most do nothing, or harm the bacterium. Now and then one alters a protein so that an antibiotic fits it less well.
The antibiotic picks the survivors
Give an antibiotic and the bacteria it fits are killed or stopped. The rare resistant ones carry on, multiply and take their place. Their change was there before the antibiotic arrived, and the antibiotic picks out the bacteria that carry it. This is natural selection, the process Charles Darwin described in 1859, running in hours. It is the bacteria that become resistant, and the person taking the medicine stays the same.
Passing genes on
Bacteria also share genes. Many resistance genes sit on plasmids, small rings of DNA kept apart from the bacterium's main DNA. A bacterium can copy a plasmid and pass the copy to a neighbour through a thin tube between the two cells, even to a different kind of bacterium. One plasmid can carry genes against several antibiotics at once, so a single swap can make a bacterium resistant to all of them.