Trimethoprim-sulfamethoxazole is used to treat a variety of bacterial infections, from ear infections, urinary tract infections, and traveler’s diarrhea to more serious infections like pneumonia. If you have a bacterial infection, your doctor will work with you to determine whether trimethoprim-sulfamethoxazole is an appropriate course of treatment.