It might be hard to believe, but seven years ago Microsoft (MSFT 1.82%) and Oracle (ORCL 2.02%) were considered peers, with each worth roughly $200 billion. In the time that's followed, however, it's been no contest: While Microsoft has fully embraced the Software-as-a-Service (SaaS) business model and blossomed as a result, Oracle has been left in the dust, trying to deal with the vagaries of being a legacy software provider.

That doesn't mean that Oracle's days are numbered. After all, the company has spit out almost $14 billion in free cash flow over the past twelve months alone. Only a small cadre of organizations in the world can claim to be as profitable. Meanwhile, Microsoft's run over that time frame -- up 220% assuming dividends were reinvested -- has some wondering if it's overpriced.

Against this backdrop, which is the better stock to buy today?

Businessman making a choice at a fork in the road.

Image source: Getty Images

Obviously, we can't answer that question with 100% certainty. But we can compare the three companies on three crucial metrics to see which is the better buy. When we line them up, here's how they fare.

Financial fortitude

When I say "financial fortitude", what I'm really asking is this: If a financial crisis akin to the Great Recession of 2008 were to hit today, how would these companies be affected? If they have lots of cash and strong free cash flow, they might not only survive, but get stronger. It would be cheaper to buy back stock or acquire rivals in a down turn, and easier to price the competition into bankruptcy. But if a company has lots of debt, a system-wide downturn can be a death knell.

Keeping in mind that Microsoft is valued at over four times the size of Oracle, here's how the two stack up.

Company

Cash

Debt

Free Cash Flow

Microsoft

$130 billion

$70 billion

$32 billion

Oracle

$49 billion

$52 billion

$14 billion

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

The winner here is easy: Microsoft.

Let's get one thing clear: Oracle would likely survive just fine in a downturn. It has a manageable debt load and strong cash flows. Microsoft, however, would be in a position to benefit mightily. It has a net cash position of over $60 billion, and much of its free cash flow is brought in on a recurring (read: reliable) basis. It could make several strategic purchases in such an environment that few of its competitors could.

Winner = Microsoft

Valuation

Next we have valuation, which is a bit murkier. I like to consult a number of different metrics when determining whether one stock is more "expensive" than another.

Company

P/E

P/FCF

PEG Ratio

Dividend

FCF Payout

Microsoft

25

25

1.7

1.8%

41%

Oracle

19

13

1.5

1.5%

22%

Data source: Yahoo! Finance, E*Trade. Non-GAAP earnings used to calculate P/E when applicable.

Despite Microsoft's impressive run over the past five years, there isn't an enormous chasm in valuation between the two companies. That being said, it's clear that Oracle is the cheaper stock; it came out ahead in almost every metric, even when potential for growth was taken into consideration with the PEG ratio.

And while Oracle's dividend may be slightly less than Microsoft's, it also uses less than one of every four free cash flow dollars to meet its payout obligations. That means that it has more room to grow the dividend moving forward.

Winner = Oracle

Sustainable competitive advantages

Finally, we have what I consider to be the most important -- and most difficult -- thing to investigate: a company's sustainable competitive advantages, or its "moat". Companies with wide moats keep customers coming back year after year, while the competition can't make a dent. They are wealth compounding machines.

Oracle's key moat comes from high switching costs. Once companies are locked into using Oracle's enterprise software -- and have stored their information, trained their employees, and spent money on on-premise hosting -- they don't often want to switch. The problem with this moat: SaaS completely disrupted it. 

Oracle has tried to pivot toward SaaS, as well as Infrastructure-as-a-Service (IaaS) and Platform-as-a-Service (PaaS) offerings, but growth has decelerated markedly over the past year. The company stopped breaking out the division entirely last year, which is not a positive sign. 

Microsoft was also late to the SaaS game, but it has successfully made the transition under the guidance of current CEO Satya Nadella. While there are lots of moving pieces, Microsoft Office Cloud -- which includes things like Word, Excel, and Outlook Mail -- and Azure cloud hosting are the biggest growth drivers. Recent results prove that momentum is on the company's side: Revenue jumped 12%, and operating income grew even faster at 18%.

The bottom line is this: Oracle primarily relied on high switching costs via its on-premise, licensed software. The SaaS model completely disrupted this business model. Microsoft eventually made the transition, but Oracle may have waited too long and is now playing catch-up.

Winner = Microsoft

Check out the latest Microsoft earnings call transcript.

And my winner is...

So there you have it: While Oracle may have the "cheaper" stock, Microsoft's moat and its financial fortitude give it the edge. While I haven't bought shares for my own portfolio -- an enormous "miss" for me -- I have given the company an outperform rating on my CAPS portfolio. If you're looking for a stable SaaS company to invest in, Microsoft should be one of your first candidates.