I tried writing down a formula relating a given debt and interest to the periodic payments and number of payments.
So let's say someone starts off with a debt of $D$. The periodic interest is $r$ (for example, $0.6\% =0.006$ each month). Let's call the periodic payment $p$, and the number of payments $N$.
I based my equation off of the fact that the total payments must equal to the original debt plus the added interest. The total payments are clearly $Np$. The added interest each month is $r$ times the remaining debt, so after one period we would add $$rD$$ after another, we would add $$(D+rD-p)r=rD+r^2D-pr$$ next we would add $$(D+rD+r^2D-pr-p)r=rD+r^2D+r^3D-pr^2-pr$$ then $$(D+rD+r^2D+r^3D-pr^2-pr-p)r=rD+r^2D+r^3D+r^4D-pr^3-pr^2-pr$$ and so on, for each of the $N$ periods.
Adding all of these up, along with the initial debt $D$ will give us the total that needs to be payed. Noticing the similar terms in each expression, we get
$$\text{Total} = D(Nr+(N-1)r^2+(N-2)r^3+\dots +r^N)-p((N-1)r+(N-2)r^2+(N-3)r^3\dots+r^{N-1})$$
$$=D\sum_{i=1}^{N} (N+1-i)r^i-p\sum_{i=1}^{N-1} (N-i)r^i = D\sum_{i=1}^{N} (N+1)r^i -p\sum_{i=1}^{N-1} Nr^i - D\sum_{i=1}^{N} ir^i +p\sum_{i=1}^{N-1} ir^i$$
The first to sums are geometric. The second two can be done using:
$$\sum_{i=1}^{k} ir^i = r\cdot \sum_{i=1}^{k} \frac{\partial}{\partial r} r^i = r\cdot \frac{\partial}{\partial r} \sum_{i=1}^{k} r^i =r\cdot \frac{\partial}{\partial r} \frac{r^{k+1}-r}{r-1} = \frac{kr^{k+1}-kr^k-r^k+1}{(r-1)^2}$$
So overall we get
$$D(N+1)\frac{r^{N+1}-r}{r-1}-pN\frac{r^N-r}{r-1}-D\frac{Nr^{N+1}-Nr^N-r^N+1}{(r-1)^2}+p\frac{(N-1)r^{N}-(N-1)r^{N-1}-r^{N-1}+1}{(r-1)^2}$$
As mentioned above, this total should equal $Np$, therefore we can finally conclude
$$N=\frac{D}{p}(N+1)\frac{r^{N+1}-r}{r-1}-N\frac{r^N-r}{r-1}-\frac{D}{p}\frac{Nr^{N+1}-Nr^N-r^N+1}{(r-1)^2}+\frac{(N-1)r^{N}-(N-1)r^{N-1}-r^{N-1}+1}{(r-1)^2}$$
I have a few questions. Firstly, is my attempt correct (I have a feeling this shouldn't be this complicated...). Secondly, is there a way to solve this equation for $N$ (non-numerically)? If not, and I am correct, then how do people determine how long their loan will take them to pay off given their monthly payment?
Thanks in advance.