A recession can be a very stressful period. Some people lose their jobs, budgets tighten, spending decreases, markets get volatile, and investors get nervous as they see a portion of their portfolios apparently begin to evaporate.

Some investors panic and make the mistake of selling their stocks during a recession and lock in losses. But others know that recessions are a time to buy stock as they offer access to lower stock prices that can lay the foundation for tremendous returns once the economy recovers. The key to executing that last action successfully is to focus on buying stock in strong companies that can survive periods of soft demand and high unemployment.

No one knows when a recession will hit, but we do know there have been 18 recessions over the last century, so it's likely to happen again. The wise investor will do what it takes to be prepared for this eventuality. 

Here are three relatively safe tech stocks that represent strong companies and I would buy them during the next recession.

A young couple sitting at a table with pieces of paper and a laptop sitting in front of them.

Image source: Getty Images.

1. Microsoft

Microsoft's (MSFT -1.02%) software is widely used by both consumers and businesses. There are more than 1 billion active devices that run on Windows 10, and the company reported that Office 365 usage was higher than ever last year. Microsoft is also a leader in helping organizations shift to digital technologies, where Microsoft Azure is emerging as a strong second-place competitor to Amazon (AMZN -2.60%) in the cloud services market. 

Even with Microsoft's established brand and customer base, the company is not immune to dips in demand caused by recessions. For example, spending on technology could decline during a weak economy, pressuring Microsoft's revenue growth. But it's worth noting that spending on cloud services and infrastructure continued to increase during the pandemic as Microsoft benefited from the remote work trend, and CEO Satya Nadella believes the growing demand for digital services is just getting started. 

"Over a year into the pandemic, digital adoption curves aren't slowing down. They're accelerating, and it's just the beginning," Nadella stated in the fiscal Q3 2021 earnings report. 

Microsoft estimates that 50 billion new devices will come online by 2030, and that could translate to tremendous growth in revenue for Azure -- not to mention demand for Microsoft's popular software tools like Word and Excel, which the company bundles as a subscription service with Microsoft 365. 

Microsoft is a financial fortress. It ended the most recent quarter with a net cash position of $73 billion, and it generated $54 billion in free cash flow over the last four quarters. With that much cash sitting on the balance sheet and more coming in every year, Microsoft would likely be able to continue increasing its dividend payout even during challenging business conditions. The stock currently pays a dividend yield of 0.87%, representing a cash payout ratio of 30% relative to free cash flow. 

The secular demand trend for digital enterprise software services should keep Microsoft growing over the long term, and its rock-solid financial position should provide a cushion to the stock price in the event of another market correction.

2. Amazon

Amazon provides essential services through its grocery businesses (Amazon Fresh and Whole Foods). It's also the leader in cloud services with its Amazon Web Services business. But serving the consumer is still its bread and butter. The annual Prime Day (usually held in the summer months) has become just as big as Black Friday, and the event provides Amazon an opportunity to reach new customers with its Prime membership program.

Amazon generated $419 billion in revenue over the last year, and it continues to grow very fast for a large business. Revenue has doubled over the last three years, with growth accelerating during the pandemic. 

Still, not all recessions may turn out as well for the e-commerce giant. Amazon sells a lot of consumer electronics and other nonessential items that people may not purchase during a prolonged recession.

On the other hand, many customers would likely stick with their Prime memberships to enjoy movies, music, and free grocery delivery. Amazon now has more than 200 million loyal patrons through Prime, and the company is seeing Prime engagement continue to rise, providing a stickier ecosystem of services for consumers. 

Like Microsoft, Amazon generates a substantial amount of free cash flow to continue investing in the future no matter what the economy is doing. Over the last four quarters, Amazon generated $26.4 billion in free cash flow. Most of its operating profit comes from cloud services, where Amazon Web Services made up 11.6% of total revenue on a trailing-12-month basis. 

While Amazon doesn't pay a dividend, that's sort of a good thing at this juncture, because it means management is still seeing tremendous opportunities to invest in building more fulfillment warehouses and its own transportation fleet to meet growing demand. This is a top growth stock to consider buying when the next market correction strikes.

AAPL Chart

AAPL data by YCharts

3. Apple

Apple (AAPL -1.16%) is one of the most iconic consumer brands in the world. Sure, sales of its pricey aluminum-clad devices would likely suffer if people didn't have money to spend, but the company also has a growing revenue stream from subscription services, and it generates plenty of cash to continue paying a regular dividend to shareholders. 

While iPhone revenue dropped 3.3% in fiscal 2020 (which ended in September), Apple saw sales of its Macs, iPads, and wearables grow at healthy rates during the pandemic. And since the iPhone 12 launched in the fall, Apple's revenue growth has accelerated to 53% year over year in the quarter that ended in March. 

Most importantly, Apple's installed base of active devices continues to hit new records. The new Macs and iPad Pros featuring Apple's new M1 chip have rejuvenated sales of these products -- a great sign of Apple's brand strength in the marketplace.

The stock currently pays a dividend yield of 0.67%, with a current cash payout ratio of 15.7% of trailing free cash flow. While shares are up 50% over the last year, the forward price-to-earnings ratio is roughly in line with that of the broader market at 24 times expected earnings. At this valuation level, there might be more room for upside in the near term, especially if the iPhone upgrade cycle remains stronger than investors expect.

During the earnings call in late April, Apple CEO Tim Cook noted that 5G penetration is "still low at this point," with a lot of upgrades still in front of the company.

AAPL PE Ratio (Forward) Chart

AAPL PE Ratio (Forward) data by YCharts

In the event of another recession, investors can feel confident that Apple's business won't be starving for funds to keep cranking out new products -- and most importantly, keeping its employees happily on the payroll.

Apple ended the fiscal second quarter with net cash of $87 billion on the books. While management is working toward a cash-neutral position on its balance sheet, Apple continues to gush more every year, with trailing free cash flow topping $90 billion.

The key takeaway

Shares of leading tech stocks that generate substantial amounts of free cash flow will be relatively safe bets during a recession. Microsoft, Amazon, and Apple possess these traits in spades. These companies are dominant sector leaders that should reward investors for years to come.