Purchasing a home is likely the largest financial decision you will make. This mortgage calculator helps you estimate your monthly financial obligation by breaking down the core components of a housing payment: Principal, Interest, Taxes, and Insurance (PITI).
How is the Mortgage Calculated?
Your monthly payment is determined by four main factors:
Principal: The amount of money you borrowed to buy the house. This is the home price minus your down payment.
Interest: The cost of borrowing money, determined by your Annual Percentage Rate (APR).
Taxes: Property taxes charged by your local government, usually bundled into your monthly payment via an escrow account.
Insurance: Homeowners insurance protects your property against damage and is typically required by lenders.
The Amortization Formula
While taxes and insurance are simple additions, the principal and interest payment is calculated using the standard amortization formula:
M = P [ i(1 + i)^n ] / [ (1 + i)^n – 1]
Where:
M = Total monthly payment
P = Principal loan amount
i = Monthly interest rate (Annual rate / 12)
n = Number of months (Loan term in years × 12)
Why the Down Payment Matters
The size of your down payment directly impacts your monthly rate. A larger down payment reduces the principal loan amount, which lowers both your monthly payment and the total interest paid over the life of the loan. Additionally, putting down less than 20% often triggers Private Mortgage Insurance (PMI), which would be an extra cost on top of the estimate provided above.
function calculateMortgage() {
// Get input values
var homePrice = parseFloat(document.getElementById("homePrice").value);
var downPayment = parseFloat(document.getElementById("downPayment").value);
var interestRate = parseFloat(document.getElementById("interestRate").value);
var loanTerm = parseFloat(document.getElementById("loanTerm").value);
var propertyTax = parseFloat(document.getElementById("propertyTax").value);
var homeInsurance = parseFloat(document.getElementById("homeInsurance").value);
// Validation
if (isNaN(homePrice) || isNaN(downPayment) || isNaN(interestRate) || isNaN(loanTerm)) {
alert("Please enter valid numbers for Home Price, Down Payment, Interest Rate, and Loan Term.");
return;
}
// Handle optional fields as 0 if empty
if (isNaN(propertyTax)) propertyTax = 0;
if (isNaN(homeInsurance)) homeInsurance = 0;
// Core Calculation Variables
var principal = homePrice – downPayment;
var monthlyRate = (interestRate / 100) / 12;
var numberOfPayments = loanTerm * 12;
// Monthly Payment Logic
var monthlyPI = 0;
if (principal <= 0) {
alert("Down payment cannot be greater than or equal to the home price.");
return;
}
if (interestRate === 0) {
monthlyPI = principal / numberOfPayments;
} else {
// Formula: M = P [ i(1 + i)^n ] / [ (1 + i)^n – 1]
var mathPower = Math.pow(1 + monthlyRate, numberOfPayments);
monthlyPI = principal * ((monthlyRate * mathPower) / (mathPower – 1));
}
var monthlyTax = propertyTax / 12;
var monthlyIns = homeInsurance / 12;
var totalMonthly = monthlyPI + monthlyTax + monthlyIns;
// Total Interest Calculation
var totalCostOfLoan = monthlyPI * numberOfPayments;
var totalInterest = totalCostOfLoan – principal;
// Display Results
document.getElementById("resPI").innerText = "$" + monthlyPI.toLocaleString('en-US', {minimumFractionDigits: 2, maximumFractionDigits: 2});
document.getElementById("resTax").innerText = "$" + monthlyTax.toLocaleString('en-US', {minimumFractionDigits: 2, maximumFractionDigits: 2});
document.getElementById("resIns").innerText = "$" + monthlyIns.toLocaleString('en-US', {minimumFractionDigits: 2, maximumFractionDigits: 2});
document.getElementById("resTotal").innerText = "$" + totalMonthly.toLocaleString('en-US', {minimumFractionDigits: 2, maximumFractionDigits: 2});
document.getElementById("resLoanAmount").innerText = "$" + principal.toLocaleString('en-US');
document.getElementById("resTotalInterest").innerText = "$" + totalInterest.toLocaleString('en-US', {minimumFractionDigits: 0, maximumFractionDigits: 0});
// Show result box
document.getElementById("resultBox").style.display = "block";
}