They are two of the world's most valuable companies. One -- Apple (NASDAQ:AAPL) -- makes the most popular gadgets for well-to-do consumers around the globe. The other -- Facebook (NASDAQ:FB) -- owns properties that help connect all of these consumers. Together they are worth over $1.5 trillion!

Today we're going to figure out which of these two stocks is a better buy. That's no easy feat, but by splitting the task up into three digestible pieces, we'll get a better idea of what we're paying for if/when we buy shares of either company.

Young man using smart phone with social media icons superimposed above the phone

Image source: Getty Images

Financial fortitude

The first topic we'll tackle is financial fortitude. The litmus test here is simple: if we were to have a 2008-or-worse style economic crisis tomorrow, how would that affect the long-term prospects of these two companies? 

Keeping in mind that Apple is worth roughly $940 billion versus Facebook's $600 billion valuation, here's where these two stand.

Company Cash Debt Free Cash Flow
Apple $267 billion $101 billion $54 billion
Facebook $44 billion $0 $19 billion

Data source: Yahoo! Finance. Cash includes short and long-term investments. Free cash flow presented on trailing twelve-month basis.

Solid arguments could be made for both companies to win this round. Facebook has absolutely zero long-term debt to worry about, which is a big deal. It also brought in $19 billion in free cash flow over the past year. That's more than twice what it brought in just two years ago.

However, Apple only added debt when interest rates were low, and part of that had to do with an inability to repatriate its cash held abroad. Even after backing out debt, Apple has a net cash position of over $160 billion. But while Apple's cash flows are the envy of Wall Street, they are also down over 20% from all-time highs.

If we get back to the litmus test, however, the answer is pretty clear: Both of these companies have incredibly strong balance sheets and cash flows, and both would definitely be able to comfortably weather an economic downturn.

Winner = Tie

Valuation

Next we have valuation. To get a better idea of how expensive a stock is, here are five metrics I like to consult in building out a more complete understanding.

Company P/E P/FCF PEG Ratio Dividend FCF Payout
Apple 18 17 1.2 1.6% 24%
Facebook 30 32 1.1 N/A N/A

Data source: Yahoo! Finance, E*Trade. P/E calculated using non-GAAP earnings when possible. N/A = Not applicable due to Facebook not offering a dividend.

On this metric we do have a winner. Apple is cheaper on both an earnings (P/E) and free cash flow (P/FCF) basis, and even when we throw growth into the equation (the PEG ratio) it is only minimally more expensive than Facebook. Apple also offers up a modest but very safe dividend for investors.

Facebook's valuation isn't terrible either, especially given the fact that revenue grew at 49% last quarter while earnings jumped 63%. So the elevated ratios shouldn't make you shy away from the stock. 

But Apple does have a demonstrably more favorable valuation at today's prices.

Winner = Apple

Sustainable competitive advantages

Finally, we have sustainable competitive advantages, or "moats", as they are referred to by investors. In my ten years as an investor, nothing has been more significant for the returns of my investments than the strength of the moats of the underlying companies.

Beginning investors are often surprised to find out that Apple's moat -- historically -- hasnt' been all that strong. Because the company built itself by building The Next Great iThing after The Next Great iThing, it seemed like the company could do no wrong. But such successes are actually quite easy to mimic -- look at the rise of the Android operating system as proof.

That's why, historically, the value of Apple's brand was the most powerful moat it had. Today, no one in the world has a better brand -- at least that's what the folks at Forbes have to say. They named it the globe's #1 brand, and valued it at $183 billion.

But Apple's moat doesn't stop there. With the creation of the iCloud and the popularity of Apple's services, switching costs are rising. If you have all of your data and apps stored on the iCloud -- and available on your iPhone, Mac, and iPad -- it would make sense to just buy another Apple product when it came time for an upgrade.

Those moats, however, aren't enough to dethrone Facebook. The company also benefits from an enormously valuable brand, which includes Instagram and WhatsApp too. Forbes ranked it #4, with a brand value of almost $95 billion.

But Facebook's real moat comes from the network effect. When someone new joins Facebook -- or Instagram, or WhatsApp -- non-users are incentivized to join. What's the point, after all, in joining a social network if no one you know is on it? That creates a virtuous cycle that keeps drawing users in, and allows Facebook to collect ever more data on those users and sell it to advertisers.

Because of the network effect, it would be very difficult to unseat Facebook's social media dominance in short order. Because of that, my nod goes to Facebook.

Winner = Facebook

And my winner is...

So there you have it: two high quality companies reaching a draw. Whenever this is the case, I always give the nod to the company with the wider moat. In this case, that's Facebook. Not surprisingly, that also matches where my own money is: While I don't own shares of Apple, Facebook is not only given an out-perform rating on my CAPS profile, but it also accounts for 7% of my real-life holdings. 

This is a high-quality company with a very strong balance sheet run by a founder-CEO with lots of skin in the game, plus it has powerful network effects as a tailwind. I think it's worth considering for your portfolio.

Brian Stoffel owns shares of Facebook. The Motley Fool owns shares of and recommends Apple and Facebook. The Motley Fool has the following options: long January 2020 $150 calls on Apple and short January 2020 $155 calls on Apple. The Motley Fool has a disclosure policy.