Moses remained on the mountain for 40 days, until the 10th of Tishrei (Yom Kippur), during which time He obtained G-d's whole-hearted forgiveness and reconciliation with the people of Israel following their betrayal of the covenant between them with their worship of the Golden Calf. This was the third of Moses' three 40-day periods on Mount Sinai in connection with the Giving of the Torah. Ever since, the month of Elul serves as the "month of Divine mercy and forgiveness."
Font: chabad.org