Skip to main content
Urinary Tract Infection (UTI)

How Do You Get a Urinary Tract Infection, and What Causes It?

Angela Dunn, MD, MPHMandy Armitage, MD
Written by Angela Dunn, MD, MPH | Reviewed by Mandy Armitage, MD
Updated on November 6, 2025

Key takeaways:

  • Urinary tract infections (UTIs) happen when germs from the skin or gut get into your urinary tract. Women are more likely to get UTIs because they have shorter urethras.

  • The most common germ that causes a UTI is the bacteria Escherichia coli (E. coli).

  • Certain health conditions, sexual activity, and holding in urine can increase your risk of getting a UTI.

Having a urinary tract infection (UTI) is a common problem, especially for women. In fact, about 4 in 10 adult women will get a UTI at least once in their lives. If you’ve ever had one, you’ve probably wondered how and why it happens.

A UTI happens when germs get into your urethra (the tube that carries urine out of your body) and travel to your bladder, causing an infection. But why does this happen? And why are women more likely to get a UTI? Here’s what you need to know.

A 3D illustration of the female and male urinary tracts highlighting the kidney, ureter, bladder, and urethra.

What is the most common cause of a UTI?

The most common cause of a UTI is Escherichia coli (E. coli), a bacteria in your gut and poop. But other germs can also cause UTIs when they get into your urinary tract. Most commonly, UTIs are caused by: 

  • Bacteria: Besides E. coli, other bacteria that live on your skin or in your intestines can cause UTIs.

  • Fungi (yeast): Candida is the most common fungus to cause UTIs. It’s the same type of fungus that causes thrush or yeast infections.

  • Viruses: A virus can cause a UTI, but this is very rare. Viral UTIs can occur in people with weakened immune systems, like those with cancer, who are getting cancer treatment, or who have the human immunodeficiency virus (HIV).

How do you get a UTI or bladder infection?

When germs get into your urethra and travel up to your bladder, they can cause an infection. Germs from the gut or rectum can get into your urethra because the openings of the urethra and rectum are so close together. Once these germs are able to stick to the walls of the urethra and bladder, they can multiply and cause an infection.

Certain activities can make it more likely for germs to get into your urethra.

1. Sex

Sex is a common way that bacteria from the skin, anus, or rectum gets into your urethra. This is especially true for women, who tend to get more UTIs than men. Women also have shorter urethras, which means bacteria have a shorter distance to travel to reach the urethral opening and bladder.

2. Using a urinary catheter

A catheter is a tube that goes into your urethra to drain your bladder. People who can’t empty their bladder on their own may need a catheter. If the tube has germs on it, those germs can cause an infection. UTIs caused by using a urinary catheter are some of the most common infections people get in the hospital. The longer a catheter stays in place, the higher the risk of infection.

3. Holding urine

Anything that blocks the flow of urine can cause a UTI. This includes holding in urine too long or not emptying your bladder completely (for example, because of an enlarged prostate). Not emptying your bladder allows bacteria to collect in your bladder and urethra and cause an infection.

What are risk factors for UTIs?

It’s important to be aware of what can make you more likely to get a UTI. There’s a long list of UTI risk factors, including:

  • Dehydration: When you don’t drink enough water, your urine becomes more concentrated and it can irritate your bladder. You also pee less often, giving bacteria more time to grow in your bladder.

  • Kidney or bladder stones: Like holding in your urine, kidney or bladder stones can cause urine to back up. This creates a place for bacteria to grow and cause an infection.

  • A weakened immune system: People with weakened immune systems, like those with HIV or diabetes, can’t fight off infections very well. So UTIs are more likely.

  • Pregnancy: When you’re pregnant, your growing uterus can make it harder for your bladder to empty completely. Pregnancy-related changes in hormones and vaginal bacteria can also increase your risk of getting a UTI.

  • Wiping from back to front: Bacteria from your anus can get into your urethra when wiping from back to front after going to the bathroom. While this theory makes sense, it hasn’t been well studied. But some research shows that people who wipe back to front might have a higher risk of developing UTIs.

  • Use of spermicide: Spermicide, commonly used with condoms or diaphragms, kills sperm. But it can also irritate your vagina and disturb the healthy bacteria there, making UTIs more likely.

  • Changes in estrogen levels: Lower estrogen during and after menopause can increase your risk of UTIs. Experts believe this is due to changes in the soft tissues and bacteria in the vagina.

  • Sexual activity: As mentioned above, having sex can help bacteria get into your urethra. Having new or multiple sex partners increases the risk even more.

GoodRx icon
  • What does a urinary tract infection (UTI) feel like? Learn from real people about what a UTI feels like, how they treated their symptoms, and what they do to help prevent further infections.

  • Quicker UTI recovery: Taking antibiotics as directed is your best bet to treat a UTI, but there are also lots of over-the-counter medications and home remedies. Learn more about how they might help.

  • Wanting to treat your UTI at home? Find out if you can really get rid of a UTI without antibiotics.

