Resistance can develop through several mechanisms. Bacteria can mutate spontaneously, leading to changes in their genetic code that confer resistance. Alternatively, they can acquire resistance genes from other bacteria via horizontal gene transfer. This can occur through transformation (uptake of DNA from the environment), transduction (transfer by viruses), or conjugation (transfer via direct contact).