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