How the payoff math works
Every month, your student-loan balance accrues interest at your annual rate divided by 12 (the periodic monthly rate). Whatever you pay above that month's interest charge goes straight to principal — that's the part that actually reduces your balance.
Mathematically, the months-to-payoff is the smallest n for which simulating n months of payments against the balance brings it to zero. The closed-form for a fixed payment M, balance P, and monthly rate r is:
n = -log(1 - (P × r / M)) / log(1 + r)
We simulate it month-by-month instead so we can also handle extra payments and the “insufficient payment” edge case (when M ≤ Pr — the balance grows forever and there is no payoff).
Total interest is the sum of every month's interest charge across the simulation — i.e., (total paid) − (original balance).