Please help me with a bit of math. It seems to be common wisdom, here that if one can invest money at a higher rate, that is a better idea than paying off debt. I keep running into an issue with this, but I believe that there are some factors that I’m missing. I will lay this out with rough numbers, here:

Generic debt: $20k @ 3.5% for 10 years

Payment: $200/month made after tax (really $197, but keeping it simple)

If one has $20k in cash, I would usually say that the thing to do is to invest this in an index fund and get the average 7% returns. Over the course of the 10 years, one can hope to have about $40k.

However, if one were to pay the debt in one stroke and then invest the initial payment in a pretax account (assuming 25% tax rate total) They’d be investing about $250/month for 10 years. This, compounded over 10 years would yield about $43k.

Again, I have used some very generic numbers, here. 25% tax off of a paycheck (i.e. gross pay of $100 gives $80 in paycheck). 20k debt. This really makes it look like leveraging this low interest debt is the wrong play. What am I looking at wrong, here?