Whether a recession is coming or not (and the U.S. Federal Reserve thinks it is), buying shares of companies that can survive any economic environment is obviously an excellent idea. Since investors have a relatively long time horizon, they will inevitably encounter headwinds related to economic cycles, so it's important to build a portfolio with that in mind.

Thankfully, plenty of stocks on the market fit that profile. Let's consider two of them: HCA Healthcare (HCA -4.51%) and Visa (V -0.48%).

^SPX Chart

^SPX data by YCharts

1. HCA Healthcare

HCA Healthcare is one of the leading hospital chains in the U.S. Over the trailing-12-month period, the company's shares are up by 27%. Last year's bear market did little to slow the healthcare giant, even as it was still dealing with lingering issues related to the pandemic and economic troubles. For instance, inflation and an increased reliance on more expensive contract labor during the pandemic (hospitals needed workers to care for COVID-19 patients) led to increased expenses and a lower bottom line than HCA Healthcare would have reported.

There was also some uncertainty on the top line due to various surges of COVID-19 cases. Still, HCA Healthcare has performed relatively well even amid these challenges, both in terms of its financial results and on the stock market. The company's revenue increased 4.3% in the first quarter to almost $16 billion. Adjusted net earnings per share of $4.93 jumped by 19.7% year over year. That is a testament to the strength and resilience of HCA Healthcare's business.

While a recession could somewhat harm the company, medical services remain in relatively high demand even amid downturns. The company makes money based on occupancy rates and the services physicians order for their patients. People don't choose when they will be sick, need to see a doctor, or what kind of services will best suit them. Nor are these things on the top of the list of services to cut back on if a recession hits.

So you can expect HCA Healthcare's occupancy rates to remain somewhat stable and the company to navigate a recession relatively well. That's why HCA Healthcare is an outstanding stock to add to a well-rounded recession-ready portfolio. And due to the nature of its operations that will benefit from long-term trends such as the world's aging population, it is also a solid company to hold on to for a long time. 

2. Visa

Visa does not look like a typical recession-proof stock that offers necessary goods people can't go without. As one of the leading payment networks, the company risks seeing its payment volume and revenue suffer meaningfully if investors cut spending due to a tanking economy. But even so, a recession-induced slowdown would be a temporary issue for Visa. The company is at no serious risk of its business falling apart.

On the one hand, Visa's fundamentals are strong, as the pandemic years demonstrated. Visa's revenue and earnings have been on an upward trajectory despite the economic devastation caused by the outbreak.

V Revenue (Quarterly) Chart

V Revenue (Quarterly) data by YCharts

Second, Visa's business benefits from the network effect, with merchants and consumers on the company's platform increasingly attracting one another. This competitive advantage doesn't make Visa immune to headwinds, but it does ensure that it will remain a leading payment network provider even if there is a slowdown in economic activity.

Moreover, Visa still has an attractive long-term opportunity. That may seem counterintuitive since the company has been helping displace cash and check transactions in favor of credit for a long time. It has become one of the world's most recognizable brands, and millions worldwide use credit cards that bear its logo daily.

But there are still trillions of dollars spent on cash and check, according to the company. The long-term goal for Visa is to phase these out, grow its payment volume, and by extension, its revenue. While not ideal, a recession would be little more than a speed bump for Visa's financial results. And the strength of the company's operations should allow it to navigate an economic downturn better than most.

That's why investors can safely buy shares of the company even if there are challenging times ahead.