In the not-too-distant past, both Microsoft (MSFT -0.10%) and International Business Machines (IBM 0.11%) were sitting pretty. Microsoft, with its mighty Windows and Office businesses, seemed almost unassailable. And IBM's strategy of selling integrated solutions involving hardware, software, and services created high switching costs for customers, making it difficult for them to move away from Big Blue.

Things have changed dramatically in only a few short years. Microsoft, blindsided by the rapid growth of mobile devices as well as the shift to cloud computing, required a new strategy from a new CEO. The company has since embraced the cloud, shifting to a software-as-a-service model for Office and investing heavily in its Azure cloud computing platform. While revenue has still been growing, Microsoft's profits have slumped. Free cash flow of $23.1 billion in fiscal 2015 was down more than 20% compared with 2012.

IBM is also facing major challenges. The company was late to cloud computing, and while heavy investments will help it catch up, many of its legacy businesses are in decline. Fast-growing areas like analytics and security are being offset by weakness elsewhere, and the net result has been falling revenue and profit. IBM generated $12.9 billion of free cash flow in 2015, down 13% from $14.9 billion in 2012.

Both Microsoft and IBM now appear to be on the right track, making the necessary investments to drive growth in the future. But which iconic tech giant is the better buy for investors?

The case for Microsoft

Image Source: Microsoft.

Under CEO Satya Nadella, who took the helm in 2014, Microsoft has made some major changes. Platforms other than Windows, which were formerly neglected or completely ignored, began to be treated as first class citizens. Office apps came to the iPhone, iPad, and Android devices, along with other Microsoft software like Outlook, OneDrive, and Skype. Microsoft realized that it needed its software to be on all devices that people used, not just PCs.

Office 365, the software-as-a-service version of Office, has been growing fast, with 22.2 million consumer subscribers. On the enterprise side, the company's Intelligent Cloud segment, which includes Azure as well as server products, has reached a $10 billion annual run rate. Windows 10, which was given away for free to consumers as an upgrade, has reached an install base of 300 million. Microsoft hopes that a massive number of users will give developers a reason to create apps for Windows 10 PCs and mobile devices.

Microsoft has some weak spots, too. Windows OEM revenue is in decline, thanks to both the free upgrade offer and the slumping PC market. And the company's smart phone business is a disaster, with Microsoft writing down $7.6 billion last year from its acquisition of Nokia's phone operations. Microsoft hasn't been able to carve out a spot for Windows mobile devices, leaving the company with a negligible market share.

In terms of valuation, Microsoft stock isn't particularly inexpensive. Backing out the net cash on the balance sheet, Microsoft's cash-adjusted P/E ratio based on analyst estimates for this fiscal year is about 16. Microsoft is by no means a bargain at this price, especially considering the trouble the company is having growing earnings. However, the strategy that Microsoft now has in place looks like the right one, and in the long run I expect the company will do just fine. I'd wait for a lower price, though.

The case for IBM

Image Source: IBM.

IBM has deeper problems than Microsoft. The company has reported year-over-year revenue declines for 16 straight quarters, and its earnings are still declining. The company expects to report non-GAAP EPS of at least $13.50 this year, down from $14.92 in 2015.

IBM is undertaking a fairly dramatic transformation, shifting resources toward high-growth areas and away from shrinking legacy businesses. The company's strategic imperatives, which include cloud, analytics, security, social, and mobile, grew revenue by 26% on an adjusted basis in 2015, and the business now account for about 35% of the company's total revenue.

Unfortunately, the rest of the business is performing poorly, and currency fluctuations have had a severe negative affect on IBM's global business. The net result has been what appears to be abysmal revenue declines; during 2015, revenue as reported slumped 12%. However, adjusted for currency and divestitures, revenue fell by just 1%, far from a disastrous outcome.

IBM is making a lot of long-term bets, with one of the biggest being healthcare. The company has made a few acquisitions in the space, and its Watson Health unit has partnered with a variety of healthcare organizations and companies. Watson, IBM's cognitive computing system, is being used to analyze structured and unstructured medical data in an effort to aid healthcare professionals and provide personalized care to patients. The efforts will take a while to pay off, and there's no guarantee that they ever will, but healthcare is potentially a multibillion-dollar opportunity for IBM.

IBM stock trades at just 11 times the company's earnings guidance, and a 3.8% dividend yield pays investors to wait for the company to complete its transformation. There's a chance that IBM's transformation fails, leaving the company's profits permanently lower. But I think IBM's valuation more than accounts for that risk.

While investing in IBM takes a particularly patient investor, IBM stock offers better value than Microsoft stock, making Big Blue the better buy.