This works for any partial sum of geometric series.
Let $S = 1 + x + x^2+\ldots +x^n$. Then $xS = x + x^2 + \ldots +x^n + x^{n+1} = S - 1 + x^{n+1}$.
All you have to do now is solve for $S$ (assuming $x\neq 1$).
To solve for S:
$xS - S = x^{n+1} - 1 + S - S$ $(x - 1)S = x^{n+1} - 1$ $S = (x^{n+1} - 1)/(x-1)$
Note that 1 is simply $x^0$.