Despite a year full of controversy, Facebook (NASDAQ:FB) shareholders can't complain about the stock's performance. Amid battles against fake news and Russian-bought U.S. election ads, Facebook shares were up over 50% in 2017.

Shares are up for good reason. Facebook's user, revenue, and profit numbers continue to defy gravity. The company's flagship platform added 284 million monthly active users over the last four quarters. Instagram added around 200 million users itself in the first nine months of the year. Meanwhile, revenue grew nearly 50% last quarter, while profits were up almost 80%.

So, what exactly drove Facebook's spectacular results? And can the company continue its momentum into 2018?

The like symbol at the entrance to Facebook's campus.

Image source: Facebook.

More users, more advertisers, more ads

Facebook's core platform surpassed 2 billion users in the middle of 2017. The company's ability to consistently add new users quarter after quarter is extremely impressive. Most of those new users are coming from its Asia-Pacific and Rest of World regions, as the company has largely saturated users in North America and Europe.

Even as its user count goes up and Facebook expands into less well-connected parts of the world, average user engagement remains extremely high. In 2016, management reported the average user spends over 50 minutes per day across Facebook, Instagram, and Messenger.

When asked about it again during both the first-quarter and third-quarter earnings calls, CFO Dave Wehner noted time spent per user continues to climb across the family of apps.

As a result of its strong user growth and improving engagement, advertisers continue to flock to Facebook. Facebook announced it has over 6 million active advertisers on its flagship platform and 2 million on Instagram.

Those advertisers have enjoyed a seemingly all-you-can-eat buffet of advertisements in the recent past, but that's starting to change. Wehner noted last year that Facebook has saturated its ad load for News Feed, which generates the bulk of its revenue. As a result, in the third quarter, ad impressions across Facebook's apps increased just 10%, less than Facebook's user growth.

Facebook more than made up for the slow ad impression growth with increases in average price per ad. Those price increases are supported by the huge number of advertisers on Facebook's platform. The return on investment for Facebook ads is so much higher than most of its competitors that prices still have room to increase.

Instagram is growing faster than anyone thought it would

The biggest star for Facebook in 2017 was the performance of Instagram. As I previously mentioned, the company added around 200 million monthly active users in the first nine months of the year. Instagram Stories -- a copy of Snap's (NYSE:SNAP) Snapchat Stories feature -- was one of the biggest contributors for that growth. Instagram added around 200 million daily users in the year following the launch of the feature.

Engagement on Instagram increased to levels that rival Snapchat's. As a result, Instagram successfully won a larger share of ad budgets in 2017, some of which seemed originally earmarked for Snapchat. Snapchat found underwhelming demand on its self-serve platform soon after launching it, and its ad revenue has repeatedly fallen below expectations.

Meanwhile, Instagram continues to grow active advertisers and its ad revenue is exploding. The photo-sharing app could surpass $10 billion in revenue by 2019, according to estimates.

Will 2018 turn out just as good for investors?

Facebook continues to invest heavily in several areas including video, virtual reality, and artificial intelligence. At the same time, it's downshifting from four growth levers to three, as it runs out of room for ad impressions on its flagship platform. That could put pressure on Facebook's operating margin.

Additional operating margin pressure could stem from a shift to more video content, which currently relies on paying for content upfront, but will eventually shift to a revenue-sharing model. Video may be cannibalistic to time spent in the News Feed, which means there's potential for fewer ad impressions.

At the same time, Facebook is in a strong position to keep growing the top line. Digital advertising spending continues to grow at a relatively fast pace, and Facebook is poised to capture a huge share of the new money coming into digital in 2018. Advertisers continue to see strong ROI on their spending compared to other platforms, so Facebook should see robust top-line growth. Just don't expect operating margin to continue expanding at the mid-to-high single-digit pace it did over the past year.

This article represents the opinion of the writer, who may disagree with the “official” recommendation position of a Motley Fool premium advisory service. We’re motley! Questioning an investing thesis -- even one of our own -- helps us all think critically about investing and make decisions that help us become smarter, happier, and richer.