If you have a little extra cash at the end of each month, it's wise to put it toward long-term financial goals. But how do you know which goals should come first? Is it more worthwhile to put your extra money toward your mortgage or your retirement fund?

The short answer is that they're both good options. About 36% of American households have a mortgage, and of those people, the average household owes about $168,000. And in regards to retirement planning, the median amount working-age American families have saved is just $5,000 -- not even enough to see them through one year in retirement. In other words, a little extra cash would benefit most people in either of these situations.

But if you only have a couple hundred dollars (or less) to spare each month, where will you get the most bang for your buck?

bag filled with cash

Image source: Getty Images.

Investing in your home versus investing in your future

Before you start paying off your mortgage or saving for retirement, you should build a solid emergency fund to cover six months' worth of expenses. And if you have a 401(k), it's also a good idea to contribute enough to get your employer's full match, because that is essentially free money, and you'd be foolish to turn it down.

After you have those basics covered, it's time to compare the pros and cons of paying off your mortgage and saving for retirement.

The best time to start aggressively paying off your mortgage is in the first few years, because at this point, most of your payments are going toward interest and not the principle. So by paying as much as you can right away, you can pay less in interest overall. However, because the amount you pay in interest is tax-deductible (assuming you qualify and itemize your deductions), paying interest isn't quite as terrible as it may sound.

At the same time, it's also wise to start investing for retirement as early as possible in order to take full  advantage of compound interest. Investments tend to gain value exponentially, so every year you delay saving for retirement will set you back to a disproportionately large degree. Money invested now has much more value than the money you'll invest five or 10 years from now.

This is where interest rates come into play. If you have an unusually high interest rate on your mortgage, then it makes financial sense to pay down that debt first. Because the stock market has historically gained about 7% per year, if your interest rate is higher than that, then you're likely paying your lender more than you could earn by investing the money instead.

A look at the numbers

Say, for example, you just took out a 30-year mortgage of $150,000 and are trying to decide whether to put your extra money toward the mortgage or your retirement savings. Also assume an interest rate of 4.5% per year on your mortgage, a 25% federal tax rate, and an 8% state tax rate. Finally, let's say that your interest payments are tax-deductible, so your after-tax rate is 3.105%.

Here's what your financial future could look like based on how fast you pay off your mortgage:

Mortgage Payoff Term Monthly Payment Total Interest Paid
30 $760 $123,609
25 $833 $100,124
20 $948 $77,754

If you pay only the minimum mortgage payments over the course of 30 years, you'll end up paying a grand total of $123,609 in interest alone. However, if you bump up your monthly payment by about $200 and pay off your mortgage 10 years early, you'll pay only $77,754. In other words, you could save about $46,000.

Now let's assume that you only make the minimum mortgage payments and instead put that extra $188 per month into your retirement savings, rather than your mortgage payment. Assuming you start with $0 in savings and earn an average of 7% per year on your investments, in 20 years you'd wind up with about $96,000 in your retirement account -- about $45,000 in contributions and $51,000 in earnings. That only puts you slightly ahead of the $46,000 in interest you'd save by paying off your mortgage 10 years early. However, if you continued to invest that $188 per month until the end of your 30-year loan term, your retirement savings would swell to $221,000 -- that's $153,420 in earnings on top of your $67,680 investment. All in all, you'd come out $30,000 ahead by investing your spare cash, rather than using it to pay off your mortgage 10 years early.

To sum it up, you can save more money in the short term by paying down your mortgage faster, but in the long term, you'll likely come out far ahead by saving more for retirement. In any case, you certainly shouldn't completely neglect your retirement savings while you pay off your mortgage. Even if you choose to repay your loan on an accelerated schedule, make sure you save something for retirement while you have time -- and compound interest -- on your side.

How to calculate your own numbers

Ready to find out which option is right for you based on your unique situation? First, use a compound interest calculator to determine how much your retirement savings can grow over time. Then use a mortgage calculator to see how much you'll be paying in interest over the course of your loan.

After you compare these numbers, you'll have a better idea of how much you can earn on your investments compared to how much you can save in interest payments.

Every situation is different, so there's no one-size-fits-all answer as to whether you should use your extra cash to pay down your mortgage or save for retirement. But by creating a plan and calculating where your money will be best spent, you're setting yourself up for future financial success.

The Motley Fool has a disclosure policy.