A mortgage is a long-term loan used to purchase real estate. The monthly payment typically includes two main components: principal and interest. Over time, more of your payment goes towards the principal balance, and less towards interest.
The formula used in this calculator is the standard monthly payment formula for an amortizing loan:
M = P [ i(1 + i)^n ] / [ (1 + i)^n – 1]
M = Your total monthly mortgage payment
P = The loan amount (principal loan amount)
i = Your monthly interest rate (annual rate divided by 12)
n = The total number of payments over the loan's lifetime (loan term in years multiplied by 12)
This calculator provides an estimate for the principal and interest portion of your monthly payment. It does not include property taxes, homeowner's insurance, or private mortgage insurance (PMI), which are often included in an actual mortgage escrow payment.
Example: For a $300,000 loan at 5% annual interest over 30 years, the estimated monthly principal and interest payment would be approximately $1,610.46.
function calculateMortgage() {
var loanAmountInput = document.getElementById("loanAmount");
var annualInterestRateInput = document.getElementById("annualInterestRate");
var loanTermInput = document.getElementById("loanTerm");
var monthlyPaymentOutput = document.getElementById("monthlyPayment");
var loanAmount = parseFloat(loanAmountInput.value);
var annualInterestRate = parseFloat(annualInterestRateInput.value);
var loanTerm = parseFloat(loanTermInput.value);
if (isNaN(loanAmount) || loanAmount <= 0) {
monthlyPaymentOutput.textContent = "Please enter a valid loan amount.";
return;
}
if (isNaN(annualInterestRate) || annualInterestRate < 0) {
monthlyPaymentOutput.textContent = "Please enter a valid interest rate.";
return;
}
if (isNaN(loanTerm) || loanTerm <= 0) {
monthlyPaymentOutput.textContent = "Please enter a valid loan term.";
return;
}
var monthlyInterestRate = (annualInterestRate / 100) / 12;
var numberOfPayments = loanTerm * 12;
var monthlyPayment = loanAmount * (monthlyInterestRate * Math.pow(1 + monthlyInterestRate, numberOfPayments)) / (Math.pow(1 + monthlyInterestRate, numberOfPayments) – 1);
// Handle cases where the formula might result in Infinity or NaN for very small rates or terms
if (!isFinite(monthlyPayment) || isNaN(monthlyPayment)) {
monthlyPayment = 0; // Or display an error, depending on desired behavior
}
monthlyPaymentOutput.textContent = "$" + monthlyPayment.toFixed(2);
}