In 2022 and 2023, the Federal Reserve raised interest rates numerous times in an effort to cool inflation. That's resulted in higher borrowing costs for consumers, which isn't a great thing.

But on the plus side, higher interest rates mean that savers can now earn more in a CD. And that might seem like a hard opportunity to pass up.

Many banks are offering CDs with yields between the 4% and 5% mark, depending on term. And the nice thing about a CD is that your principal deposits are protected provided that you bank at an FDIC-insured institution and you limit your deposit to $250,000 (or $500,000 if there's a joint owner on your account).

Because CD rates are so attractive right now, you may be considering opening one for the purpose of saving for retirement. But that's not actually your best bet.

A person at a laptop.

Image source: Getty Images.

You might earn a lot more money in an IRA or 401(k)

It's true that CDs are paying generously right now. But the Fed is expected to start cutting interest rates as early as later this year. And from there, CD rates may start to fall.

Now you could try to lock in a longer-term CD and snag somewhere in the vicinity of a risk-free 4% return on your money. But then what happens when that CD comes due in, say, five years and rates are considerably lower? From there, you may have to shift to a strategy that centers on investing anyway -- so you might as well get started now.

See, in the long run, the stock market is likely to deliver a much higher return on your money than CDs. So when you're investing for a far-off goal, like retirement, a stock portfolio that you build in an IRA could be a better bet. Similarly, a 401(k) that's broadly invested in stocks could offer a lot more growth than a CD, or a CD ladder.

Case in point: Let's imagine you have $20,000 to sock away for the long haul today. We can be optimistic and say that you'll snag a 4% return on a CD for the next 30 years, even though that's unlikely. If so, your $20,000 will be worth about $65,000 in three decades.

On the other hand, let's say you invest your $20,000 in stocks, whether by opening an IRA or buying the right funds in a 401(k). Let's also assume you're able to generate an average annual 8% return on those investments, which is a bit below the stock market's average. In 30 years, your $20,000 will be worth $201,000. That's more than three times the balance you're looking at when you stick to CDs.

Think about the tax consequences, too

Another hiccup you might encounter if you invest for retirement with CDs? The interest you earn is taxed as ordinary income every year, which means it's subject to your highest marginal tax rate.

Meanwhile, if you fund a traditional IRA or 401(k) plan, your contributions get to go in tax-free. Then, gains in your account will be tax-deferred so that you aren't taxed until you take withdrawals.

Another option is to save for retirement in a Roth IRA or 401(k). With these accounts, you forgo an initial tax break on your contributions, but you'll never pay taxes on your investment gains.

All told, a CD could be a good option if you're saving for a somewhat near-term goal. It could even be a good option if you're nearing retirement and want to keep some of your money in cash to avoid the risks that come with investing. But as a general strategy, you're better off saving for retirement throughout your career by investing in an IRA or 401(k) than by limiting yourself to CDs.