It depends.
Inside a woman’s body, it doesn’t live long at all, if we’re referring to in the vaginal canal. Sperm that is in the vagina will leak out or die before a few hours. However, if the sperm makes it to the cervical mucus, then it can live for a day or two there. But some “top survivor” sperm will live even longer, beyond 4 days. Remember, we are talking about several millions of sperm, so they survive different durations. Because there are so many INDIVIDUAL sperm, the lifespan varies between the fastest to die and the slowest to die. It’s sort of like us asking the question “How many years can a car be driven before it needs a major repair” In general, that answer might be 1-5 years, but you can always have that one car that is still running after 10 years without a repair, even though that is an uncommon exception. So in a particular grouping of sperm, the wimpiest will die instantly, and each minute more die until after a few days, only the best survive. It’s not a scenario where the sperm all stay alive and then a biological alarm goes off and they all instantly die at the same time.
Inside the male’s body, the life span of sperm is 74 days. This means if a man does something bad for sperm (smokes marijuana or tobacco), then the sperm will be negatively affected for a long time.
Outside the body, sperm die very quickly (less than a few hours), unless of course, we are talking about sperm that is placed outside the body into a special laboratory environment. Then it can live several days. If that sperm is frozen properly, then it can live indefinitely until it is thawed.

