A lot of questions come up in reddit.com/r/personalfinance about where should an individual place their money: into their debt or into their investments (retirement).
The TL;DR is that it is game of interest rates, risk, and time. How fast and for how long will investments and debt grow and with what level of risk? The higher the interest rate and the smaller the risk is where you should put your money. Time is also a consideration for the length of the debt or the investment horizon.
Disclaimer: The following is my thought process and how I work with my debt. Your situation will vary from mine. You should do what you think is best for you.
Personally, looking at my loans, they are at a weighted-average fixed interest rate of about 7.4%. They are risk-free, meaning I know that the debt will always accrue interest at that rate.
However, the stocks, bonds, commodities, and other investments have a return rate that is unknown in the future. Stocks in the long run have believed to return 8% per year. So, my math up to this point has led me to believe that if I want to optimize my long term net worth, I should dump money into stocks instead of my student loan debt (8 > 7.4).
The problem with saying that stocks return 8% a year, every year, is that that's not the case. It might go down 5% one year and up 14% the next, averaging out to 8% each year. This volatility in the return of the stock market is what we identify as risk.
For me, since I am young, I can afford to be very risky with my investments for retirement. The term of my loans are fixed. Assuming all is well and I go along with the minimum payments, they won't last longer than 2020. I won't have access to my retirement accounts until I am 59.5 years old, which is more than 30 years away for me.
Because my debt has a shorter term than my investment horizon, it makes sense to invest more than to put capital into my debt. Why? Because consider the compounding of 30 years compared to the compounding of 10 years, it's at least 4x larger (1.08^30 / 1.074^10 ~= 4.9).
However, for shorter term investments, like saving to buy a home needs to go after spending money on my loan because the power of compounding dictates that I shouldn't have a large cash savings (<1% return in savings account) while interest on debt is accruing over time.
Over the last two years I've been employed I've maximized my traditional 401k, a Roth IRA, and an HSA.
To reiterate why it's because of the interest rates and time. Those are the two components that determine whether to invest your cash or to pay down your debt.
On the other hand, any capital I have had after my retirement savings (and after my emergency fund) I have not saved into cash; I put them into my student loans.