The compound interest formula is A = P(1 + r/n)^nt. It looks worse than it is - each part has a plain meaning, and once you can read it you can check any calculator against it, including this one.
A = P(1 + r/n)nt
Where A is the final amount, P the principal you start with, r the annual interest rate as a decimal, n the number of times interest compounds each year, and t the number of years.
r/n is the rate for a single compounding period. At 5% compounded monthly, that is 0.05 ÷ 12 = 0.004167 per month.
1 + r/n is the growth multiplier for one period - 1.004167 in that example. Multiply by it once and you have one month's growth.
nt is simply how many periods there are in total. Twenty years compounded monthly is 240 periods.
So the formula says: start with P, and multiply by the one-period growth factor once for every period. Nothing more.
Compounded annually, n = 1, so A = 10000 × (1 + 0.05)20 = 10000 × 2.6533 = $26,532.98. Interest earned is $16,532.98 on a $10,000 deposit.
Compounded monthly, n = 12, so A = 10000 × (1 + 0.05/12)240 = $27,126.40. The extra $593.42 comes purely from compounding more often.
Subtract the principal: Interest = A - P. There is no separate formula for it, which is a common point of confusion.
It assumes the rate never changes and nothing is added or withdrawn. Real savings rarely behave that way. For regular deposits or withdrawals use the savings calculator, which runs the arithmetic month by month instead of applying a single formula.