ThisCalculator

Everyday

Leap Year Calculation Logic Explained

Updated · Standard formula, shown below

The calculator for this page is switched off while it is checked. The formula is below, and the worked example in the article shows how to use it by hand.

Leap Year Calculation Logic Explained

This calculator works out whether a given year is a leap year using the standard Gregorian calendar rules, and it also shows the number of days in that year. You enter a year, and you get a clear yes/no answer plus the day count. The logic is simple: a year is a leap year if it is divisible by 4, except if it is divisible by 100, unless it is also divisible by 400.

Formula

The leap year rule is written as:

Leap year if: (year is divisible by 4) AND (year is not divisible by 100) OR (year is divisible by 400).

In symbols, for a year y:

(y % 4 == 0 && y % 100 != 0) || y % 400 == 0

Where % means “remainder after division�. For example, 2024 % 4 = 0 because 2024 divided by 4 leaves no remainder. The variables are:

  • y – the year you are checking (integer, e.g., 2024).
  • % – modulo operator, gives the remainder after division.
  • && – logical AND (both conditions must be true).
  • || – logical OR (at least one condition must be true).

The number of days in the year is simply 365 plus 1 if it is a leap year, so 366 days for leap years, 365 otherwise.

Worked Example

Using the default year 2024:

  1. Check if 2024 is divisible by 4: 2024 ÷ 4 = 506, remainder 0 → true.
  2. Check if 2024 is divisible by 100: 2024 ÷ 100 = 20 remainder 24 → false (so the “not divisible by 100� part is true).
  3. Since the first two conditions are true (divisible by 4 and not by 100), the year is a leap year. The third condition (divisible by 400) is not needed.
  4. Days in year = 365 + 1 = 366.

The calculator shows “Leap year? 1� (meaning yes) and “Days in year 366�.

Why the Rule Exists

The Earth takes about 365.2422 days to orbit the Sun, not exactly 365 days. If we ignored the extra 0.2422 days, the calendar would drift: seasons would shift about 1 day every 4 years, and after a few centuries, summer would start in December. To fix this, the Julian calendar (introduced in 45 BCE) added a leap day every 4 years, giving an average year of 365.25 days – still 0.0078 days too long. By the 1500s, the calendar had drifted about 10 days, so Pope Gregory XIII introduced the Gregorian calendar in 1582 with the refined rule we use today. By skipping leap years in century years not divisible by 400, the average year length becomes 365.2425 days, which is very close to the actual 365.2422.

How to Use the Calculator

Enter any year (positive integer, typically from 1 onward). The calculator will instantly tell you if it is a leap year and how many days it has. For example:

  • 2000 – divisible by 400 → leap year (366 days).
  • 1900 – divisible by 100 but not 400 → not a leap year (365 days).
  • 2024 – divisible by 4 and not by 100 → leap year.
  • 2025 – not divisible by 4 → not a leap year.

This works for any year in the Gregorian calendar, which most of the world uses today. For years before 1582, the Julian calendar rules (every 4 years) would apply historically, but the calculator uses the modern Gregorian rule for simplicity.

Common Mistakes When Calculating

One frequent error is forgetting the century exception. Many people think every year divisible by 4 is a leap year, but 1900 is not. Another mistake is applying the 400 rule too broadly – a year like 2000 is a leap year because it is divisible by 400, but a year like 2100 will not be. Also, note that the rule applies to the Gregorian calendar; other calendars (like the Hebrew or Islamic) have different leap systems. When programming, be careful with the order of operations: the AND condition is evaluated before the OR, so the expression works as intended. If you write it incorrectly, you might get wrong results for century years.

Limitations of the Formula

The Gregorian rule is accurate for the next few thousand years, but it is not perfect. The average year length is 365.2425 days, while the actual tropical year is about 365.2422 days, so there is a tiny error of about 0.0003 days per year, which accumulates to about 1 day every 3,300 years. Some proposals exist to skip leap years in years divisible by 4000, but they are not official. Also, the rule assumes the Earth’s rotation and orbit remain constant, which is not exactly true, but the changes are negligible for practical purposes. For historical dates before 1582, the Julian calendar was used in many regions, so the leap year pattern was different (every 4 years without exception).

Frequently Asked Questions

Why is 2000 a leap year but 1900 is not?

Because 2000 is divisible by 400, which makes it a leap year despite being a century year. 1900 is divisible by 100 but not by 400, so it is not a leap year. The rule is: century years are leap years only if divisible by 400.

What happens if I enter a year before 1582?

The calculator still uses the Gregorian rule, which may not match historical calendars. Before 1582, many regions used the Julian calendar, where every year divisible by 4 was a leap year. So for historical dates, you would need to know which calendar was in use.

Is there a leap year every 4 years?

No, not exactly. There is a leap year every 4 years, except for century years that are not divisible by 400. So the pattern is: 4-year cycle, but every 100 years you skip, and every 400 years you don’t skip. This gives an average of 97 leap years per 400 years.

How many leap years are there in a century?

Usually 24, but if the century year is divisible by 400, there are 25. For example, the 20th century (1901-2000) had 25 leap years (including 2000), while the 21st century (2001-2100) will have 24 because 2100 is not a leap year.

Does February always have 28 days in a non-leap year?

Yes, in the Gregorian calendar, February has 28 days in a common year and 29 days in a leap year. The leap day is added at the end of February, which is why February 29 exists only in leap years.

Related

Formula used
in y | Year | - | 2024 | 0
out is_leap | Leap year? | - | (y % 4 == 0 && y % 100 != 0) || y % 400 == 0 | 0
out days | Days in year | - | 365 + ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0) | 0

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.