There are plenty of reasons it's hard to save for retirement. It seems there are always other expenses that take priority, from the mortgage to car payments to shopping for groceries, and retirement gets shoved to the back burner.

But there's one surprising expense that has nearly a third of baby boomers struggling to save for retirement: student loans.

Concerned older couple looking at bills

Image source: Getty Images.

Thirty-one percent of baby boomers say their student loan debt is hindering their ability to prepare for retirement, according to a survey from AARP and the Association of Young Americans. Furthermore, of those baby boomers who carry student loan debt, 50% owe $30,000 or more -- which can make saving for retirement even more of a challenge.

However, carrying debt isn't an excuse not to save for retirement. If you're a baby boomer who is still paying down loans, if you wait to save for retirement until your debt is completely paid off, you'll run out of time and risk having nothing at all saved by the time you retire. The good news is that you don't have to decide between paying down debt and saving for retirement because it's possible to do both at the same time -- here's how.

Tackling debt and retirement

If you're nearing retirement age, you can't afford to wait another second to start saving. Even if you have a decade or two left before you're ready to retire, it's still crucial to start stashing money away as soon as possible because with each passing year, you're missing out on valuable time you'll never get back.

While it's tougher to save for retirement when you still have thousands of dollars in debt to pay off, it's not impossible. Even if you don't have a lot of extra cash lying around, it's still possible to put money toward both of these goals at the same time.

For example, say you're 50 years old with $30,000 in student loan debt and $20,000 in your retirement fund. You're paying $300 per month toward your debt, and right now you're not saving anything for retirement. You also have an extra $250 per month that you can put either toward your debt or into your retirement fund.

You have two options: Pay $300 per month toward your debt and $250 per month toward retirement, or pay $550 per month toward your debt and nothing toward retirement until the debt is completely paid off.

Let's look at scenario one first. If you're paying $300 per month toward student loans at, say, a 5% interest rate, you'll pay that debt off in around 11 years, paying around $8,900 in interest during that time. Then, if you're also contributing $250 per month toward your retirement goals, assuming you're earning a 7% annual return on your investments, you'll have around $80,800 saved after that roughly 11-year span. If you were to then start saving the full $550 per month once your debt is paid off, after around nine years (when you'd be turning 70), you'd have more than $250,000 saved. Subtract the $8,900 you paid in interest, and your net savings would amount to roughly $241,500.

In scenario two, you're paying off all your debt first without touching your retirement fund. If you're paying $550 per month toward your loans at a 5% interest rate, you'll have that debt paid off in just over five years, paying $4,100 in interest. Meanwhile, the money in your retirement fund will continue to grow even if you're not making additional contributions, and in five years, assuming you're earning an annual 7% return on your investments, you'll have accumulated around $28,000. If you then start saving $550 per month for another 15 years (until you turn 70), all other factors remaining the same, you'll have around $243,000 in total. Subtract the $4,100 in interest, and you have a net total of around $239,000.

How employer matching contributions change the game

While you'll still come out slightly ahead by saving for retirement and paying down debt at the same time (ending up with around $241,500, compared to $239,000 by tackling each goal separately), if your employer offers matching 401(k) contributions, it's a smart idea to be contributing as much as you can as early as you can to earn that extra money.

Using the numbers from the last example, let's add one more assumption: that your employer matches half of your contributions up to $125 per month. In the first scenario, you're contributing to your retirement account from day 1, and that means you're getting that extra $125 a month longer. Your net savings at age 70 would be almost $303,000. However, in the second scenario, you don't start getting that $125 until your debt's paid off, and that would leave you with less than $277,000 in retirement.

It may feel as if there's never enough money to go around, and that other bills are more important than retirement. But your golden years will creep up quickly, and if you don't start saving as early as possible, you may miss your chance at enjoying a comfortable retirement.

The Motley Fool has a disclosure policy.