I’m confused

When is the earliest I can take a pregnancy test? My period is due in 5 days. Is there any way that I could start this next period and still be pregnant? I had unprotected sex last night and I’m just so confused on when I can take a test