We can work out a 3 payment structure for a loan and then generalize that to an n-payment structure

((L * (1 + i/12) - P) * (1 + i/12) - P) * (1 + i/12) - P = 0

Let 1 + i/12 = k

((Lk - P) * k - P) * k - P = 0

Solve for L

((Lk - P) * k - P) * k = P

(Lk - P) * k - P = P/k

(Lk - P) * k = P + P/k

Lk - P = P/k + P/k^2

Lk = P + P/k + P/k^2

L = P/k + P/k^2 + P/k^3

If this extended on through to an n-number of payments, hopefully you could see how this would generalize to:

L = P/k + P/k^2 + P/k^3 + .... + P/k^n

But adding up all of those terms is annoying, so let's simplify it. Let 1/k = a

L = Pa + Pa^2 + Pa^3 + ... + Pa^n

L = P * (a + a^2 + a^3 + ... + a^n)

S = a + a^2 + a^3 + ... + a^n

Sa = a * (a + a^2 + a^3 + .... + a^n)

Sa = a^2 + a^3 + a^4 + ... + a^(n + 1)

Sa - S = a^2 + a^3 + ... + a^(n + 1) - (a + a^2 + ... + a^n)

S * (a - 1) = a^2 - a^2 + a^3 - a^3 + ... + a^n - a^n + a^(n + 1) - a

S * (a - 1) = 0 + 0 + 0 + ... + 0 + a^(n + 1) - a

S * (a - 1) = a^(n + 1) - a

S * (a - 1) = a * (a^(n) - 1)

S = a * (a^(n) - 1) / (a - 1)

S = a * (1 - a^(n)) / (1 - a)

S = (1/k) * (1 - (1/k)^n) / (1 - (1/k))

S = (1/k) * (1 - (1/k)^n) / ((k - 1)/k)

S = (1 - (1/k)^n) / (k - 1)

S = (1 - k^(-n)) / (k - 1)

L = P * S

L = P * (1 - k^(-n)) / (k - 1)

L = P * (1 - (1 + i/12)^(-n)) / (1 + i/12 - 1)

L = P * (1 - ((12 + i) / 12)^(-n)) / (i/12)

L = 12 * P * (1 - (12/(12 + i))^n) / i

L = loan amount

P = payment

i = annual interest rate

n = number of payments

L = 20000

P = ?

i = 6% = 0.06

n = 15 year * 12 months/year = 180 months

L = 12 * P * (1 - (12/(12 + i))^n) / i

20000 = 12 * P * (1 - (12/(12 + 0.06))^180) / 0.06

20000 * 0.06 / (12 * (1 - (12/12.06)^180)) = P

P = 20000 * 0.01 / (2 * (1 - (2/2.01)^180))

P = 200 / (2 * (1 - (200/201)^180))

P = 100 / (1 - (201/200)^(-180))

P = 100 / (1 - 1.005^(-180))

P = 168.77136560969026208686627213866...

Your monthly payment will be $168.77. Expect for it to be rounded up to 168.78 or even 169, just to make it a nice roundish number (that's real world expectation, where your final payment will be less than previous payments, but all of the other payments will be nicer to look at)

You're going to make 180 of those payments

180 * 100 / (1 - 1.005^(-180)) = 30378.845809744247175635928984958

$30378.85

You'll pay 10378.85 in interest

10378.85 / 30378.85 = 0.34164714073551645564690222761633

34.165%, roughly in interest. The rest will be in principal. 1 - 0.34164714073551645564690222761633....