Background: Extensive use of cotrimoxazole has been associated with increasing level of Escherichia coli resistance.Objectives: In the current study, we focused on assessing the prevalence of E. coli resistance to cotrimoxazole and frequency of its associated genes.Materials and Methods: One-hundred and forty-four E. coli isolates were identified during March 2007 to April 2012 at Ilam hospitals and Milad (Tehran) hospital. Antibiotic susceptibility for screening of resistance isolates was done by the Kirby-Bauer method. The sul1, sul2, sul3, dfrA1, dfrA5, int1, blaTEM, blaSHV and CTX-M genes were detected by polymerase chain reaction (PCR) amplification. Plasmid curing was done for identifying correlations between resistance genes and plasmids.Results: Amongst the 144 E. coli isolates, seventy-two (50%) Extended Spectrum Beta Lactamase (esbl) -producing and seventy-two (50%) non-esbl-producing E. coli isolates were identified; eighty-seven isolates (60.41%) were resistant to cotrimoxazole. Frequencies of sul1, sul2 and sul3, were 81% (116 isolates), 67% (96 isolates) and 2.29% (three isolates), respectively. Furthermore, 50.57% (72 isolates) had sul1 and sul2, 2.29% (3 isolates) contained sul2 and sul3, and 2.29% (three isolates) contained sul1, sul2 and sul3 genes, simultaneously. Thirty-four (39.1%) of the isolates had the dfrA1 gene. Five (5.7%) of the isolates had the dfrA5 gene. Sixty-eight (78.2%) strains contained the int1 gene. Furthermore, dfrA1 and dfrA5 were present in three (3.4%) of the isolates. The results showed that of the esbl-producing isolates, 85.2% (n=122), 53.2% (n=76) and 26.1% (n=37) were blaTEM, blaSHV and CTX-M harboring isolates, respectively.Conclusions: Our study indicated a high frequency of cotrimoxazole resistance gene in E. coli isolates from Ilam and Tehran (Milad) hospitals, and sul genes had a major role in cotrimoxazole resistance of these isolates.