The sum \(S\) of the geometric progression with \(n\) terms, ratio \(r\) and first term \(a\)
\[S = a + a r + a r^2 + a r^3 + \ldots + a r^{n-2} + a r^{n-1}\]is calculated buy multiplying the equation above by \(r\) to obtain
\[r S = a r + a r^2 + a r^3 + \ldots + a r^{n-1} + a r^n\]And then subtracting the top equation from the bottom one to obtain
\[\begin{align*} r S - S & = & a r & + a r^2 + a r^3 + \ldots + a r^{n-1} + a r^n \\ & - a & - a r & - a r^2 - a r^3 - \ldots - a r^{n-1} \end{align*}\]On the right, all but two terms cancel out and we get
\[\begin{align*} r S - S & = a r^n - a \\ S ( r - 1 ) & = a ( r^n - 1 ) \\ & \\ S & = a \frac{r^n - 1}{r-1} \end{align*}\]