Let \(S_i\) denote the \(i\)th partial sum of a geometric sequence with common ratio \(r\). The sum of the first \(n\) terms of the sequence is
\(S_n=a+ar+ar^2+ar^3+\cdots+ar^{n-1}+ar^n\).
Suppose we multiply both sides by \(r\), then
\(rS_n=ar+ar^2+ar^3+ar^4+\cdots+ar^n+ar^{n+1}\)
Taking the difference makes most of the terms vanish:
\(S_n-rS_n=a+(ar-ar)+(ar^2-ar^2)+\cdots+(ar^n-ar^n)-ar^{n+1}\)
\(1S_n-rS_n=a-ar^{n+1}\)
Then solving for \(S_n\) gives the formula.
\((1-r)S_n=a\left(1-r^{n+1}\right)\)
\(S_n=a\dfrac{1-r^{n+1}}{1-r}\)