Microsoft (NASDAQ:MSFT) and HP (NYSE:HPQ) are two of America's most iconic tech companies. Microsoft redefined personal computing with its Windows operating system and Office software, while HP grew from Silicon Valley's first tech start-up into one of the world's largest PC makers.

But over the past five years, Microsoft's stock has surged nearly 340% as HP's advanced less than 30%. Microsoft brought back the bulls with the growth of its cloud businesses under CEO Satya Nadella, while HP failed to excite investors by retaining its PC and printing businesses after splitting with Hewlett-Packard Enterprise (NYSE:HPE) in 2015. Will that trend continue over the next few years?

An illustration of network connections across the globe.

Image source: Getty Images.

Microsoft makes a six-year comeback

Under Nadella, who became Microsoft's third CEO in 2014, the aging tech giant has reduced its dependence on its Windows and Office cash cows with a new "mobile first, cloud first" mantra.

Microsoft transformed Windows and Office from local software products into cloud-based services, launched mobile apps on iOS and Android, and expanded its cloud infrastructure platform Azure. It also expanded its lineup of Surface devices and nurtured the growth of its Xbox gaming ecosystem.

That transformation initially throttled Microsoft's sales growth, as the company pivoted from one-time installations toward recurring subscription revenue, and dented its earnings growth as the company ramped up its investments. However, those strategies gradually paid off and generated double-digit sales growth in both fiscal 2018 and 2019.

Last quarter, Microsoft's "commercial cloud" revenue, which includes Office 365, Dynamics 365, Azure, and other services, surged 39% annually to $13.3 billion and accounted for 38% of its top line. Azure is also now the world's second-largest cloud infrastructure platform after Amazon Web Services (AWS).

HP loses its CEO and rejects a hostile suitor

HP was led by Dion Wiesler, who previously led its PC and printing units, after its split with HPE. Weisler revived the stagnant PC business by launching fresh designs for higher-end ultrabooks, 2-in-1 devices, and gaming PCs.

Color ink cartridges in a printer.

Image source: Getty Images.

Weisler also scaled up the printing unit by expanding it into new markets like industrial 3D printing, and overseeing its acquisitions of Samsung's printing unit and office equipment dealer Apogee. Those moves breathed fresh life into HP, as its revenue rose 8% in 2017 and another 12% in 2018. Unfortunately, that streak ended in 2019 with less than 1% sales growth as demand for its PCs and printers tapered off.

The slowdown in its printing business was particularly worrisome, since its high-margin supplies were losing ground to generic ink and toner suppliers. The ongoing loss of that higher-margin revenue throttled HP's earnings growth.

Weisler then resigned due to a family matter in late 2019, and supply chain issues prevented HP from capitalizing on the surging demand for PCs throughout the COVID-19 crisis. To top it off, HP rejected a hostile takeover bid by Xerox, which had been considered a way for both aging tech companies to stay relevant, earlier this year.

Which company faces fewer headwinds?

Microsoft's revenue and earnings rose 14% and 28%, respectively, in the first nine months of fiscal 2020, which ended in late June. It didn't offer any guidance for the fourth quarter, but analysts anticipate 12% sales growth and 20% earnings growth for the full year.

Earlier this year, Microsoft warned that the COVID-19 crisis had curbed sales of its Windows licenses, gaming hardware, Surface devices, and search ads, but noted those slowdowns were offset by the growth of its cloud services throughout the crisis. Wall Street expects Microsoft's momentum to continue next year with 11% sales growth and 10% earnings growth.

HP's revenue fell 6% in the first half of fiscal 2020, and its earnings dipped 3%. Its PC sales were stable at the beginning of the year, but tumbled in the second quarter as the COVID-19 crisis disrupted its supply chains. Printing sales were weak throughout the first half, with soft demand in both hardware and supplies.

HP also didn't provide a full-year forecast, but analysts expect its revenue and earnings to decline 8% and 6%, respectively. For 2021, its revenue is expected to stay flat as its earnings to jump 11% on cost-cutting measures, buybacks, and easier year-over-year comparisons.

The valuations and dividends

Microsoft trades at 33 times forward earnings and pays a forward dividend yield of 1%. HP trades at just 7 times forward earnings and pays a much higher forward yield of nearly 4%.

Value-seeking investors might be impressed by HP's low valuation and high yield, but the stock is cheap for obvious reasons: Its growth is anemic, its printing unit is still bleeding, and it's under the leadership of a new CEO who seems more interested in big buybacks than rejuvenating its sluggish businesses.

Meanwhile, Microsoft deserves its premium valuation because its core businesses are still firing on all cylinders. Its cloud businesses still have plenty of upside potential, and the upcoming launch of the Xbox Series X and new Surface devices will strengthen its hardware business. In short, Microsoft will likely remain a better buy than HP for the foreseeable future.