How do bacteria develop resistance against the antibiotics we took for years?

Genetics. Bacteria adapt to antibiotics for survival. Small genetic mutations develop that give a bacterium a survival advantage. It makes copies of this genetic anamoly (on a separate genetic fragment called a plasmid) that then is passed on to other bacteria of the same species. Over time, succeeding generations have this advantage and since they survived, they are now resistant.