When you first load a webpage, the first thing that happens is it generates an impression, which is then forwarded to an ad server. So far, so good, but you might be surprised by how much that ad server knows about you.
Using information gathered from Internet cookies, social media, and more, an ad server is capable of generating a unique profile of various metrics, almost like a QR code, that contains everything it knows about you: how old you are, your relationship status, what websites you browse, where you're located, etc.
With that code generated, the ad server tries to match it against a pre-sold inventory of ads, almost like a key fitting into a lock. If the key fits, the process ends there, and an ad is returned that advertisers believe jibes with your unique personal profile. But it's what happens if the server doesn't have an ad that matches where things gets interesting.