One needs to specify the payment scheme a bit more accurately, because for exact computation we need those details. Let $n$ be the number of months between current age and retirement age. I will assume that $n$ is an integer.
I will also assume that you make a payment $P$ every month, with first payment today, and the last payment done a month before retirement, for a total of $n$ payments. You will have to make minor adjustments if the payment scheme is slightly different. Let $N$ be the desired sum available at retirement.
Let $r$ be the nominal yearly rate. I assume we have monthly compounding. The monthly rate is $\frac{r}{12}$. Let $x=1+\frac{r}{12}$.
So in one month $1$ unit of currency grows to $x$ dollars. The payment $P$ you made a month before retirement has grown to $Px$ at retirement, not much! The one you made two months before retirement has grown to $Px^2$. The one three months before retirement has grown to $Px^3$. And so on. Finally, the one you made $n$ months before retirement has grown to $Px^n$. (The payments made long before retirement have grown quite a bit.)
We want to have accumulated a total of $N$, so $N=Px+Px^2+Px^3+\cdots +Px^n=Px(1+x+x^2+\cdots+x^{n-1}).$ The sum of the geometric series $1+x+x^2+\cdots+x^{n-1}$ is $\frac{x^n-1}{x-1}$. (This is a standard formula, you can look it up on Wikipedia.) So our equation becomes $N=Px\frac{x^n-1}{x-1}.$ Now it is all ready for numerical calculation. With interest rate $3\%$, for example, $x=1.0025$.