If you've listened to any pundits, analysts, or economists, you know by now that there is a good chance the U.S. economy will tip into a recession either next year or in 2024.

How severe that recession will be is anyone's guess. After the Federal Reserve just conducted four consecutive 0.75 percentage-point interest rate hikes, investors are finding themselves in uncharted waters, especially as the Fed also unwinds its massive balance sheet. 

That said, investors should prepare for what is to come. Legendary investor Warren Buffett, whose company Berkshire Hathaway has widely outperformed the broader market over the last seven decades, has seen a recession or two in his day and has the experience many retail investors lack. Here's Buffett's advice for investing during a recession.

Think long-term and invest in smart assets

Timing anything in the stock market can be quite difficult, and that includes recessions. It's also quite possible a recession will occur before anyone knows and won't be declared until it is well underway or over.

Warren Buffett.

Image source: Motley Fool.

Recessions also happen more than you might think; having one every decade is not unheard of. That means recessions are often part of investing, and if you are investing long term, you should expect to run into one sooner or later.

Buffett has always advised investors to keep a long-term outlook in mind because short-term volatility and earnings struggles are quite typical. If you invest in a company with strong fundamentals, it will likely improve and drive record earnings five or 10 years down the line.

Still, this doesn't mean you can't help yourself by investing in smart assets. Buffett likes what he refers to as "productive" assets, like farms and real estate, which are tangible and generate lots of cash. Buffett has also advised people not to make things more complicated than they need to be. For most investors, simply investing in an index fund tied to the S&P 500, which has a track record of performing well long term, is really all they need.

Think opportunistically

Despite some of his more conservative advice, Buffett has always advised investors to look for opportunities during a recession. Be "fearful when others are greedy, and greedy when others are fearful," the Oracle of Omaha has famously said.

And his advice makes sense because all recessions are temporary in nature and have always been followed by new market highs eventually. Recessions offer investors rare chances to buy stocks when they are at lows and trading at cheap valuations and then reap the long-term rewards.

Buffett has followed his own advice many times before. Take Bank of America, Berkshire Hathaway's second-largest position in its large equities portfolio. Buffett first invested in what is now America's second-largest bank by assets in 2011, getting $5 billion of preferred shares and stock warrants, allowing Berkshire to purchase hundreds of millions of shares of Bank of America's common stock at $7.14 per share.

Fast forward to the present: Shares of Bank of America trade for more than $32 per share -- and that's after the stock is down close to 30% this year.

Heed Buffett's advice

With a potential recession looming, it can be hard to stay calm while in the moment, but do your best to follow Buffett's advice.

If you've done really good due diligence on a stock, but the market has sold it off intensely this year, stay the course if you still feel good about it. Chances are it will bounce back.

If you have some cash to deploy and see some really good opportunities, don't be afraid to go for it. Also, don't be afraid to admit you are in over your head, and instead of individual stocks, put cash into index funds. Long term, these will likely serve you well.

Lastly, always remember that recessions, while painful at the time, have always been temporary and followed by new market highs. Stay positive and keep the faith.