This is the geometric sum:

1+x+x^2+...+x^n

Let S=1+x+...+x^n

Then,

xS=x+x^2+...+x^{n+1}

Thus,

S-xS=(1+x+...+x^n)-(x+x^2+...+x^{n+1})=1-x^{n+1}

S(1-x)=1-x^{n+1}

Now if x is not equal to 1 then,

S=(1-x^{n+1})/(1-x)

And if x is equal to 1 then,

1+x+x^2+...+x^n=1+1+...+1=n

Thus,

sum[k=0,n]x^k = (1-x^{n+1})/(1-x) if x not = 1, n if x =1.