Can antibiotics cause a UTI?

No, antibiotics don’t cause UTIs, they treat them. 

But antibiotics can change the balance of healthy microbes in your body (called the “microbiome”). This means that they kill both bad and good bacteria in your body. A drop in healthy bacteria — especially in places like your gut and vagina — creates an environment where harmful microbes can thrive.

Over time, using antibiotics too often can cause antibiotic resistance. This means that future infections won’t respond as well to antibiotics. Antibiotic resistance can be a problem for people who take antibiotics often for UTIs.

Urinary Tract Infection medicationsCompare prices and information on the most popular Urinary Tract Infection medications.
  • Amoxicillin
    Generic Amoxil
    $4.64Lowest price
  • Augmentin
    Amoxicillin/Potassium Clavulanate
    $9.40Lowest price
  • Cephalexin
    Generic Keflet and Keflex and Keftab
    $8.09Lowest price

This doesn’t mean you should never take antibiotics. It just means you should only take them when you need them. And when you do take them, you should finish the entire course, even if you start feeling better before your course is over.

Can stress cause a UTI?

No, stress doesn’t directly cause UTIs, but it can raise your risk of getting one. Stress can affect your health in a few different ways, particularly by affecting your immune system.

Since you need your immune system to be healthy to fight off infections, you might be more likely to get an infection if you’re dealing with high levels of stress.

How can you prevent a UTI?

If you’re prone to UTIs, you might be wondering what you can do to prevent them. Here are a few tips to consider:

  • Don’t hold your urine. Empty your bladder when you feel the need. This makes your bladder a less friendly environment for bacteria to grow and flourish in.

  • Pee right after sex. Flushing your urinary tract after sex may help get rid of germs that enter during sex.

  • Drink water often. Staying hydrated keeps urine flowing through your urinary tract, which helps flush out bacteria.

  • Avoid spermicides. Use condoms or diaphragms without spermicide, or consider another form of birth control. But keep in mind that only condoms can help prevent sexually transmitted infections (STIs).

  • Use vaginal estrogen. Estrogen is key to a healthy vaginal microbiome. Studies suggest that vaginal estrogen can reduce the risk of recurrent UTIs in women after menopause.

  • Eat cranberries or drink cranberry juice. Cranberries have compounds that make it harder for bacteria to stick to the inside of your urinary tract. So, it’s a popular product for UTI prevention. But there’s mixed evidence that it actually works, and it’s not recommended as treatment. That said, it might be worth trying if you can avoid products with added sugar, since sugar may make it less effective.

It’s a good idea to get medical attention if you’re experiencing multiple UTIs. There are different prevention methods and treatments for recurrent UTIs, which is defined as having more than 2 UTIs in a 6-month period.

Frequently asked questions

It’s common to hear or read that you should avoid tight clothing to help prevent a UTI. In theory, this might make sense. But there’s actually very little evidence to support it.

No. Sex increases your risk of getting a UTI. But UTIs aren’t transmitted sexually.

Men can get UTIs for a few reasons. The most common cause in men is decreased urine flow, such as with an enlarged prostate. A weakened immune system, being uncircumcised, or using a urinary catheter can also increase the risk of UTIs in men.

The bottom line

Urinary tract infections (UTIs) happen when germs, like bacteria from the skin or gut, get into your urethra and bladder. Because the urethra and rectum are close together, and the urethra is shorter in women, UTIs are more likely in females. Other factors like sex, hormonal changes, weakened immune systems, kidney stones, and holding in urine, can also increase your risk.

To prevent UTIs, avoid holding your urine and pee after sex. You should also wipe front to back and stay hydrated. If you’re pregnant or going through menopause, speak with a healthcare professional about treatment options.

why trust our exports reliability shield

Why trust our experts?

Angela Dunn, MD, MPH, is a public health physician practicing in Utah, with a focus on serving under-resourced communities.
Alex Eastman, PhD, RN, is a California-based registered nurse and staff medical editor at GoodRx, where he focuses on clinical updates and Latino health.
Mandy Armitage, MD
Reviewed by:
Mandy Armitage, MD
Mandy Armitage, MD, has combined clinical medicine with her passion for education and content development for many years. She served as medical director for the health technology companies HealthLoop (now Get Well) and Doximity.

References

GoodRx Health has strict sourcing policies and relies on primary sources such as medical organizations, governmental agencies, academic institutions, and peer-reviewed scientific journals. Learn more about how we ensure our content is accurate, thorough, and unbiased by reading our editorial guidelines.

Was this page helpful?

Latest articles