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 Mortgage Payments Work

Your monthly mortgage payment stays the same every month for the life of a fixed-rate loan, but what's inside that payment shifts over time. Early on, most of your payment goes toward interest. By year 20 of a 30-year loan, the split flips and most goes toward principal.

The Formula

M = P * [r(1+r)^n] / [(1+r)^n - 1]

  • M = Monthly payment (principal + interest only)
  • P = Loan amount (home price minus your down payment)
  • r = Monthly interest rate (annual rate divided by 12, then by 100)
  • n = Total payments (loan term in years times 12)
  • When to Use This Calculator

    Use it when comparing homes at different price points, testing what happens if you put more down, or seeing how a rate change affects your payment. It's also useful for checking whether a 15-year term is affordable vs. a 30-year.

    What This Doesn't Include

    This calculates principal and interest only. Your actual monthly housing cost will be higher because of property taxes (typically 1-2% of home value per year), homeowner's insurance, and PMI if your down payment is under 20%. On a $300K home, taxes and insurance can add $300-$500/month on top of the P&I number shown here.

    What Changes the Payment Most

    Interest rate has the biggest impact. On a $240,000 loan, the difference between 6% and 7% is about $160/month, which adds up to $57,600 over 30 years. Loan term is next. A 15-year term roughly doubles your monthly payment but saves you more than half the total interest.

    Common Mistakes

  • Forgetting to subtract the down payment before calculating. The formula uses the loan amount, not the home price.
  • Comparing rates without checking if they include points. A lower rate with 2 points upfront might cost more than a slightly higher rate with no points.
  • Not accounting for PMI. If you put less than 20% down on a conventional loan, PMI typically adds 0.5-1% of the loan amount per year to your cost.
  • 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

    When to Use This Formula

    • Comparing two mortgage offers with different rates and terms to see which costs less over the life of the loan.
    • Figuring out how much house you can afford by working backward from a target monthly payment to a maximum loan amount.
    • Deciding whether a 15-year or 30-year mortgage makes more sense given your monthly cash flow and total interest paid.
    • Estimating the impact of making a larger down payment on your monthly obligation and total interest cost.
    • Evaluating whether refinancing at a lower rate saves enough to justify closing costs, by comparing remaining payments under each scenario.
    • Running scenarios for adjustable-rate mortgages by calculating payments at the initial rate, the cap rate, and likely adjustment rates.

    Common Mistakes to Avoid

    • Using the annual interest rate directly instead of converting to monthly (divide by 12) — this dramatically overstates each payment because the formula expects the periodic rate, not the annual one.
    • Forgetting that the "n" in the formula is total number of payments, not years — a 30-year mortgage has 360 monthly payments, not 30.
    • Ignoring property taxes, homeowners insurance, and PMI when budgeting — the formula gives principal and interest only, so your actual monthly housing cost will be significantly higher.
    • Comparing only monthly payments between two loans without calculating total interest paid — a lower monthly payment over a longer term often costs tens of thousands more in total interest.
    • Assuming the formula works for adjustable-rate mortgages without recalculating at each rate change — the standard PMT formula applies to fixed-rate periods only.

    Frequently Asked Questions

    How is a mortgage payment calculated?

    A mortgage payment is calculated using the amortization formula: M = P * [r(1+r)^n] / [(1+r)^n - 1], where P is the loan principal, r is the monthly interest rate, and n is the total number of payments.

    What is included in a mortgage payment?

    A basic mortgage payment includes principal and interest (P&I). Your total housing payment may also include property taxes, homeowner's insurance, and PMI (private mortgage insurance) if your down payment is less than 20%.

    How much should my down payment be?

    A traditional down payment is 20% of the home price, which avoids PMI. However, many loan programs allow as little as 3-5% down. A larger down payment means lower monthly payments and less interest over the life of the loan.

    What is the difference between a 15-year and 30-year mortgage?

    A 15-year mortgage has higher monthly payments but you pay roughly half the total interest of a 30-year loan. A 30-year mortgage offers lower monthly payments and more cash flow flexibility, but you build equity slower and pay significantly more interest overall.

    Learn More

    Guide

    How to Calculate Mortgage Payments

    Learn how to calculate mortgage payments step by step. Understand the mortgage payment formula, principal vs. interest breakdown, escrow, PMI, and how to use amortization schedules.

    Ready to run the numbers?

    Open Mortgage Calculator