I am struggling to understand the formula for compound interest. More specifically what the $n$ stands for.
The formula is as follows according to the wikipedia: $$ A = P(1 + \frac{r}{n})^{nt} $$
Where
$A$ = final amount
$P$ = initial principal balance (money invested)
$r$ = interest rate
$n$ = number of times interest applied per time period
$t$ = number of time periods elapsed
But we can twist the parameters so that the interest is not $r$.
Let's take an example: annual interest rate of 20%, compounded quarterly. This means that the parameters are $t = 1$ year, $r = 20$%, $n = 4$
If I invest 1 USD for a year ($P = 1$) it should be 1.20 USD at the end of the year by the definition of annual interest rate, but based on the formula, I calculate something different: The annual interest rate is $21.55$%, because by investing 1 USD, I will have earned 1.2155 USD by the end of the year.
$$ A = 1(1 + \frac{0.2}{4})^{4 \cdot 1} = 1.21550625 $$ Which is approximately 21.55%, not 20% annually.
The continuous compounding interest is derived from this formula, so I would like to understand this before understanding that.
An annual interest rate of $20\%$ compounded quarterly means what the formula reflects, namely that your investment grows once every quarter at a quarterly rate of $20\%/4=5\%.$ This is not the same thing as an annual interest rate of $20\%$ (no compounding), which means your investment grows once every year at the yearly rate of $20\%$. As you have noted, the former gives an effective annual rate of approximately $21.55\%$ while the latter simply gives an effective annual rate of $20\%.$
Compounding more frequently thus leads to a higher annual return, i.e.
$$P(1+r/n)^{nt}\quad (1)$$
increases in $n$ for $r,t>0$. Intuitively, the exponential effect of more compounding periods outweighs the linear effect of the lower per-period interest rate. As you suggestively note, taking the limit of $(1)$ as $n\to \infty$ gives the continuous compounding formula
$$Pe^{rt}.$$