Fidji Simo, Facebook product management director on the ads team, on the left.

Fidji Simo and Hong Ge have, quite arguably, some of the most important jobs at Facebook.

It's their job — and their team's job — to pick from the tens of millions of ads running on Facebook every day and winnow the glut down to the hypothetical 10 or so ads that each Facebook user sees in their News Feed every day. To do that, the team has had to build a complex algorithm that not only maximizes value for advertisers, but also ensures that the user experience stays pleasant.

The process of placing an ad on News Feed is a complicated dance. Facebook has to decide not only which ad to show to its users, but when to show it to them. There isn't a dedicated "slot," so to speak, for an ad in News Feed, so the team must time the ads based what the user is doing on Facebook at that given moment.

BuzzFeed / Matthew Lynley

Each day, there are between 11 and 12 million active ads on Facebook, from roughly 1.5 million advertisers running campaigns, Simo told BuzzFeed News. Part of the reason for that glut of advertisers is thanks to the trove of data that Facebook has from its users over the social network's 10 years that can be used to target ads more effectively, eMarketer principal analyst Debra Williamson said.

"One of the things that has set Facebook apart from other media platforms is the information it has about its users," she said. "Right from the start, Facebook was able to develop an ad platform that took advantage of actual, real information as opposed to guesses and estimates of who was looking at the page, where they were coming from."

Using that targeting data — which ranges from what college the user is attending to where they are in the universe or where they work — Facebook is able to quickly whittle away the number of ads that are relevant to a specific user to between 5,000 and 7,000 ads. At this point, the job is only around halfway done.

In News Feed, any given user has around 1,500 stories they could see each day. The News Feed ranking algorithm's job is to determine which of those stories should be shown highest on each user's News Feed. The company does this through a rather complex algorithm that weights how engaging each post is — how many likes and comments it has — and a wide range of other signals it can use to determine what's most important. For example, a News Feed story that has a comment that says "congratulations" is weighted more strongly than other stories, since it implies that some major life event may have occurred.

Ads effectively follow the same rules, though there are a few other things happening under the hood, Ge said. What determines whether an ad is shown in News Feed is a careful optimization problem that ensures that Facebook users still have a high-quality experience, while advertisers are still driven value.

BuzzFeed / Matthew Lynley

The formula shown above is the basis of the algorithm, and determines whether an ad gets shown in a high slot in your News Feed at all. The value for advertisers is a combination of how much they bid for their ad as well as the probability that their ad will achieve the objective the advertiser sets for it — whether that's a click, a video view, an impression or anything along those lines. Value for users is determined by how high quality the post is and whether it will impact the user experience. That Facebook optimizes for revenue to itself is actually somewhat of a misnomer, Simo argued, though the company's revenue numbers don't lie: They're making money.

"It's a good alignment of incentives," Simo said. "For an advertiser, a more engaging ad means a user is going to enjoy it more, and you actually get better value because you end up paying less." Essentially, higher quality ads — whether that's good video, high-fidelity photos, or ads that attract a lot of likes and comments — cost less to be ranked higher in News Feed.

In essence, News Feed ads are basically competing with organic Facebook stories for placement in a News Feed. Once the number of ads has been whittled down to the 5,000 to 7,000 from the initial wave, the ranking algorithm kicks in and Facebook begins to cull step by step to the hypothetical ten ads a Facebook user sees each day based on the probability that they will achieve the advertiser's goal, how much the advertiser is willing to pay, and whether it still adds some value to the user's overall News Feed experience.

Still, there are times in which the value for the user overwhelms the advertising component of the algorithm, Simo said. If a Facebook user is very active on the site or the app, and actively liking and commenting on News Feed stories about a particular subject or event (the birth of a niece or nephew, for example), then the user is actually less likely to see an ad ranked higher in their News Feed. The idea is that if a user is very active on Facebook around a subject or event, an ad would impact the overall experience, so it's less likely to be shown. Conversely, if a user is casually browsing the site or app, and is looking for more content, an ad is more likely to be shown.

Facebook

Ad placement is also an equally complex technical problem. Facebook is executing these ranking and refining algorithms every time a Facebook user loads his or her News Feed. With more than 800 million checking Facebook every day — and many checking it more than once — the problem quickly becomes a massive data problem.

"If you do the math, there's a lot going on in the background in terms of how we choose the ad, and how it gets show in News Feed," Ge said. "By doing this we're giving value to viewers and also advertisers. By optimizing the engagement and relevance for the ad, we're maximizing their chance of them appearing in News Feed."

One way Facebook determines how high the quality of its News Feed is by regularly surveying its users. Over time, some users will see surveys asking them how their Facebook News Feed experience is, and the company charts how that progresses over time. It then compares different groups of people with different experiences — for example, there are groups of Facebook users who haven't seen ads in a very long time, Simo said, that are compared to groups who do see ads.

The company has also recently begun asking it users why they hide posts in their News Feed, and tracking the sentiment around specific stories over time. In an update today, Facebook said it would weight more strongly how its users respond when they hide advertisements when it determines the quality of an ad, and also pay closer attention to when users that don't often hide ads end up hiding one. After a user hides an ad, Facebook now asks why that user hid the ad.

"That's one of the big things we do with surveys. That's critical, all the other signals we have are very behavior-based, like you sharing," Simo said. "Surveys give us more of a feeling of how things are going. [We want to make] sure this thing over time improves. If we do a good job picking up on all these signals and ranking ads based on these signals, you imagine over time the ads are higher quality and therefore overall engagement goes up."

Facebook

The results have thus far been pretty good. Facebook went from not having a mobile advertising business at all to generating $2.68 billion in advertising revenue last quarter — 62 percent of which comes from advertisements on mobile devices. The company's newest advertising business, mobile app install ads, is tracking to generate $1 billion in revenue annually according to analyst estimates.

Over time, Facebook wants ads to improve in News Feed. High quality of ads means that advertisers have to spend less and still get a lot of value out of their ad campaigns, and Facebook users will still keep coming back to the site over and over without a negative ad experience driving users away. To do so, Facebook works carefully with advertisers to determine what ads perform best and best practices for advertising on Facebook.

"Nobody wants to see bad ads, bad content in the feed, because they're not going to want to come back or interact or engage," Williamson said. "It's obviously in the best interest of Facebook and its advertisers to develop high quality ads. It's a combination of extraordinary reach with very, very specific targeting."

Matthew Lynley is a business reporter for BuzzFeed News in San Francisco. Lynley reports on Silicon Valley and the tech industry.