The calendar year is typically 365 days. However, Earth's orbit around the sun takes slightly longer than this. Because of this difference, every fourth year of our calendar is called a leap year, and has 366 days. The differences arise because it actually takes the Earth around 365.25 days to make a full orbit. This value is rounded down for the sake of our timekeeping.
Sidereal Day vs. Solar Day
Astronomers can refer to two different types of days when tracking the motion of the Earth and heavens. A sidereal day is the time it takes for a star to rotate 360 degrees, completely around the sky. This length of time is roughly 23 hours, 56 minutes and 4 seconds. A solar day is the time it takes for the sun to travel completely across the sky, crossing the meridian twice. Because the Earth moves around the sun as it rotates, the sun's position changes relative to the stars. Therefore, a solar day is slightly longer than a sidereal day. A mean solar day is exactly 24 hours long.
Sidereal Year vs. Solar Year
The discrepancy between a sidereal day and solar day results in slightly different lengths of the entire year. A sidereal year is 365 days, 6 hours, 9 minutes and 9 seconds. A solar year is 365 days, 5 hours, 48 minutes and 46 seconds. The resulting 20-minute, 23-second discrepancy does not have too many immediate repercussions. However, the positions of the equinoxes change gradually relative to the stars, and astronomers must make note of this in their observations.
Integer Timekeeping and Leap Years
Ultimately, both sidereal years and solar years are slightly longer than our 365-day calendar year. However, in order to maintain the day as a significant marker of time, we round our calendar to the nearest day. Therefore, even though the Earth itself takes longer than 365 days to orbit the sun, we round this to the nearest integer. In order to account for this difference, we add a day to every fourth year. These years are called "leap years."
The Julian and Gregorian Calendars
The Julian calendar was the first 365-day calendar. It was created in 46 B.C. by Julius Caesar. Because the actual length of the year was roughly 365.25 days, the Julian calendar added one day every four years. However, the true length of the solar year is 365.242199 days. This difference causes a discrepancy of three days every 400 years, even accounting for leap years. In 1852, Pope Gregory XIII altered the calendar so that any century year not divisible by 400 would not be a leap year.