Student loans can be a real drag on your finances. The average class of 2017 grad owes more than $39,400 in education debt and spends $351 a month to pay off student loans.

When reducing loan debt is your focus, saving for retirement can easily slip to the back burner. According to an Aon Hewitt survey, 51 percent of workers who have student loan debt are contributing no more than five percent of their salary to their employer’s retirement plan. If that’s you, the result could be a savings shortfall once you’re ready to retire.

On the other hand, making retirement your priority could help you build the nest egg you need, but mean that you risk still being indebted in your later years. An estimated 2.8 million seniors age 60 and older owe student loans, with an average balance of $23,500.

Finding a way to balance saving for retirement with paying down student debt can be tricky, but it’s not impossible. It begins with having the right strategy.

A graduation cap on money to pay off student loans.

Start with Your Budget

A budget is a written plan for how you spend your money each month. When you have student debt, it’s a tool you can’t afford to be without.

If you don’t have a budget, making one is relatively simple. Start by listing all your expenses for the month. That includes recurring expenses, such as rent, utilities and student loan payments, as well as extras, such as eating out or new clothes. Total them up, then subtract that number from your income.

Ideally, you should have money left over each month. If you don’t, you need to go back to the drawing board and figure out what you can cut to give yourself some wiggle room. Once you’ve done that you need to decide what to do with the extra cash.

There are a few different options. You could put all of it toward your student loans. While that could get you out of debt faster, there’s a downside where your retirement is concerned. Waiting five or 10 years to start saving could put you at a disadvantage in the long run.

Another option is to use anything extra you have to fund your retirement savings. This won’t get your loans paid off faster, but it can give you a solid foundation for the future. Here’s an example.

Say you’re 25 years old and have $400 a month you can put toward your loans or retirement. If you were to save that $400 from age 25 to age 65 in a Roth IRA earning a seven percent return, you’d have over $1 million for retirement.

What if you take that money and put it toward your loans instead? Let’s say it takes you seven years to pay off student loans, and once you turn 32 you start saving that same $400 in a Roth. The delay doesn’t seem like much, but it shrinks your retirement savings to just over $610,000. Waiting those seven years would cost you nearly half of your total nest egg.

At the end of the day the value of the compound interest you could be losing out on by waiting to save could easily outweigh any money you’re saving by paying off your loans sooner. If you want to make progress on both your loans and saving, you could split the difference and use anything extra you have to fund both goals.

Be Strategic About Where You Save

If you’re working on saving for retirement while also paying down student loans, it’s important to save in the right places. Your employer’s retirement plan is a good place to start, especially if your company offers a matching contribution.

At the very least you should be saving enough to qualify for the match, if there is one. Many plans allow you to increase your contribution rate automatically each year, so it may be worth it to see if that’s an option. Aim to time your increases with your annual raise, so there’s no noticeable difference in your take-home pay.

If you’re already saving enough to get the match—or don’t have a retirement plan at work—an IRA is the next best bet. When you’re younger and haven’t moved into your peak earning years yet, a Roth IRA may be preferable. A Roth IRA doesn’t allow you to deduct your contributions like a Traditional IRA does, but when you retire you can withdraw money from your account tax free.

Look Beyond Retirement

While saving for retirement and getting rid of your student loans are important financial goals, they’re not the only things you should be working toward. Remember that you also need a cushion of liquid savings in case of emergencies. If you want to buy a home someday you’ll need to think about planning a down-payment fund, the sooner the better.

Keeping your other financial goals in perspective and regularly reviewing your budget are good habits to develop as you grow your retirement savings and shrink your student loan debt.

Compare Popular IRA Providers