<s>[INST] The idea behind the sum of powers of 2 I know that the sum of power of $2$ is $2^{n+1}-1$, and I know the mathematical induction proof. But does anyone know how $2^{n+1}-1$ comes up in the first place.
For example, sum of n numbers is $\frac{n(n+1)}{2}$. The idea is that we replicate the set and put it in a rectangle, hence we can do the trick. What is the logic behind the sum of power of $2$ formula?
 [/INST] Here's a geometric intuition for why $2^0 + 2^1 + 2^2 + \dots + 2^n = 2^{n+1} - 1$:

Here's the idea. Notice that the boxes for $1 + 2 + 4$ are right next to a single box of size $8$. They perfectly fill that box once you add the gold square in, so $1 + (1 + 2 + 4) = 8$, meaning $1 + 2 + 4 = 8 - 1$. Similarly, the boxes for $1 + 2 + 4 + 8 + 16 + 32$ are right above a single box of size $64$, and the smaller boxes, plus the gold box, completely fill the box for $64$. That means that $1 + (1 + 2 + 4 + 8 + 16 + 32) = 64$, or that $1 + 2 + 4 + 8 + 16 + 32 = 64 - 1$.
More generally, this gives an intuition for why $1 + (2^0 + 2^1 + \dots + 2^n) = 2^{n+1}$: the boxes for the smaller powers of two, plus one gold box, perfectly fill the next box.
</s>