When it comes to your financial health, one important factor can affect your short-term and long-term finances: the emergency fund.

An emergency fund is something that most people probably know they should have, but many don't actually have one. In fact, 7 in 10 baby boomers say they have less than $5,000 stashed in an emergency fund, according to the Insured Retirement Institute -- and that's a problem.

Man holding hundred dollar bills

Image source: Getty Images.

Now, some people may think that saving for retirement or paying monthly bills is more important than establishing an emergency fund. And while those other financial priorities are crucial, if you're not also putting money aside for a rainy day, a big unexpected expense could drain your bank account quickly.

While putting money toward an emergency fund is hard work and may seem to take money away from other priorities (like retirement saving) in the short term, it can actually help you save more in the long run -- here's how.

The consequences of skipping the emergency fund

If you don't have much spare cash after you pay all your bills each month, it's tempting to put whatever you do have toward bigger financial goals, like saving for retirement. And while it is always important to be saving for your golden years, you could be putting your retirement fund at risk if you don't have an emergency fund.

For example, say you're 40 years old with $50,000 in your retirement fund. You're saving $250 per month and earning a 7% annual return on your investments. At this rate you'll have around $460,000 in your retirement fund by the time you turn 65.

However, let's say you get hit with an unexpected medical expense of $5,000. You don't have an emergency fund, so to cover that bill, you take out a 401(k) loan. You pay back the $5,000 over two years at an annual interest rate of 5%, and over that time you end up paying around $265 in interest (which goes back into your account).

Meanwhile, you're not making any additional contributions to your 401(k), but the rest of your money continues to grow. So after two years, when the loan is repaid, you have about $56,800 in your 401(k). If you then go back to saving $250 per month for another 23 years (still earning a 7% annual return), you'll have around $429,000 saved total.

In other words, that $5,000 loan could end up costing you more than $30,000 in lost investment opportunity by the time you retire.

Balancing goals: Saving for rainy days and retirement

It's important to be saving for retirement and putting money aside into an emergency fund. And even if you don't have much money to spare, it is possible to do both at the same time.

Using the previous example, let's say you're 40 years old with $50,000 saved for retirement. But instead of putting the full $250 per month toward your 401(k), you put $150 toward retirement and $100 toward your emergency fund each month.

For your emergency fund, it's best to aim for enough money to cover at least six months' worth of expenses. If you typically spend, say, $2,000 per month, that's a goal of $12,000. If you're saving $100 per month, it will take roughly 10 years to reach that goal.

In the meantime, you're still contributing $150 to your retirement fund each month. After 10 years, assuming you're still earning an annual 7% return on your investments, you'd have around $123,000 saved. Then, once your emergency fund is sufficient, you go back to saving $250 per month for another 15 years, giving you a total of $414,000.

While that total isn't as much as you'd have saved by foregoing the emergency fund, keep in mind that you also have that $12,000 on hand in case an unexpected expense pops up. So if the car breaks down, your kid takes a tumble during football practice, or you lose your job, your retirement funds should remain untouched -- which will help them grow more over time.