A leap year is a calendar year that contains 366 days as compared to the 365 days contained by an ordinary calendar year. A year that is not a leap year is called a common year.
A leap year contains one additional day over the common year: the February 29th (the leap day). In a common year the month of February has only 28 days and February 29th does not exist.
Nearly once every four years is a leap year, and these years must be multiples of 4. More precisely, as we'll see below, leap years happen in a cycle of 97 years out of every 400.
There is a difference between a common calendar year and an astronomical year. The astronomical year, also called a tropical year, a solar year, or an equinoctial year, is the actual duration of the Earth's full rotation around the Sun, on its orbit (Earth's revolution around the Sun). It takes the Earth around ≈ 365.242216 calendar days, or around 365 days, 5 hours and 48 minutes to complete a rotation around the Sun (* see note below). Yet, the common year has only 365 days.
The additional day contained in a leap year keeps the calendar year synchronized with the astronomical year, compensating for the fact that a period of 365 days of a common calendar year is shorter than the astronomical year (with something slightly less than a quarter of a calendar day); otherwise, seasons would occur earlier than intended in the calendar year.
Leap years keep the calendar year in sync with the astronomical year, preventing us, for example, from celebrating Christmas in the month of November.
The actual duration of the Earth's full rotation around the Sun, on its orbit, also slightly varies from year to year, sometimes up to 30 minutes, due to the Earth's rotation speed around the Sun, ie: measured from equinox (when the duration of a day is equal to the duration of a night), March 2015 - March 2016 took 365 days, 5 hours and around 45 minutes, yet March 2016 - March 2017 took 365 days, 5 hours and around 59 minutes (a difference of about 14 minutes between the two consecutive years).
In 1582, Pope Gregory XIII (13th), January 7th, 1502 - April 10th, 1585, Pope of the Catholic Church from May 13th, 1572 to his death in 1585, commissioned the adjustment of the Julian calendar, that was in use at that time, and which was already generating significant discrepancies over the astronomical year.
The new calendar was instituted when Pope Gregory decreed, by the papal bull Inter gravissimas of February 24th, 1582, that the day after Thursday, October 4th, 1582 would be not Friday, October 5th, but Friday, October 15th, 1582.
The modern calendar that is currently in use, also called the Gregorian or civil calendar, is based entirely on the Julian calendar, which was introduced by the Roman Emperor Julius Caesar, in 45 BC.
The Julian calendar featured a year comprized of 12 months, being a 365 days a year calendar, with an intercalary day inserted every fourth year at the end of month of February to make an average year of 365.25 days.
But, as we have already seen above, because the length of the astronomical year is actually ≈ 365.242216 days, the Julian calendar year was longer by about 11 minutes and 14 seconds than the astronomical year. Perhaps this doesn't seem a lot, but over time it added up, until in the 16th century, after 1627 years from its adoption, the vernal equinox (* see note below) was falling around March 11th instead of March 21st (a 10 days shift).
Equinox = the moment when day and night are of approximately equal duration all over the planet, the northern and southern hemispheres being equally illuminated. In this moment the plane of Earth's equator passes through the center of the Sun's disk.
The equinox occurs twice a year: once around March 20th (the vernal equinox, conventionally marks the beginning of spring in the nortern hemisphere while for the southern hemisphere it is the autumnal equinox, that marks the beginning of autumn) and once around September 23rd (the autumnal equinox, conventionally marks the beginning of autumn in the nortern hemisphere while for the southern hemisphere it is the vernal equinox, that marks the beginning of spring).
In 1582, at February 24th, by papal bull Inter gravissimas, Pope Gregory XIII (the 13th) commissioned the adjustment of the Julian calendar, that was in use at that time, in short dully leaping from the date of October 4th (Thursday) not to the date of October 5th (Friday) as it would had been normal, but to the date of October 15th (Friday), dully synchronizing the calendar year with the astronomical one.
Also, as important as the above synchronization, it was the change on the rule for the intercalary day, so that the kind of discrepancies (differences) generated by the Julian calendar would not happen, well, at least not for the next 3300 years.
Therefore the algorithm ended up with the leap year rule, as presented in the above sections. This new rule, whereby a century year (one that is evenly divisible by 100) is a leap year only if it's also evenly divisible by 400, is the sole feature that distinguishes the Gregorian calendar from the Julian calendar (added on top of the previous rule of years being evenly divisible by 4).
Following the Gregorian reform, the average calendar year length is now 365,2425 days, an even better approximation to the astronomical year (≈ 365.242216).
At this rate, it takes about 3236 years for the Gregorian calendar to get into errors, gaining 1 extra day versus the astronomical year, from the moment of its creation in 1582.
By then though we'll probably come up with another better calendar, in advance real time computer synchronized with the astronomical year, based on real time measurements.
To make a calendar a better measurement of the astronomical year, determined by the Earth's orbit around the Sun, leap year rules were created and have since been improved. These improvements have resulted in a better synchronization between the calendar year and the astronomical one, but the calendar year will only be an approximation:
Slightly less than 1 in 1,500 (1 in 1,461, more precisely).
The Paradox of Being a Leap Year Baby Born on February 29: A person born on February 29th may be called a "leapling" or a "leaper". In non-leap years, some leaplings celebrate their birthday on either February 28th or March 1st, while others only observe birthdays during leap years, on the authentic February 29th. If you were born on a Leap Year, do you get your driver's license on February 28th or on March 1st? This is an ambiguous question that is decided by each country differently, some preffer to use the February 28th (New Zealand) while others preffer the March 1st (UK, Hong Kong). There are around 4 million people worldwide who were born on a Leap Day (February 29th).