Q: I finally have a little extra money in my bank account every month. Should I put it toward my student loans or save it in an emergency fund?

A: There are golden rules in the personal finance world, and this is one of them: An emergency fund is absolutely necessary, even if you have a big student loan payment (and even if you live in a city where cocktails costs $15). An emergency fund is handy in an infinite number of scenarios: sudden job loss, car repairs, unexpected dental bills … the list goes on.

In fact, when you have no savings, everything unexpected is an emergency. A dedicated bank account will let you pay for sudden expenses without putting them on a credit card, which could rack up 15% or more in interest over time.

I advise building an emergency fund before paying any extra toward your loans. Continue making your minimum loan payments to keep them in good standing.

The amount you’re comfortable putting into your emergency fund is up to you. Here’s a three-step plan to get your emergency fund going and keep your student loans on track.

Step 1: Decide on an emergency-fund comfort level

First, take stock of your monthly expenses. Look back at your bank statement and credit card transactions for the previous month to see how much you spent on rent, food, bills, transportation and entertainment. Then decide how many months’ worth of expenses you’d like to have as a cushion.

Say you spend $2,500 a month on average. Ideally, you’d keep at least three months of expenses, or $7,500, in your emergency fund. If you can count on support from other sources, such as your parents or spouse, that amount might be enough. If you’re on your own, six months or more of expenses would be a better target.

But anything — even $500 or $1,000 — is better than nothing.

Step 2: Make a plan to build up your emergency fund

Once you know how much you want to save, make a plan to do it. Very few of us 20-somethings have an extra $7,500 or more lying around, so it’s OK to take several months to sock away the money you want to keep in your emergency fund.

  • Set up an automatic transfer from your checking account. I had to rebuild my savings account when I got my first full-time job out of grad school. I realized the only way I’d make it happen would be to automate the saving, so I linked my bank accounts and created a fund transfer from my checking to my savings account right after each payday. Now I barely miss the amount I contribute to my emergency fund, since I don’t have the opportunity to spend it. I’ll stop the transfer when I hit my goal.
  • Put away big chunks when you get big chunks. Think of your emergency fund first when you get a bonus or a raise at work, you get your tax refund or you get cash back as a perk for using your credit card. It’s no fun at first to put extra money toward savings, but when you need it you’ll be glad you did.
  • Consider your emergency fund untouchable once it’s full. Only dip into it to pay for true emergencies, and replenish it as soon as you can if you use it. Create a separate savings account if you want to save for a vacation, a car or another big expense that doesn’t qualify as an emergency.

Step 3: Once you hit your goal, put the same amount toward your student loans

There’s an added advantage to setting up an automatic transfer to your emergency fund: You’ll get used to not having that amount to spend. Say you’ve been putting $500 a month toward savings. When your emergency fund is at a level you’re happy with, start contributing that $500 toward your student loans instead.

You’ll save the most money in the long run by directing the payment toward your highest-interest loans first. But if it would motivate you to first pay off your smaller loans completely, start with those.

Call your student loan servicer and ask the company what your options are for paying more than the minimum each month. Many servicers will let you set up a direct recurring payment from your checking account for a new total amount: $500 if your minimum payment is $300, for instance. Or you can manually pay extra on the servicer’s website. If you want to pay off specific loans first, you mgiht have to mail or email instructions to the company. The Consumer Financial Protection Bureau (CFPB) has a helpful sample letter you can use as a template.

It’s exciting to have the flexibility to pay down your student loans faster; just make sure you have some savings to fall back on in case an emergency hits. Next time, we’ll look at what to do when you’re ready for another adult financial milestone: I’ve never had a credit card. Should I get one to build credit?

More from NerdWallet: