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_payments

Total Amount Paid

total_paid = monthly_payment * num_payments

Total Interest Paid

total_interest = total_paid - principal

Variables

VariableDescriptionDefault
home_priceHome Price(USD)300000
down_paymentDown Payment(USD)60000
annual_rateInterest Rate(%)6.5
loan_term_yearsLoan Term(years)30
principalDerived value= home_price - down_paymentcalculated
monthly_rateDerived value= annual_rate / 12 / 100calculated
num_paymentsDerived value= loan_term_years * 12calculated

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:

  • M = Monthly payment
  • P = Principal (home price minus down payment)
  • r = Monthly interest rate (annual rate / 12 / 100)
  • n = Total number of payments (years * 12)
  • 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
    1. 01Calculate the loan principal: $300,000 - $60,000 = $240,000
    2. 02Convert annual rate to monthly: 6.5% / 12 = 0.5417% (0.005417)
    3. 03Calculate total payments: 30 * 12 = 360 monthly payments
    4. 04Apply the formula: M = $240,000 * [0.005417 * (1.005417)^360] / [(1.005417)^360 - 1]
    5. 05Monthly Payment = $1,517.09
    6. 06Total amount paid over 30 years: $1,517.09 * 360 = $546,152.40
    7. 07Total interest paid: $546,152.40 - $240,000 = $306,152.40

    Ready to run the numbers?

    Open Mortgage Calculator