You can think of John Hegeman as Facebook's chief economist. He spends his days thinking about the economics of Facebook advertising.

That's an enormous thing. Facebook pulled in $4.04 billion in the second quarter of this year. And the overall economy of Facebook advertising, as Hegeman describes it, is far larger. Advertising, you see, is very much a part of everything else on the world's largest social network. Hegeman doesn't just think about ads. He thinks about how ads fit with the rest of Facebook.

When he joined Facebook in 2007, after getting a master's in economics at Stanford University, Hegeman helped build the online auction that drives the company's advertising system. Auctions are the standard way that online services accept ads from advertisers and place them on web pages and inside smartphone apps. That's what Google uses with AdWords, the system that serves up all those ads when you look for stuff on the company's Internet search engine. Advertisers bid (in dollars) for placement on the results page when you key in a particular word or group of words. But in building Facebook's advertising system, Hegeman and team took online auctions in a new direction.

The VCG auction spent decades as little more than an academic exercise. But then Hegeman and Facebook came along and applied it to online ads.

They built a system based on what's called the Vickrey-Clarke-Groves auction, or VCG, an auction mechanism that dates back to the '60s and '70s. Named for a trio of academics, including Nobel Prize winner William Vickrey, VCG spent decades as little more than an academic exercise. But then Hegeman and Facebook came along and applied it to online ads. The VCG system provided a way of building an auction that advertisers couldn't game for their own monetary gain (at least in theory). And eventually, Hegeman and team modified this complex system so that it not only ranks ad against ad, but ad against all the other stuff on Facebook.

In an echo of Google's system, the Facebook auction doesn't maximize short-term revenue for the company. The (rather idealistic) goal is to show people only ads they want to see—ads that are just as enjoyable as everything else that shows up in your Facebook News Feed and other parts of the social network. The reality hasn't quite caught up with the ideal (as anyone who uses Facebook knows all too well). But, according to Hegeman and Facebook head of ad engineering Andrew Bosworth, that ideal is what drives the company's entire ad business. They believe it will maximize revenue in the long term. "If advertisers get return," Bosworth says, "they're going to spend more."

The Facebook ad auction at least serves as a symbol for why the company has been so successful with online advertising, particularly on mobile devices. And it could provide a model for others looking to crack an increasing complicated market (Apple just added ad-blocking tools to the iPhone web browser). Google's auction has been hugely successful, but it's tailored to Google's particular medium—search—and there are ways that advertisers can game it. Facebook's auction is well suited to media beyond search, and it can't be gamed (unless advertisers somehow collude with each other).

"For anyone who is trying to build a platform with a long-term focus, where the goal is creating value for the participants rather than short-term revenue," says the 30-year-old Hegeman, "this kind of thing is going to be a pretty good option."

The Right Ad at the Right Time

With Google's system, based on what's called a "generalized second price auction," advertisers bid for a spot on the page when someone searches for a particular keyword. The winning bidder gets to place an ad for the price bid by the next highest bidder. Or at least, that's the gist. Bids are weighted according to ad relevance and other factors. But with its VCG auction, Facebook adds a different element. It calculates price according to how much value is lost from the rest of the system if the ad lands on the page. This value is a mix of how much other advertisers bid for placement and how relevant the ad is to the particular situation at hand.

"If you're an advertiser and you're getting a chance to show your ad, you're going to take away the opportunity from someone else," Hegeman explains. "The price can be determined based on how much value is being displaced from those other people. An advertiser will only win this placement if their ad really is the most relevant, if it really is the best ad to show to this person at this point in time."

The price can be determined based on how much value is being displaced from those other people.

This is how the VCG is fundamentally designed to work. It's well suited to situations where multiple bidders are vying for multiple items—such as many advertisers bidding for many different ad spots, with many different types of ads, in many different situations—and basically, it doles out these items based on which scenario maximizes the total value created by all bidders. For instance, if three people places bids on three things, it will allocate the items according to how the entire group values those three things. The particulars of this are complicated, but the end result is that bidders can't game the auction. They only succeed if they're truthful in placing a value (a bid) on each item.

That, says Ron Berman, a professor of marketing at the Wharton School of Business, can help drive the health of something like the Facebook ad system, encouraging advertisers to properly target ads rather than just trying to maximize their own revenue. "If you can game the system, you spend a lot of time and effort trying to game the system. It's a waste of money, but it also gives you less confidence in the auction itself," Berman says. "If you know there is no way to game the system, you're focused on making the advertising better. In the long run, it's good for bidders and it's good for auctioneers."

At the same time, Facebook shapes and reshapes this basic setup in ways that aim to better define the idea of relevant ad. As you use Facebook, you can identify ads that you don't like, and this information plays into the auction. Or, if advertisers produce what the system considers good and relevant ads over the long haul, the system will lower their prices. "We're creating an economic incentive for advertisers to produce ads that are better targeted, or that are better quality in general," Bosworth says.

The rub is that—like Google's auction—it's a black box. From outside Facebook, you can't really know how it works on the inside. But since Facebook rolled out its VCG auction, it has proven massively successful, and the idea has spread. According to a paper published by Google chief economist Hal Varian and another Googler, Chris Harris, the company has now used VCG with the ad systems it runs beyond its search engine.

Ads Against the Rest

Meanwhile, with the introduction of ads into the Facebook News Feed in 2012, Hegeman and Facebook have modified their VCG auction so that it can help slot ads among all the other stuff on Facebook. It calculates relevance relative to everything else happening in your News Feed.

"What our systems are able to do is think about what is the most relevant organic piece of content we have and what is the most relevant ad we have, and we can balance those things against each other," Hegeman explains. "If there is a really important life event, that can show up on top. If not, and there’s a really relevant ad, the ad can show up higher." Again, the aim is to show people things they most want to see—ad or not.

It not only ranks ad against ad, but ads against the rest of Facebook.

This is different from what you see on the Google search engine. If Google ads appear, they appear either at the top or on the side of the page—not mixed with the organic results. On News Feed, Facebook places ads among everything else. One method isn't necessarily superior to other (opinions on the matter differ). But Berman argues that each method suits the medium.

"The goals are different," he says. "Google's goal is to help you find content as fast as possible and leave Google. Facebook's goal is to lengthen the time you spend on Facebook—to make it interesting for you and enjoyable. Google wants to make it easier for you to find answers. Facebook wants to give you mix of things. There is no answer you are trying to find."

Faith in the Un-Gameable

In some ways, Facebook's VCG auction is still a theoretical exercise. How much do advertisers really think about gaming the system? How much do they really understand about the way the auction prevents such gaming? How much do they understand the value of an ad in a particular situation? Such questions can't necessarily be answered. "A lot of the bidders don't really understand how much their advertising is worth," Berman says. "Even if you spend a lot of time ensuring no one can game the system, it may not matter."

But there is at least some value in an un-gameable system—whether people understand it on not: it may be enough that they believe it's un-gameable. And certainly, the big advertising houses understand how things work. According to Tony Effik, a vice president at advertising agency R/GA, advertisers spend an awful lot of time trying to game Google. Facebook? Not as much.

In some respects, the changes Facebook has made to its auction are small. But that doesn't mean they're inconsequential. "Sometimes," says Stanford economist and professor of price theory Jonathan Levin, "you can make very small changes in an auction, and it can have very big effects in the way the auction works—and in the way the market behaves."