Sperm can live inside your uterus for up to five days after having sex, and pregnancy can only occur if there are sperm in your uterus or fallopian tubes when you ovulate.

For many women, ovulation occurs around day 14 of your cycle. However, having unprotected sex during your period or outside of your expected fertile window isn’t a guarantee that you won’t get pregnant.

For women with a shorter cycle — the average is 28 to 30 days — there’s still a possibility pregnancy could occur if you have sex during your period. For example, if you have sex toward the end of your period and you ovulate early, you can conceive. Using birth control, condoms, or another method of protection is always the safest way to prevent pregnancy.

Read on to learn more about how to time sex and other ways to prevent pregnancy.

Ovulation occurs when a mature egg is released from an ovary. About once a month, an egg matures and is released into the fallopian tube. It then heads toward waiting sperm in the fallopian tubes and uterus.

An egg is viable between 12 and 24 hours after it leaves the ovary. Sperm can stay alive up to five days after having sex. Implantation of an egg, which happens after fertilization, usually takes place 6 to12 days after ovulation.

You can get pregnant immediately after your period. That can happen if you have sex toward the end of your cycle and are approaching your fertile window. On the other hand, the probability of getting pregnant right before your period is low.

If you’re tracking ovulation and wait 36 to 48 hours after ovulating, the chance you’ll conceive is low. The probability for pregnancy decreases the further in the month you are from ovulation.

If pregnancy doesn’t occur, the uterine lining will shed and your menstrual period will start.

Tracking your fertile window is a way to determine your “optimal” time to get pregnant. It can also help prevent pregnancy if you aren’t trying to conceive. As a method of reliable birth control, it can take several months of recording your monthly cycle to figure out your fertile window.

How to track your fertile window

The following method will help you find out your fertile window.

  1. For 8 to 12 months, record the day you start your menstrual period and count the total number of days in that cycle. Note that the first full flow day of your menstrual period is day one.
  2. Then write down the longest and shortest number of days from your monthly tracking.
  3. Find out the first day of your fertile window by subtracting 18 days from the length of your shortest cycle. For example, if your shortest cycle was 27 days, subtract 18 from 27, and write down day 9.
  4. Find out the last day of your fertile window by subtracting 11 from your length of the longest cycle. For example, if it was 30 days, you’d get day 19.
  5. The time between the shortest and longest day is your fertile window. In the above example, it would be between days 9 and 19. If you’re trying to avoid pregnancy, you’d want to avoid having unprotected sex during those days.

How to use your fertile window as birth control

Ovulation will occur one day during your fertile window. The egg released is viable for 12 to 24 hours. That doesn’t mean you can get pregnant every day during this window. But if you’re trying to prevent pregnancy, you should abstain from unprotected sex during the entire fertile window.

Tools for tracking your cycle

To track your cycle, mark the first day of your menstrual cycles on the calendar or in your day planner. Do this over several months. You can also use a fertility app, such as Glow Ovulation or Clue Period Tracker, to help you keep track.

If you have very consistent cycles, knowing your fertile window can help prevent pregnancy. But keep in mind, your cycle days can still change each month. Factors like stress, diet, or heavy exercise can affect the number of days in your cycle. The day of ovulation can also change every month.

Tracking your ovulation is a more effective way to help you get pregnant. If you’re trying to avoid pregnancy, talk to your doctor about the best birth control for you.

Tracking ovulation is another effective fertility awareness method. Common ways to track ovulation include:

Basal body temperature

Your basal body temperature is your temperature when you’re fully at rest. It rises slightly following ovulation. To track your basal body temperature, you’ll need a special basal temperature thermometer.

Using the thermometer, take and record your temperature when you first wake up in the morning before getting out of bed. You can chart it on paper or an app. Your temperature will rise slightly, about 0.5°F (0.3°C), during ovulation.

Because this method helps you understand when ovulation has occurred, it works better for preventing pregnancy by waiting to have unprotected sex until a couple of days after the spike in temperature.

Cervical mucus

Some women notice an increase in cervical mucus close to ovulation. This is because estrogen levels surge during this time, causing your cervix to produce more mucus.

This mucus will be clear and stretchy. The consistency will be similar to egg whites. Your body may be most fertile on days when you notice an increase in cervical mucus.

Ovulation predictor kits

If you’re trying to get pregnant, you may want to purchase an ovulation predictor kit. They test your urine for a surge in the luteinizing hormone (LH).

LH surges 24 to 48 hours prior to ovulation. Avoid having unprotected sex at this time if you’re trying to prevent pregnancy. Because sperm can survive in the uterus for up to five days, however, you would also want to avoid unprotected sex for the five days before this surge, which can be harder to predict ahead of time.

There are several options for effective forms of contraception. Popular choices include:

These options are over 99 percent effective against pregnancy if you follow the instructions carefully.

Condoms are another effective form of birth control and also protect against sexually transmitted infections.

Having unprotected sex during your period decreases your probability of pregnancy. But it isn’t a guarantee.

Tracking ovulation and determining your fertile window can decrease your chance of getting pregnant each month. Natural family planning has about a 25 percent failure rate. If you want to prevent pregnancy, the best option is to talk to your doctor about a more reliable form of birth control.

Healthline and our partners may receive a portion of revenues if you make a purchase using a link above.