The formula for calculating compound interest is A = P(1 + r/n)^nt, where A is the accumulated amount, P is the principal, r is the annual rate per period, n is the number of times interest is compounded annually, t is the length of time (in years), and ^ represents exponentiation.