The payment formula
Principal and interest come from the standard amortization formula M = P × i / (1 − (1 + i)^−n), where P is the loan amount, i is the monthly interest rate (the annual rate divided by 12) and n is the number of monthly payments.
Because interest is charged on the remaining balance, early payments are mostly interest. On a $320,000 loan at 6.5%, the first payment sends about $1,733 to interest and only around $290 to principal. The mix reverses slowly over the life of the loan.