Back to Blog

The math of leap years — why every 4 years isn't always right

May 10, 2026
6 min read
Written by ConvertTime Team
leap-yearcalendarcalculatormathfundamentals

You probably learned that a leap year is "every 4 years." That's mostly true but not always. The full rule: every 4 years, except every 100 years, except every 400 years. So 1900 wasn't a leap year (divisible by 100 but not 400), but 2000 was (divisible by 400). 2100 won't be a leap year either.

For computing dates, leap year-aware calculations matter. The age calculator and duration calculator handle them automatically.

The basic rule

A leap year has 366 days instead of 365. The extra day is February 29.

The rule:
- Year is divisible by 4: usually a leap year
- EXCEPT if divisible by 100: usually NOT a leap year
- EXCEPT if also divisible by 400: IS a leap year

Examples:
- 2024: divisible by 4, not 100 → leap year (366 days)
- 2025: not divisible by 4 → not leap year (365 days)
- 2026: not divisible by 4 → not leap year (365 days)
- 2027: not divisible by 4 → not leap year (365 days)
- 2028: divisible by 4, not 100 → leap year
- 1900: divisible by 100, not 400 → not leap year
- 2000: divisible by 400 → leap year
- 2100: divisible by 100, not 400 → not leap year

Why this rule

Earth's orbital period (a "tropical year") is 365.2422 days. Not exactly 365.25 (which would suggest just "every 4 years").

Without leap years, the calendar would drift slowly out of sync with the seasons:
- Without correction: ~6 hours per year
- After 700 years, the seasons would shift by 1 month

The "every 4 years" rule overcorrects (4 leap days per 4 years = 1 extra day per year on average, but the actual extra is 0.25 days per year × 4 years = 1 day, exactly matching). Wait — that math is right. So what's the issue?

The issue: 365.2422 ≠ 365.25 exactly. Difference: 0.0078 days per year, or 11.25 minutes per year. Adds up to:
- 1 day per ~128 years

The Julian calendar (no exception rule, every 4 years) accumulated this error. By the 1500s, the seasonal drift was significant.

Pope Gregory XIII reformed it in 1582 with the "100/400" exception:
- Every 100 years, skip leap year (correcting most of the drift)
- Every 400 years, do leap year anyway (small final correction)

Result: the Gregorian calendar is accurate to within ~1 day per 3,000 years.

Why the 1582 reform was contentious

When Pope Gregory introduced the new rule, October 4, 1582 was followed by October 15, 1582 — skipping 10 days to realign the calendar. Different countries adopted at different times:

- 1582 (Catholic countries): immediate
- 1700 (Protestant Europe): late
- 1752 (Britain and colonies, including American colonies)
- 1873 (Japan)
- 1918 (Russia, after the revolution)
- 1923 (Greece, last European country)

Russia's "October Revolution" (1917) actually happened in November of the Gregorian calendar — Russia was still on the Julian calendar in 1917.

For dates before each country's adoption, you'd need to know which calendar was being used.

How the math works out

In a 400-year cycle:
- Years divisible by 4: 100 (would be leap years under the simple rule)
- Years divisible by 100: 4 (would NOT be leap years)
- Years divisible by 400: 1 (IS a leap year)

So in 400 years: 100 - 4 + 1 = 97 leap years.

Total days in 400 years:
- Regular years: (400 - 97) × 365 = 110,595
- Leap years: 97 × 366 = 35,502
- Total: 146,097 days

In years (using 365.2425 average):
- 400 × 365.2425 = 146,097 (matches exactly)

So the Gregorian calendar averages 365.2425 days per year, very close to the 365.2422 actual tropical year. The small remaining error (~0.0003 days per year, or 26 seconds per year) is too small to require frequent correction.

Other calendar systems

Different calendars handle leap years differently:

Hebrew calendar: lunar with periodic 13-month "leap years" added 7 times every 19 years. Different from solar leap years.

Islamic (Hijri) calendar: pure lunar. No leap years. The year drifts ~11 days earlier each Gregorian year.

Chinese calendar: lunisolar. Leap months added periodically (about every 3 years).

Thai solar calendar: Buddhist Era with similar leap year rules.

Iranian calendar (Solar Hijri): solar. Leap year rules differ slightly from Gregorian.

For Gregorian-only purposes, the 4/100/400 rule is what matters.

February 29 special considerations

People born on February 29 (leap day) face a calendar oddity:

Gregorian birthday: only every 4 years.

Legal recognition: most jurisdictions treat their "birthday" in non-leap years as either February 28 (some countries) or March 1 (most). For age calculations, March 1 is the more common convention.

February 29 babies:
- Born 2000-02-29: they're 26 in 2026
- Their actual birthday: 6 actual leap days experienced (2004, 2008, 2012, 2016, 2020, 2024)

The age calculator uses March 1 for non-leap year "anniversary."

How leap years affect duration calculations

When calculating duration:

- Across a leap year: +1 day extra
- 1 year = 365 or 366 days depending on which year
- 365 days is the average in a non-leap year
- Leap year math is built into modern date libraries

Most date arithmetic handles leap years correctly without explicit handling.

When you need to check leap year

For pure programming:

```python
def isleapyear(year):
return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)

isleapyear(2024) # True
isleapyear(2025) # False
isleapyear(1900) # False
isleapyear(2000) # True
```

```javascript
function isLeapYear(year) {
return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
}
```

```sql
SELECT
year,
CASE
WHEN year % 400 = 0 THEN 'Leap'
WHEN year % 100 = 0 THEN 'Not leap'
WHEN year % 4 = 0 THEN 'Leap'
ELSE 'Not leap'
END AS leap_status
FROM years;
```

Most date libraries have a built-in `isLeapYear` function.

The exact tropical year

A few precise measurements:

- Tropical year (vernal equinox to vernal equinox): 365.2422 days
- Sidereal year (relative to fixed stars): 365.2564 days
- Anomalistic year (perihelion to perihelion): 365.2596 days
- Eclipse year: 346.6201 days

The Gregorian calendar's average year (365.2425) is closest to the tropical year. Calendar reformers chose tropical because it tracks the seasons.

Future leap year accuracy

The Gregorian rule is accurate but not perfect. Over 3,000 years, the calendar will drift by ~1 day from the actual tropical year. Future calendar reforms might add a "skip leap year every X" rule (e.g., every 4,000 years, skip the leap year that would otherwise occur).

For practical purposes, the Gregorian calendar is good enough for the next several millennia.

FAQ

Was 1900 a leap year?

No. Divisible by 100 but not by 400.

Was 2000 a leap year?

Yes. Divisible by 400.

Will 2100 be a leap year?

No. Divisible by 100 but not by 400.

What's the next non-100-rule-affected leap year?

2024 was leap. 2028 will be. 2032 will be. None of these touch the 100/400 rule.

How accurate is the Gregorian calendar?

About 1 day off per 3,000 years compared to the actual tropical year. Very accurate for any practical purpose.

Does the Hebrew calendar have leap years?

Yes, but they work differently. Leap years add a 13th month (Adar I and Adar II) about 7 times every 19 years.

How can I tell if my code handles leap years correctly?

Test with February 29 in a leap year. If date arithmetic treats it correctly (without throwing errors or skipping), you're good.

Bottom line

Leap year rule: divisible by 4, except divisible by 100, except divisible by 400. So 2024 and 2028 are leap years; 1900 and 2100 are not; 2000 was. The rule keeps the calendar accurate to within 1 day per ~3,000 years.

For age and duration calculations that account for leap years correctly, the age calculator and duration calculator handle them automatically.

Share this article

Related Articles