Both Microsoft (NASDAQ:MSFT) and IBM (NYSE:IBM) have earned their places as stalwarts of the tech industry. Microsoft built its leadership through its industry-leading software and Windows operating system, while IBM made its name with some of the most innovative tech hardware used by business around the globe.

But the technology sector has changed significantly over the years, and both companies have been forced to adapt to cloud-based software and services. Microsoft has made some missteps along the way but is now a cloud computing powerhouse with a clear direction for its future. Meanwhile, IBM appears to still be trying to find its place in an ever-changing tech world.

To really know which of these companies is the better long-term buy, let's look at their financial fortitude, valuations, and competitive advantages.

Two doors next to each other.

Image source: Getty Images.

Financial fortitude

Company Cash Debt Free Cash Flow (TTM)
Microsoft $131.5 billion $86.3 billion $33.6 billion
IBM $18.0 billion $55.1 billion $11.7 billion

Data source: Yahoo! Finance and Morningstar. TTM=Trailing 12 months.

Both companies have a significant amount of debt, but Microsoft is in a much better position because it has enough cash to balance out its debt and is generating solid free cash flow. IBM, on the other hand, has far more debt than cash, and its free cash flow is far lower than Microsoft's. It has made a number of acquisitions over the past few years in an attempt to spur growth, which is part of the reason its financials look far worse than Microsoft's right now.

Winner: Microsoft.

Valuation

Company P/E Ratio (TTM) Forward P/E EV/EBITDA
Microsoft 30.22 26.62 19.18
IBM 14.76 9.97 9.42

Data source: Yahoo! Finance. EV = enterprise value.

The average P/E for companies in the S&P 500 is about 22, which makes IBM's stock look cheaper when compared directly to Microsoft, whose P/E isn't all that expensive, but is a bit pricier.

Meanwhile, the average EV/EBITDA for companies in the S&P 500 is around 14, which again makes IBM's shares look cheaper versus Microsoft's. It's worth pointing out that just because one company's stock is technically less expensive than another's, it doesn't necessarily mean that the stock is a better long-term bet.

Winner: IBM.

Competitive advantage

IBM is working hard to benefit from the rapid expansion in cloud computing, and one of its biggest moves came most recently when it spent $34 billion at the end of last year to purchase of Red Hat. The acquisition will make IBM a leading player in the hybrid cloud market, which it believes will eventually be worth $1 trillion.

But the Red Hat purchase substantially adds to IBM's debt, and it's still unclear how well the purchase will ultimately pan out for the company. It appears to be more dependent on making acquisitions to enter new markets, which is an expensive and a risky way for any tech company to bet its growth on.

Meanwhile, Microsoft has successfully transitioned to cloud computing by bringing its Office suite online and making it a source of recurring revenue for the company. The overall cloud strategy is delivering strong results for the company, with commercial cloud revenue growing 41% in the most recent quarter to $9.6 billion, and the company's Azure cloud-computing platform sales jumping 73% year over year.

Microsoft is the No. 2 public cloud computing platform behind Amazon.com, and its early moves into this space should help maintain an advantage over smaller players that challenge its dominance. The fact that Microsoft is already benefiting from cloud computing and holds a dominant position means that it has a stronger competitive advantage in its respective markets when compared with IBM.

Winner: Microsoft.

And the winner is...Microsoft.

Sure, IBM's stock is cheap right now, but I'm not convinced that the company has successfully set itself up for the next decade with its current moves. The purchase of Red Hat should help its cloud strategy, but Microsoft is already benefiting from moves it made years ago to position itself as a cloud computing leader. Its innovation is paying off now and should help the company outpace IBM in the coming years.