According to the Gregorian calendar (which is in use today) the year is intended to be of the same length as the cycle of the seasons. However, the cycle of the seasons, technically known as the tropical year, is approximately 365.2422 days. Since a calendar year consists of an integral number of whole days, a calendar year cannot exactly match the tropical year. If the calendar year always consisted of 365 days, it would be short of the tropical year by about 0.2422 days every year. Over a century, the calendar and the seasons would depart by about 24 days, so that the beginning of spring in the northern hemisphere would shift from March 20 to April 13.
To synchronize the calendar and tropical years, leap days are periodically added to the calendar, forming leap years. If a leap day is added every fourth year, the average length of the calendar year is 365.25 days. This was the basis of the Julian calendar, introduced by Julius Caesar in 46 B.C. In this case the calendar year is longer than the tropical year by about 0.0078 days. Over a century this difference accumulates to a little over three quarters of a day. From the time of Julius Caesar to the sixteenth century A.D., the beginning of spring shifted from March 23 to March 11.
Source: US Naval Observatory
No calendar is perfect. To make a calendar a better measure of the Earth's orbit around the Sun, leap year rules were created and have since been modified. These improvements have brought a close correlation between the calendar and the orbit, but the calendar year will always be an approximation.
Source: Steffen Thorsen
The leap year was introduced in the Julian calendar in 46 BC. However, around 10 BC, it was found that the priests in charge of computing the calendar had been adding leap years every three years instead of the four decreed by Caesar (Vardi 1991, p. 239). As a result of this error, no more leap years were added until 8 AD. Leap years were therefore 45 BC, 42 BC, 39 BC, 36 BC, 33 BC, 30 BC, 27 BC, 24 BC, 21 BC, 18 BC, 15 BC, 12 BC, 9 BC, 8 AD, 12 AD, and every fourth year thereafter (Tøndering), until the Gregorian calendar was introduced (resulting in skipping three out of every four centuries).
97 years out of every 400 are leap years, giving the total number of days in 400 years as
400*365+97 = 146,097
Source: Eric W. Weisstein.
Tøndering, C. "Frequently Asked Questions about Calendars."
Vardi, I. "The Julian Calendar." §3.5.1 in Computational Recreations in Mathematica. Redwood City, CA: Addison-Wesley, p. 44, 1991.