These immune benefits can also help with infertility as well.

Having sex might help your body prepare for pregnancy. Ae Cherayut / Shutterstock

Sexual activity may actually lead to a temporary decrease in immunity during the time of ovulation in women, but for one important reason: to aid in fertility, according to Dr. Zhana Vrangalova, a professor of human sexuality at New York University and co-host of The Science of Sex podcast. “The part of the immune system that protects us against foreign invaders (like bacteria and viruses) can sometimes attack the male sperm or the fertilized egg as if they are foreign invaders,” she told INSIDER. “In order to lower the risk of this happening, the natural defenses of sexually active women loosen up during the time that fertilization could occur.”

At the same time, sexual activity can cause an increase in a different part of the immune system, T2 helper cells, which help prepare the body for pregnancy. T2 cells can "facilitate embryo implantation by increasing the body's tolerance of the embryo. This increase happens after ovulation is over, because that's when the body needs to start preparing for implantation."

Citing several studies by Dr. Tierney Lorenz published in the last three years, Vrangalova adds that "sexual activity leads to a complicated set changes in the immune system of women in order to navigate a tricky balancing act: Protect itself from foreign invaders without using those defenses against the sperm and embryo."

As Dr. Lorenz told Futurity in 2015, "We’re actually seeing the immune system responding to a social behavior: sexual activity. The sexually active women’s immune systems were preparing in advance to the mere possibility of pregnancy."