Leap Years Explained
Learn how leap years work, why February sometimes has 29 days, and how to determine whether a year is a leap year using the Gregorian calendar rules.
A leap year is a calendar year that contains one additional day compared with a normal year. In the Gregorian calendar, that extra day is February 29, giving the year 366 days instead of the usual 365. Leap years exist because Earth's orbit around the Sun does not take exactly 365 days.
Without periodic adjustments, the calendar would gradually move out of alignment with the seasons. Over many years, dates associated with spring, summer, autumn, and winter would slowly shift relative to the calendar. Leap years provide a correction that keeps the calendar closely synchronized with the astronomical year.
What Is a Leap Year?
A leap year is a year with 366 calendar days rather than 365. The additional day is inserted into February, which normally contains 28 days but has 29 days during a leap year.
| Year Type | Days | February |
|---|---|---|
| Common year | 365 | 28 days |
| Leap year | 366 | 29 days |
The extra day is known as a leap day. Because it occurs on February 29, people born on that date sometimes refer to themselves as leap-day or leap-year babies.
Why Do Leap Years Exist?
The reason is that a tropical year, which is closely related to the cycle of the seasons, is slightly longer than 365 days. Earth's orbit and the apparent annual movement of the Sun do not fit perfectly into a whole number of 24-hour days.
If every calendar year contained exactly 365 days, the calendar would lose roughly a quarter of a day relative to the seasonal cycle each year. That difference accumulates over time. After several years, the accumulated error becomes large enough to require a correction.
Adding an extra day approximately every four years compensates for most of this difference. However, simply adding a leap day every fourth year would still introduce a small long-term error, which is why the Gregorian calendar has additional rules for century years.
How the Gregorian Leap Year Rule Works
The Gregorian calendar uses three rules to determine whether a year is a leap year. A year is a leap year if it is divisible by 4, except when it is divisible by 100. Years divisible by 400 are leap years despite also being divisible by 100.
- If the year is not divisible by 4, it is not a leap year.
- If the year is divisible by 4 but not by 100, it is a leap year.
- If the year is divisible by 100, it must also be divisible by 400 to be a leap year.
| Year | Divisible by 4 | Divisible by 100 | Divisible by 400 | Leap Year? |
|---|---|---|---|---|
| 2024 | Yes | No | No | Yes |
| 2025 | No | No | No | No |
| 1900 | Yes | Yes | No | No |
| 2000 | Yes | Yes | Yes | Yes |
The Simple Leap Year Algorithm
The Gregorian rule can be expressed as a short logical condition. A year is a leap year when it is divisible by 400, or when it is divisible by 4 but not by 100.
function isLeapYear(year) {
return year % 400 === 0 ||
(year % 4 === 0 && year % 100 !== 0);
}
console.log(isLeapYear(2024)); // true
console.log(isLeapYear(1900)); // false
console.log(isLeapYear(2000)); // trueThe order of the conditions is important. Checking only whether a year is divisible by 4 would incorrectly classify years such as 1900 as leap years. The century exception is what makes the Gregorian calendar more accurate over long periods.
Why Is 1900 Not a Leap Year?
The year 1900 is divisible by 4, so it might initially appear to qualify as a leap year. However, it is also divisible by 100. Under the Gregorian rules, century years are not leap years unless they are divisible by 400.
Because 1900 is not divisible by 400, February had only 28 days that year. This is a useful example for testing leap-year implementations because a simple divisible-by-4 rule would produce the wrong result.
Why Was 2000 a Leap Year?
The year 2000 was a leap year because it is divisible by 400. Although it is also divisible by both 4 and 100, the final Gregorian rule overrides the century exception when the year is evenly divisible by 400.
2000 Γ· 400 = 5This distinction is important because 2000 and 1900 are both century years, but they have different leap-year status. The 400-year rule prevents the calendar from adding too many leap days over very long periods.
How Often Does a Leap Year Occur?
In the Gregorian calendar, leap years usually occur every four years. However, century years that are not divisible by 400 are skipped. As a result, there are 97 leap years in every 400-year Gregorian calendar cycle.
400 calendar years
β 303 common years
= 97 leap yearsThis means the average Gregorian calendar year is slightly longer than 365 days but slightly shorter than 365.25 days. The century exceptions improve the long-term alignment between the calendar and the seasonal year.
How Many Days Are in a Leap Year?
A Gregorian leap year has 366 days. The additional day comes from February having 29 days instead of 28.
| Month | Common Year | Leap Year |
|---|---|---|
| January | 31 | 31 |
| February | 28 | 29 |
| March | 31 | 31 |
| April | 30 | 30 |
| May | 31 | 31 |
| June | 30 | 30 |
| July | 31 | 31 |
| August | 31 | 31 |
| September | 30 | 30 |
| October | 31 | 31 |
| November | 30 | 30 |
| December | 31 | 31 |
Leap Years and Date Calculations
Leap years matter whenever software calculates dates, ages, durations, recurring events, deadlines, or differences between calendar dates. A calculation that assumes every year has exactly 365 days can produce incorrect results when February 29 falls inside the interval.
For example, the number of days between two dates cannot always be calculated correctly by simply multiplying the number of years by 365. The calculation must account for every leap day that occurs between the two dates.
Leap Years and Age Calculations
Leap years can create special cases when calculating someone's age from a birth date of February 29. The exact treatment of a February 29 birthday in a non-leap year can depend on the legal jurisdiction, application requirements, or business rules.
For ordinary age calculations, software should distinguish between measuring elapsed time and determining a person's calendar birthday. These are not always identical operations.
Leap Day: February 29
February 29 is the additional calendar day inserted during a Gregorian leap year. It follows February 28 and precedes March 1.
Because February 29 occurs only in leap years, recurring events scheduled specifically for that date require special handling. An application might choose to skip the event in non-leap years, move it to February 28, move it to March 1, or apply another business rule.
Leap Years in Programming
Developers frequently encounter leap-year logic when implementing calendars, date pickers, scheduling systems, billing periods, age calculators, reporting systems, and date validation. The basic Gregorian test is simple, but real-world date handling can become more complicated when time zones, calendar systems, or historical dates are involved.
function daysInFebruary(year) {
return isLeapYear(year) ? 29 : 28;
}
console.log(daysInFebruary(2024)); // 29
console.log(daysInFebruary(2025)); // 28For most applications using the Gregorian calendar, the standard leap-year rule is enough to determine whether February has 28 or 29 days. However, developers should avoid reinventing complete date-time handling when a mature library already provides the required functionality.
Common Leap Year Mistakes
- Assuming every year divisible by 4 is a leap year.
- Forgetting the century exception for years divisible by 100.
- Forgetting that years divisible by 400 are leap years.
- Assuming every year contains exactly 365 days.
- Calculating date differences without accounting for February 29.
- Treating February 29 birthdays as an ordinary recurring calendar date without defining a rule for non-leap years.
- Mixing Gregorian calendar rules with other calendar systems.
Julian Calendar vs Gregorian Calendar
The Gregorian calendar was introduced as a refinement of the earlier Julian calendar. The Julian system used a simpler rule in which every fourth year was a leap year. That rule makes the average calendar year slightly too long over extended periods.
The Gregorian calendar modified the rule by excluding most century years while keeping years divisible by 400 as leap years. This reduces the accumulated difference between the calendar and the seasonal cycle.
How to Check Whether a Year Is a Leap Year
To check a year manually, first determine whether it is divisible by 4. If it is not, the year is not a leap year. If it is divisible by 4, check whether it is divisible by 100. If it is not divisible by 100, it is a leap year. If it is divisible by 100, check whether it is also divisible by 400.
- 2024 β divisible by 4 and not by 100 β leap year.
- 2025 β not divisible by 4 β common year.
- 1900 β divisible by 100 but not by 400 β common year.
- 2000 β divisible by 400 β leap year.
Leap Years: Key Takeaways
- A leap year has 366 days instead of 365.
- The extra day is February 29.
- Leap years compensate for the difference between the calendar year and Earth's seasonal cycle.
- In the Gregorian calendar, years divisible by 4 are normally leap years.
- Years divisible by 100 are not leap years unless they are also divisible by 400.
- 1900 was not a Gregorian leap year, while 2000 was.
- There are 97 leap years in every 400-year Gregorian cycle.
- Leap years must be considered when performing accurate date and duration calculations.
What is a leap year?
A leap year is a calendar year containing 366 days instead of the usual 365. In the Gregorian calendar, the extra day is February 29.
How do you know if a year is a leap year?
A Gregorian year is a leap year if it is divisible by 400, or if it is divisible by 4 but not by 100.
Why do leap years exist?
Leap years keep the calendar more closely aligned with Earth's seasonal cycle because a year is slightly longer than 365 days.
Why does February have 29 days in a leap year?
The Gregorian calendar adds one extra day to February so that the calendar can compensate for the fractional length of the astronomical year.
Why was 1900 not a leap year?
1900 was divisible by 100 but not by 400, so it did not satisfy the Gregorian leap-year rules.
Why was 2000 a leap year?
2000 was divisible by 400, so it qualified as a leap year even though it was also a century year.
How many leap years are in 400 years?
The Gregorian calendar has 97 leap years in every 400-year cycle.
How many days are in a leap year?
A Gregorian leap year has 366 days, including 29 days in February.