Mortgage Calculator Formula
Understand the math behind the mortgage calculator. Each variable explained with a worked example.
Formulas Used
Monthly Payment
monthly_payment = monthly_rate > 0 ? principal * monthly_rate * pow(1 + monthly_rate, num_payments) / (pow(1 + monthly_rate, num_payments) - 1) : principal / num_paymentsTotal Amount Paid
total_paid = monthly_payment * num_paymentsTotal Interest Paid
total_interest = total_paid - principalVariables
| Variable | Description | Default |
|---|---|---|
home_price | Home Price(USD) | 300000 |
down_payment | Down Payment(USD) | 60000 |
annual_rate | Interest Rate(%) | 6.5 |
loan_term_years | Loan Term(years) | 30 |
principal | Derived value= home_price - down_payment | calculated |
monthly_rate | Derived value= annual_rate / 12 / 100 | calculated |
num_payments | Derived value= loan_term_years * 12 | calculated |
How It Works
How to Calculate Your Mortgage Payment
The mortgage payment formula calculates your monthly principal and interest payment based on the loan amount, interest rate, and loan term.
Formula
M = P * [r(1+r)^n] / [(1+r)^n - 1]
Where:
How It Works
1. Calculate your loan principal by subtracting the down payment from the home price 2. Convert the annual interest rate to a monthly rate 3. Determine the total number of monthly payments 4. Apply the amortization formula to find the fixed monthly payment
Worked Example
You want to buy a $300,000 home with a $60,000 down payment (20%) at a 6.5% annual interest rate for a 30-year fixed mortgage.
home_price = 300000down_payment = 60000annual_rate = 6.5loan_term_years = 30
- 01Calculate the loan principal: $300,000 - $60,000 = $240,000
- 02Convert annual rate to monthly: 6.5% / 12 = 0.5417% (0.005417)
- 03Calculate total payments: 30 * 12 = 360 monthly payments
- 04Apply the formula: M = $240,000 * [0.005417 * (1.005417)^360] / [(1.005417)^360 - 1]
- 05Monthly Payment = $1,517.09
- 06Total amount paid over 30 years: $1,517.09 * 360 = $546,152.40
- 07Total interest paid: $546,152.40 - $240,000 = $306,152.40
Ready to run the numbers?
Open Mortgage Calculator