For months, economists have been warning that a recession may be coming. But when, exactly, it's likely to begin is still uncertain.

Around 58% of economists believe we'll face a recession at some point in 2023, according to a recent survey from the National Association for Business Economics. One-third of the survey respondents expect it to begin between April and June, while one-fifth predict it will start around July to September.

To be clear, nobody knows for certain whether we really will face a recession. But if an economic downturn is looming, is it safe to invest right now? Here's what history says.

What history shows about recessions

There's good and bad news about recessions. The bad news is that they're unavoidable. The stock market and economy can't keep growing forever, so we're bound to face some sort of downturn eventually.

The good news, though, is that even the worst recessions are only temporary -- and the good economic times far outlast the slumps.

For example, the financial crisis of 2008 was the longest recession since the Great Depression, lasting around 1.5 years from December 2007 to June 2009. Yet the subsequent bull market went on for more than a decade, from 2009 to 2020.

^SPX Chart

^SPX data by YCharts

In the early 2000s, the recession triggered by the dot-com bubble burst lasted from March to November 2001. Once stock prices bottomed out, though, the following bull market lasted until 2007. 

If you're nervous about investing right now, that's understandable. But over the long run, recessions are merely a blip on the radar, and the market will experience far more good days than bad.

How to protect your investments

Even if recessions are only temporary, they're still tough to stomach. But the right investments can help calm your nerves and keep your money safer, regardless of what the future holds.

The best stocks are those from companies with solid underlying business fundamentals. These organizations have healthy financials, a competent leadership team, and a competitive advantage in their industries, for example.

The stronger the company, the more likely it is to pull through a recession. And the more of these stocks you have in your portfolio, the better your chances of surviving an economic downturn, too.

When in doubt, it never hurts to opt for an index-tracking fund, such as an S&P 500 ETF. These types of investments, such as the Vanguard S&P 500 ETF (VOO -0.22%), track the index itself and mirror its performance.

Because the S&P 500 itself has always recovered from recessions in the past, it's far more likely to rebound from future downturns as well. If you're looking for a safe investment that's all but guaranteed to pull through periods of volatility, you can't beat an S&P 500 ETF.

What to do right now

It may not feel like it, but now is one of the best times to invest. Stock prices are lower than they've been in a long time, and it's a smart time to buy the dip and invest at a discount.

If we face a recession, the market may fall further. But it will recover eventually. By investing during the low points, you'll be in a perfect position to take advantage of the upswing. No matter what happens in the near term, remember that better days are ahead.

In 2008, at the height of the Great Recession, Warren Buffett wrote an opinion piece for The New York Times. While all recessions are different, his advice can be reassuring in times like these. He wrote: 

I can't predict the short-term movements of the stock market. What is likely, however, is that the market will move higher, perhaps substantially so, well before either sentiment or the economy turns up. So if you wait for the robins, spring will be over.

A recession may be looming. But by investing in quality stocks and keeping a long-term outlook, your investments are far more likely to pull through.