Image source: Wikimedia Commons. 

The competition was legendary. Steve Jobs, co-founder and then CEO of Apple (AAPL -0.57%) was on one side; Bill Gates, the founder at Microsoft (MSFT -1.84%), was on the other. For years, they traded barbs and attacked each other's business. But then, in 2007, they sat down and shared a stage, reflecting on their legacies.

No matter which side of the rivalry you came down on -- if it mattered to you -- it's undeniable that these two companies have been driving forces behind the technological revolution we're currently in the middle of. As such, shareholders of both companies have been rewarded handsomely; since Microsoft and Apple went public, the stocks have returned 85,000% and 25,000%, respectively.

But which is the better buy today? That's a tough question to answer, but we can gain some insight by comparing them through three different lenses.

Financial fortitude

While cash that just sits in the bank might seem like a waste, it's an incredible asset once you zoom out a bit. Consider the reality that at some point during their lifetime, every company will encounter its fair share of chaos -- whether macro in nature or company-specific.

Groups that have cash in the bank are safe in such situations. In fact, they can outspend rivals, buy back shares on the cheap, pay a dividend, or even make acquisitions. Debt-heavy companies are on the other end of the spectrum -- forced to do everything possible just to make ends meet.

Here's how Apple and Microsoft stack up in terms of financial fortitude.

Company

Cash

Debt

Net Income

Free Cash Flow

Microsoft

$137 billion

$76 billion

$16.6 billion

$26.8 billion

Apple

$238 billion

$87 billion

$46 billion

$53 billion

Data source: Yahoo! Finance.

You could search the world over and might not find two companies that have quite as much financial fortitude as these two. Their cash piles alone are worth more than the vast majority of publicly traded companies. And both are also producing incredible levels of cash flow.

While on paper, Apple is producing better numbers, I'm calling it a tie because both companies are uber-safe in terms of their income and balance sheets.

Winner = Tie

Sustainable competitive advantages

When I look back at the performance of my own portfolio, the companies that have done the best are those with the strongest sustainable competitive advantages. In investing circles, this is often called a "moat."

In essence, a moat is what sets one company apart from the rest in the field. With it, the company has a special sauce. Without it, it quickly becomes a victim to commoditization.

Apple has historically had a weak moat, relying on a combination of its brand and coming up with the Next Big Thing. Nothing is more indicative of that than the iPhone, which accounts for the lion's share of the company's revenue. The problem with this is that "coming up with the Next Big Thing" isn't very sustainable.

Over the past five years, though, the company has been working on building out an eco-system that creates high switching costs. By syncing your iTunes and all of your other files to your computer, smartphone, and tablet, you'd be loathe to leave a network of products that has all of your stuff on the cloud.

Microsoft, on the other hand, benefits from the ubiquity of its Windows and Office 365 products. Given the fact that these products have been around -- in lesser versions -- for well over 20 years, their dominance is unquestioned. As more and more internet users come of age using Microsoft Word, Excel, and PowerPoint, Microsoft's moat becomes stronger and stronger.

This seems to give Microsoft the upper hand since switching costs are very high. Outside of Alphabet's Google Docs -- which might be able to challenge Word -- no one has designed something to replace Office 365, and few would want to spend the time learning a new one when they're already proficient on Microsoft's systems.

Winner = Microsoft

Valuation

Finally, we have valuation. While this isn't an exact science, there are some straightforward metrics we can consult to give us an idea of how expensive each stock is.

Company

P/E

P/FCF

P/S

PEG Ratio

Microsoft

21

18

5.5

2.1

Apple

13

11

2.8

1.4

Data source: Yahoo! Finance, E*Trade. P/E represents figures from non-GAAP earnings.

On every metric, Apple comes out ahead as a cheaper stock. While I wouldn't say Microsoft is unreasonably expensive, there's no question as to which appears to be cheaper.

Winner = Apple

So, there you have it: We have a draw. Both companies are solid; Microsoft has the better moat, while Apple is cheaper. If I had to choose a winner, I'd go with Apple since my family holds shares of it. But maybe your home and portfolio tell a different story, and fortunately, you really can't go wrong with either.