At around age 10 to 12 boys begin puberty and can begin producing sperm and sometimes begin experimenting with masturbation which is very normal.
Then as the boy grows into a man they become fertile with the sperm and can get a girl pregnant as early as age 12 to 13.
As you get older you still can produce sperm but the quality of the sperm declines which lowers your chances of getting a woman pregnant but it's still possible.
Men have a better chance of getting a woman pregnant and have a better quality of sperm before age 40 and after 40 the sperm quality starts to decline.
By age 60 the sperm quality gets even worse and you produce less sperm and by age 70 and 80 the quality and quantity of the sperm declines even more.
Men will always produce some amount of sperm so they never stop producing sperm at all.