The chances of a recession appear to be rising. Just a couple of months ago, economists surveyed by Bloomberg estimated a 30% probability that the U.S. would enter a recession within the next year. Last week, Bank of America predicted that a relatively mild U.S. recession will probably begin later this year.

This increasing gloom is almost certainly causing many investors to think about where to put their money if a recession is on the way. There are plenty of good alternatives. But these exchange-traded funds (ETFs) could be your best way to invest during a recession.

Look to Uncle Sam

What do investors want the most during a major economic downturn? A safe haven. It's hard to find a better safe haven than U.S. Treasury bonds. When you buy these bonds, you're lending money to the U.S. government. If the day ever comes when Uncle Sam can't pay you back, the world is in big trouble. 

Treasury bonds aren't just good investments during a recession because they're safe havens, though. In the midst of a recession, the Federal Reserve frequently buys U.S. Treasury bonds as part of a strategy to lower interest rates and spark an economic rebound. This buying causes the prices of the bonds to rise. 

Investing in ETFs that own U.S. Treasury bonds gives you greater flexibility than buying the bonds themselves. Blackrock's iShares family of Treasury bonds, in particular, allows investors to focus on different maturity lengths for the government bonds.

The heaviest-traded of these ETFs is the iShares 20 Plus Year Treasury Bond ETF (TLT -0.99%). As its name indicates, this fund owns U.S. Treasury bonds with maturities of 20 or more years.

For investors who don't want maturities quite that long, the iShares 10-20 Year Treasury Bond ETF (TLH -0.79%) is an alternative. Or you could go with shorter maturities with the iShares 7-10 Year Treasury Bond ETF (IEF -0.46%), the iShares 3-7 Year Treasury Bond ETF (IEI -0.22%), or the iShares 1-3 Year Treasury Bond ETF (SHY -0.04%).

Lessons from two recessions

There have only been two U.S. recessions since these iShares ETFs launched -- the Great Recession of late 2007 through mid-2009 and the brief coronavirus-caused recession of 2020. However, we can learn some lessons from how the ETFs performed during those two recessions.

Let's first look at the Great Recession, which was one of the most severe recessions in U.S. history. All of the iShares U.S. Treasury ETFs held up quite well during this difficult period while the S&P 500 crashed. (Note: The shaded period indicates when the U.S. economy was in recession.)

TLT Chart

TLT data by YCharts

Note that the ETFs with the longest maturities went up the most as the S&P 500 approached its lowest point. However, by the end of the recession, the shorter-maturity iShares 3-7 Year Treasury Bond ETF was on top. Throughout the period, the iShares ETF with the shortest maturity was the least volatile.

Now, let's fast-forward to the coronavirus recession of 2020. Again, all of the iShares U.S. Treasury ETFs trounced the S&P 500's performance.

TLT Chart

TLT data by YCharts

The iShares 1-3 Year Treasury Bond ETF was just as steady as it was during the Great Recession. However, this time the longer-maturity ETFs performed the best throughout most of the brief recession.

Expectations about interest rate fluctuations largely explain why these U.S. Treasury ETFs perform differently. When investors believe that interest rates will decline, the longer-term ETFs tend to rise more than shorter-term ETFs do.

Beyond the recession

These U.S. Treasury ETFs could handily beat most stocks if the U.S. economy indeed enters a recession later this year or in 2023. They truly could be your best way to invest during the period.

Keep in mind, though, that recessions usually don't last all that long. The average U.S. recession since 1900 has lasted around 15 months. Milder recessions can be even shorter. Investors should, therefore, think about the longer term beyond the recession.

Five years after the end of the Great Recession, the S&P 500 was beating the performance of all of the iShares Treasury ETFs. It took less than eight months after the end of the 2020 recession for the S&P to blow past these ETFs. Treasury bond ETFs are great way to invest during a recession, but stocks are likely to give you better returns over the long run.