When to test?

How long u can get pregnant after having sex? And minimum how many days/weeks/months u have to wait to check or to use pregnancy test?