If you've ever had a urinary tract infection, then you know the agony of that terrible burning feeling and relentless need to pee—and you'd probably do anything to avoid getting another. 

According to the National Kidney Foundation, 1 in 5 women experiences a UTI at some point in her life. And while men can get them, too (UTIs are the second most common infection), women are much more likely to contract one, says the National Institute of Diabetes and Digestive and Kidney Diseases. That's because we have a shorter urethra, which makes it all too easy for UTI-causing bacteria to pass through it and invade the bladder. No fair.

"Our urinary system is designed to keep out bacteria; however, these defenses can fail," said Dr. Kelly M. Kasper,  an ob-gyn at Indiana University Health. "When that happens, bacteria can grow and multiply and cause infections." (Heal your whole body—and lose serious weight—with Rodale's 12-day liver detox for total body health!)

Here are 8 of the most common reasons those defenses fail—and a handful of helpful tips for prevention.

Sex

We know,  huge bummer. Many women get UTIs after doing the deed because the motion of sex can transfer bacteria from the bowel or vaginal cavity into the urethra. To lower your risk of getting a UTI, pee within 30 minutes of having sex, said Dr. Lisa N. Hawes,  a general urologist in Fulton, Maryland, and a physician spokesperson for the American Urological Association. And ignore the often-shared advice that both partners should wash their genitals immediately before and after sex. "This actually changes bacterial flora and will increase UTI risks," Hawes says. (Ugh, another yeast infection? Here are 9 Highly Effective Solutions For Yeast Infections that really work.)

Constipation

You might be able to blame your poop (or lack thereof) for your UTI. Being constipated makes it difficult to empty your bladder all the way, which means trapped bacteria have lots of time to grow and cause infection, says Hawes. (Here's how to never be constipated again.) On the flip side, diarrhea or fecal incontinence can also increase your risk of getting a UTI, because bacteria from loose stool can easily make its way into your vagina and urethra. A tried-and-true tip: Wipe from front to back whenever you use the bathroom, but be especially careful to do so after a bowel movement. (See what else your poop says about you.)

Uncontrolled diabetes

"When blood sugar is high, the excess sugar is removed through the urine," Hawes said. "This makes a favorable environment for bacterial overgrowth" and a potentially unfavorable situation for you. You may have heard the myth that eating too much sugar can cause UTIs, even if you don't have diabetes, but Hawes assures us that's not true. Unless you have diabetes, your sweet tooth isn't the culprit.

Holding it

If you have to go, go! "Holding our urine for 6 hours or more may make UTIs more common, as bacteria that does get into the bladder has lots of time to overgrow between voids," Hawes said. While traveling, for example, it may seem like a good idea to hold tight and keep driving until the next rest area, but do yourself a favor and stop—the extra miles aren't worth the risk of infection. (Here’s what the color of your pee says about your health.)

Dehydration

Drinking plenty of water not only quenches your thirst, but it also wards off UTIs during hot summer months, when many of us don't hydrate enough. "We should always try to drink at least half our body weight in ounces," said Stephanie Seitz, ND, a physician at the Southwest College of Naturopathic Medicine. "When we drink plenty of water, we help flush out bacteria that can cause UTIs."

Birth control

If you switch birth control, the resulting hormone shift could lead to a change in normal bacteria in your vagina, which could up the odds of a UTI, Hawes said. Use of diaphragms and spermicides can also increase your chances of developing one, Kasper adds.

Feminine products

"Dirty pads and tampons are a place where bacteria can grow very easily," said Dr. Ehsan Ali, a primary care physician in Beverly Hills, California. So change them frequently to prevent infections while on your period. Likewise, Dr. Alyssa Dweck, MS, an ob-gyn in Westchester County, New York, says to choose your underwear wisely: "A cotton crotch is always preferred, and avoid thongs with a thin, chafing g-string, which can transfer bacteria." Wearing cotton helps prevent excessive moisture that causes bacteria to grow down there, Dweck said.

Kidney stones

These mineral deposits up your risk of getting a UTI, Ali said, because they can block the urinary tract and back up urine, giving bacteria plenty of time to grow.

This article originally appeared on Prevention.com.