# Derivation of the loan/mortgage monthly payment formula

I like to know where my formulas come from. I’m currently looking into purchasing a new vehicle, and with that will possibly be a car loan. Coming from an math/engineer perspective, I’ve found the specifics of car loans to be lacking. But that isn’t necessarily the point of this post. Many times, you want to know, given the size of the loan, the “interest rate”, and the number payments, how big will the monthly payment be?

So let’s derive it ourselves.

First, let’s define some variables. Let

\(P_0 =\) Initial loan size ($)

\(R =\) Interest rate described as an annual number (%, 0-1)

\(r = R/12\) Interest rate per month (%, 0-1)

\(M =\) Monthly payment ($)

\(n =\) Number of payments (months)

The way these loans typically work is that every month you have an interest payment on the amount you owe on the loan (principal). Anything extra that you pay that isn’t part of the interest payment will deduct from your total principal.

So let’s start from month 1. The amount of interest you owe will be the initial loan size, \(P_0\) multiplied by the interest rate.

What should that interest rate be though? It’s usually not specified clearly in many places, but it’s often assumed that it’s the annual rate divided by 12 months, which we are denoting as \(r\).

For this first payment the amount you are going to reduce the principal by is

\[M - P_0 r\]So the principal after the first payment, \(P_1\) will be

\[P_1 = P_0 - (M - P_0 r)\]With a little algebra, this is equivalent to

\[P_1 = P_0 \left(1 + r\right) - M\]From here, you can just continue the pattern, and it should be apparent that the following recursive formula is true.

\[\begin{equation} P_{n+1} = P_{n} \left(1 + r\right) - M \label{eq:recursive} \end{equation}\]This equation is the basis for all the loan payment formulas. But at this point, it’s not very useful.

We need to get rid of this subscript \(n+1\) stuff. So let’s just start looking at bigger values of \(n\) beyond 1, substituting for variables until we have only variables that we know. Let’s look at the case \(n=3\) and see if we can spot some patterns. Using Eq. \eqref{eq:recursive},

\[\begin{equation} P_{3} = P_{2} \left(1 + r\right) - M \label{eq:n3} \end{equation}\] \[\begin{equation} P_{2} = P_{1} \left(1 + r\right) - M \label{eq:n2} \end{equation}\] \[\begin{equation} P_{1} = P_{0} \left(1 + r\right) - M \label{eq:n1} \end{equation}\]Substituting Eq. \eqref{eq:n2} into \eqref{eq:n3}

\[P_{3} = \left( P_{1} \left(1 + r\right) - M \right) \left(1 + r\right) - M\]Rearranging,

\[\begin{equation} P_{3} = P_{1}\left(1 + r\right)^{2} - M \left(1 + r\right) - M \label{eq:newP3} \end{equation}\]Let do one more substitution, Eq. \eqref{eq:n1} into \eqref{eq:newP3}.

\[\begin{equation} P_{3} = \left(P_{0} \left(1 + r\right) - M\right) \left(1 + r\right)^{2} - M \left(1 + r\right) - M \end{equation}\]Distribute that \(\left(1 + r\right)^{2}\),

\[\begin{equation} P_{3} = P_{0}\left(1 + r\right)^{3} - M \left(1 + r\right)^{2} - M \left(1 + r\right) - M \label{eq:finalform} \end{equation}\]or

\[\begin{equation} P_{n} = P_{0}\left(1 + r\right)^{n} - \left[M + M\left(1+r\right) + M \left(1+r\right)^{2} + \ldots{} + M \left(1+r\right)^{n-1} \right] \label{eq:rearrangedform} \end{equation}\]Cool. So we got to a point where we only have a \(P_0\) and other terms we know (\(M\) and \(r\)). The problem is that as we keep going, we add one more \(M \left(1+r\right)^{n}\) term and that gets messy. Is there a way to simplify that?

If you were paying attention in calculus class, you may recognize that
type of series the \(M\) terms are going through. It’s known by math
people as a *geometric series*, one in which you are multiplying by a
factor over and over again. In our case, that factor is \(\left(1 +
r\right)\).

A finite geometric series is defined by the form

\[a r^{0} + a r^{1} + a r^{2} + a r^{3} + \ldots{} + a r^{n-1}\](We typically stop at \(n - 1\) because we usually want \(n\) to equal the total number of terms, and we have to include that \(r^{0}\).)

This has a well known formula for the sum (for a derivation, check out Khan Academy).

\[S_n = a \left(\frac{1 - r^{n} }{1-r}\right)\]Almost there. Now we can replace the terms in the square brackets in Eq. \eqref{eq:rearrangedform} with our formula for the sum where for us \(a\) is like \(M\) and \(r\) is like \(\left(1 + r\right)\).

\[\begin{equation} P_{n} = P_{0}\left(1 + r\right)^{n} - \left[ M \left( \frac{1 - \left(1+r\right)^{n} }{1 - \left(1 + r\right)} \right) \right] \end{equation}\]We are interested in when \(P_n = 0\) as this means the principal has gone to 0 and you owe nothing more! After all this work, one version of our final form is

\[\begin{equation} M \frac{ \left(1+r\right)^{n} - 1}{r} = P_{0}\left(1 + r\right)^{n} \end{equation} \label{eq:base}\]We now have an equation, with four variables. Given 3 of them, we can use algebra to find the 4th. Now normally, you aren’t solving for \(P_0\), the loan amount, but nothing would stop you. The equation most people will be interested in is solving Eq. \eqref{eq:base} for \(M\), the monthly payment. With algebra, that formula is

\[\begin{equation} M = \frac{r P_{0} \left( 1 + r\right)^{n} }{\left(1+r\right)^n - 1} \end{equation}\]The equation for \(n\), the number of payment months, is less well known, but we can still get it.

Algebra time. Solving for \(n\)…

\[\frac{M}{r P_0} = \frac{ \left(1 + r\right)^{n} }{\left(1+r\right)^{n} - 1}\] \[\frac{r P_0}{M} = 1 - \frac{1}{\left(1 + r\right)^{n} }\] \[\frac{1}{ \left(1+r\right)^{n} } = 1 - \frac{r P_0}{M}\] \[\left(1 + r\right)^{-n} = 1 - \frac{r P_0}{M}\] \[-n \ln{\left(1 + r\right)} = \ln{\left(1 - \frac{r P_0}{M}\right)}\] \[\begin{equation} n = \frac{- \ln{\left(1 - \frac{r P_0}{M}\right)} }{\ln{\left(1 + r\right)} } \end{equation}\]Phew. I played around with trying to find a closed form solution for \(r\), but this proved to be much more of a challenge. Simplified it a bit with some binomial coefficient formulas, but no luck completely isolating \(r\). Since you have \(r^n\), you get lots of solutions. Best way is to just numerically solve it using traditional techniques.