Who are the players and how does a particular ad (and not others) end up on a page I am browsing?

I understand how cookies work (more or less), but I don’t understand how a particular advertisement ends up on a particular web page I am browsing while others do not. Who are the players involved? Who gets paid for what?

For example, on a given day I go to the Nike website, the REI website, a small website devoted to kites, and a small website devoted to funny t-shirts.

I go to CNN, and I see an ad for Coke, an ad for a bike website I visited a month ago, and for the kite store. I go to another website and I see a Nike store ad and an ad for a local store that I have no interest in. I go to three website in a row that have the t-shirt shop ads. This leads me to think things like how did the little kite store and the t-shirt shop get in front of my eyes in front of other bigger companies with bigger budgets? Why am I not looking at only Nike ads? Seeing that I go to a lot of websites in a given day, all of who want my attention, who determines what actually gets put before me to the exclusion of others? Who is getting paid for that?

For context, when I was I worked for the high school newspaper in the olden days, we would go to merchants, give them a price for an ad size and number of times run, and they would pay us directly. Pretty simple process and relationship.

I know to some extent, ads are targeted based on the topic - keywords on the web page. I recall one noted example, a screenshot of a news item about Steve Irwin being stingray’ed to death, that mentioned his young daugher - and the ad embedded in the web page was something for life insurance, with a photo of a little girl asking “Daddy, what happens to us if you die?”

There are many different mechanisms that serve ads. It depends on what services are employed by the web site, the ad aggregators, the advertising networks, etc. In general, advertisers contract with the networks to publish a series of ads, and websites contract with networks, publishers, and aggregators to serve them. There are all sorts of mechanisms to determine which ads are served, based on past browsing, cookies, how much each advertisers is willing to pay, what ads you’ve been served recently, etc.

Geographic location also plays a big part, especially for seeing ads from local stores and companies. They make very specific ad buys, limited to the market area (a city, a state, etc.) where they operate.

Also, FWIW, the biggest network for placing digital ads (i.e., the ads you see when you visit websites) is Google; Meta/Facebook is also huge, but specifically for ads served up on their social media platforms.

Also, many ad networks collect huge amounts of data and prepare extensive profiles of unique users from all sorts of browsing activity. Even without cookies they can assume a huge amount about you and tailor their ads accordingly.