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? And 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? 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 with just an extra couple hundred dollars per month: 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, what if you only made the minimum mortgage payments and put that extra $200 per month toward your retirement savings instead? Assuming you start with $0 in savings and earn an average of 7% per year on your investments, here's how much you can expect to save up over 20, 25, and 30 years. Years Total Amount Contributed Total Amount Earned 20 $48,000 $102,081 25 $60,000 $157,494 30 $72,000 $235,212 So if you're 35 years old, are planning to retire in 30 years, and just took out a 30-year mortgage, you can earn substantially more by investing than by paying off your mortgage early. If, however, you're 45 years old, you plan to retire in 20 years, and you have a 30-year mortgage, you'll end up paying more in interest than you'd be earning on your investments in that time. In most cases, though, you'll come out ahead by saving for retirement before paying off a mortgage. While it's never a bad idea to pay down your debts, it's best to save for retirement while time is on your side -- if you wait too long, your potential gains will significantly decrease. 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 $16,122 Social Security bonus most retirees completely overlook If you're like most Americans, you're a few years (or more) behind on your retirement savings. But a handful of little-known "Social Security secrets" could help ensure a boost in your retirement income. For example: one easy trick could pay you as much as $16,122 more... each year! Once you learn how to maximize your Social Security benefits, we think you could retire confidently with the peace of mind we're all after. Simply click here to discover how to learn more about these strategies.The Motley Fool has a disclosure policy.