Sex and timing.

When is the best time to have sex to prevent possible pregnancy, within your cycle? Would it be basically as your period ends, or sometime in between?