Best time to get pregnant?

How long does sperm stay inside you for and when is the best time to have sex? Day before my period ends or day after?