My friend Bob (not his real name, sorry) tapped his IRA earlier this year to make some repairs around the house he'd been putting off for a while. And the reason he kept delaying those repairs until he no longer could was that he didn't have the money -- at least not in the bank.

Bob's been contributing to an IRA for about a decade. But while he's been pretty diligent in contributing to his retirement plan, he's been neglecting his near-term savings. And recently, it cost him.

A person at a laptop holding their head.

Image source: Getty Images.

See, Bob's not old enough to withdraw from a retirement account without a penalty. So he lost 10% of the sum he took out to cover his home repairs. But that's not even the worst of it.

The problem with raiding a retirement plan

It's never fun to face a financial penalty, whether it's a fee for paying a bill late or an IRS penalty for underpaying your taxes. Similarly, it's not a good thing to lose 10% of a retirement plan withdrawal due to taking it early.

But that's not even the main reason it can be so problematic to raid a retirement account ahead of schedule. A potentially even bigger problem is that when you remove funds from an IRA or 401(k), they no longer stay invested. And losing out on that growth could leave you with a shortfall.

Let's say you take a $10,000 IRA or 401(k) withdrawal at age 45 because you don't have cash on hand to cover an emergency expense. Not only will you lose $1,000 off the bat, but you'll lose out on many years of gains on that $10,000.

If your retirement investments generate an average annual 8% return, which is a hair under the stock market's average, and you take a $10,000 withdrawal when retirement is 20 years away, you'll end up short about $46,600. That's way worse than losing $1,000 to a penalty.

Long-term financial security starts with a solid emergency fund

If you have cash reserves to tap when unplanned expenses arise, you won't have to raid your IRA or 401(k) plan every time you need money. That could, in turn, make it possible for your nest egg to keep growing nicely.

As such, while it's a good thing to save for retirement, you should actually make building an emergency fund your financial priority. And, ideally, you should aim for enough money in the bank to cover three to six months of essential bills.

Meanwhile, Bob's going to change his ways and start funneling more money into a regular savings account. And if you've been taking a similar approach to saving as him, you may want to do the same.

One final thing: If an emergency expense arises that you can't pay for out of savings and you feel forced to tap your retirement account, before you do that, see if it's possible to borrow against your long-term savings instead. Many 401(k) plans allow for this, though you usually won't have this option with an IRA.

To be clear, 401(k) loans can be risky, because if they aren't repaid, they're considered withdrawals and are penalized accordingly. But at least this way, you're not removing a sum from your long-term savings that you have no intention to pay back.