When a course of antibiotics is taken, non-resistant bacteria should be killed. However, genetic mutations can lead to certain individuals becoming resistant to a particular antibiotic. The mutated gene that codes for resistance to the antibiotic can then be passed on through either vertical or horizontal gene transfer.
Vertical gene transfer is the transmission of DNA from parent to offspring. When a resistant bacterium divides and replicates, it will pass on its gene for antibiotic resistance.
Horizontal gene transfer is the movement of DNA between two organisms, and is a process that can even occur between distantly related species of bacteria. On cell-to-cell contact, a bacterium can send genetic material to another bacterium through its pili. This type of horizontal gene transmission is known as conjugation.
The antibiotic resistant bacteria have a genetic advantage, as they are able to survive antibiotic contact. They are therefore more likely to live and replicate, so the gene for antibiotic resistance is likely to become prevalent within the population.