If you have ever taken a loan, you have seen the EMI (equated monthly instalment): one fixed amount you pay every month until the loan is cleared. But how is that number worked out? Here is the formula, a worked example, and a few lines of JavaScript.
The EMI formula
EMI = P × r × (1 + r)^n / ((1 + r)^n − 1) - P is the loan amount (principal)
- r is the monthly interest rate, which is the annual rate divided by 12 and by 100
- n is the number of monthly instalments, which is the loan term in years times 12
A worked example
Say you borrow ₹5,00,000 at 9% a year for 5 years.
- P = 500000
- r = 9 / 12 / 100 = 0.0075
- n = 5 × 12 = 60
Putting these into the formula gives an EMI of roughly ₹10,379 per month.
Over 60 months you pay about ₹6,22,740 in total, so the interest cost is about ₹1,22,740.
Where each payment goes
Every EMI is split between interest and principal, and the split changes over time. In month 1:
- Interest = 500000 × 0.0075 = ₹3,750
- Principal repaid = 10,379 − 3,750 = ₹6,629
The next month, interest is charged on the smaller remaining balance, so a little more of each EMI goes to principal. That is why early payments are mostly interest.
The formula in JavaScript
function calculateEmi(principal, annualRatePercent, years) { const r = annualRatePercent / 12 / 100; // monthly rate const n = years * 12; // number of instalments if (r === 0) return principal / n; // interest-free loan const factor = Math.pow(1 + r, n); return (principal * r * factor) / (factor - 1); } const emi = calculateEmi(500000, 9, 5); console.log(Math.round(emi)); // about 10379 A few things to watch for in your own code:
- Convert the annual percentage to a monthly decimal rate first. This is the most common mistake.
- Handle a 0% rate separately, otherwise you divide by zero.
- Round only for display, not during the calculation.
What changes the EMI
- A longer term lowers the monthly EMI but increases the total interest paid.
- A higher rate raises both the EMI and the total cost.
- A bigger down payment reduces P, which lowers everything.
Try it without doing the maths
I built a free EMI calculator at Instant Calc Hub. Enter the loan amount, interest rate and tenure, and it shows the monthly EMI, total interest and total payment, plus a year-wise payment schedule.
What would you add to a loan calculator? Tell me in the comments.