Let the rate of interest per anum is $r$, principal $=p$, and the compound interested is calculated $n$ time per year.
So, in time $\frac 1 n$ year, the interest accrued is $p\cdot \frac 1 n \cdot r$
So, the principal + interest becomes $p(1+\frac r n)$
In the next $\frac 1 n$ year, the interest accrued is $p(1+\frac r n)\cdot \frac 1 n \cdot r$
So, the principal + interest becomes $p(1+\frac r n)+p(1+\frac r n)\cdot \frac 1 n \cdot r=p(1+\frac r n)^2$
If $t=n\cdot s+u$ where $0\le u< n$ , on $n\cdot s$ years the principal + interest will be $p(1+\frac r n)^{ns}$
For $u$ years, the rest interest is $p(1+\frac r n)^{ns}\cdot \frac u n \cdot r$