It can happen when you cough or sneeze. Or when you pick up something heavy or while working out. It can also happen when you have the urge to go, but cannot make it to the bathroom in time. It’s called urinary incontinence, and it’s the accidental leakage of urine.

“There are about 25 million people dealing with urinary incontinence, and most of them are women,” said John Danella, M.D., FACS, director of urology at Geisinger Health System. “Though many people think it’s just something that happens as you age, it is a medical condition that you can work to prevent now.”

The bladder is a hollow organ that stores urine. When you urinate, the muscles surrounding the bladder tighten to push urine out of the bladder, while the sphincter muscle in the urethra relaxes to let the urine flow out. Stress urinary incontinence happens most often when these muscles weaken. However, nerve damage due to some diseases can also cause urinary incontinence.

Urinary incontinence is not inevitable; in fact, there are several lifestyle factors that can help prevent stress incontinence. Here are seven ways to keep your bladder healthy.

Drink the right amount of water. Believe it or not, drinking plenty of water, and not too little, can help you prevent incontinence. When you don’t drink the recommended six to eight glasses of water each day, your bladder gets used to holding less fluid. This can lead to incontinence.

“If you worry about bladder leakage during the night, cut back on drinking fluids an hour or two before bed,” Dr. Danella said.

Avoid constipation. The bladder and rectum are near each other. If you don’t empty your bowels regularly, they can put pressure on the bladder and cause incontinence. Eating a healthy diet with plenty of fiber and drinking enough water can help to keep things moving.

Maintain a healthy weight. There are a number of health issues associated with being overweight — and research shows that urinary incontinence is another issue that can affect people carrying too much weight. The heavier you are, the more pressure is put on your pelvic floor muscles, which help to keep urine in the bladder. When the pelvic floor muscles weaken, urine can leak from the bladder.

Maintain a healthy diet. Certain foods can contribute to urinary incontinence. Chocolate, acidic fruits such as oranges or grapefruits, spicy foods and sugary treats can all irritate the bladder and cause incontinence.

“If you’re suffering from urinary incontinence, try removing chocolate, acidic fruits, spicy foods and sweets from your diet to see if that has an impact,” said Dr. Danella. “You can then try to add them back in slowly to see how they affect your body.”

Avoid tobacco products. Urinary incontinence is yet another reason to stop smoking. People who smoke are three times more likely to have urinary incontinence issues compared to those who don’t. Though researchers don’t know exactly why this happens, it may have something to do with how nicotine interacts with your bladder.

Smokers are also more likely to have a chronic cough, which can lead to bladder leakage.

Stay away from caffeine, fizzy drinks and alcohol. If you’re prone to incontinence, it might be best to drink water. Coffee and other caffeinated beverages, sodas with sugar or artificial sweeteners and alcohol can all irritate the bladder and may cause urinary leakage.

Practice Kegel exercises. Strengthening the pelvic floor muscles can help you prevent urinary incontinence. You can do these exercises, called Kegels, by tightening muscles used to keep urine in, holding and releasing. It’s important to talk to your doctor to find out how often you should do Kegel exercises.

Prevent and treat chronic conditions. Many chronic conditions can affect your bladder. Patients with uncontrolled diabetes can have sugar in their urine, which greatly worsens urinary leakage. Untreated vascular disease and other conditions can cause damage to the nerves to the bladder. Ensuring these diseases are controlled may prevent worsening of bladder function over time.