Urinary tract infections can be caused by bacteria migrating through the urethra or present inside the body, e.g. in the bowel; in adults, most infections are due to Escherichia Coli (normally present in the colon).
Women are generally more vulnerable, since their urethra is shorter than in men and closer to anus and vagina, areas normally populated by bacteria, making their colonization of urinary tract easier.