Leap Year Calculator

JJ Ben-Joseph headshot JJ Ben-Joseph

Introduction

A leap year is a calendar year with one extra day added to keep the calendar aligned with Earths motion around the Sun. In an ordinary year, the Gregorian calendar has 365 days. In a leap year, February has 29 days instead of 28, so the year has 366 days. That extra day may seem small, but it solves a real problem: the solar year is not exactly 365 days long. It is about 365.2422 days, so a calendar that ignored the fraction would slowly drift away from the seasons.

This calculator checks whether a year is a leap year under the Gregorian calendar rule and also shows the nearest leap years before and after the year you enter. That makes it useful for quick date checks, schoolwork, software testing, historical comparisons, and general curiosity. If you have ever wondered why 2000 was a leap year but 1900 was not, this page explains the logic in plain language and lets you test any integer year directly.

The Gregorian calendar, introduced in 1582, improved on the older Julian calendar. The Julian system treated every year divisible by 4 as a leap year. That rule was simple, but it made the average year slightly too long. Over many centuries, the mismatch caused the calendar to drift relative to the equinoxes and solstices. The Gregorian reform corrected that drift by skipping some century leap years. The result is the leap-year rule still used in most civil calendars today.

Understanding Leap Years

Leap years are intercalary years that contain one extra day in February. In the common year, the Gregorian calendar contains twelve months and a total of 365 days. Because Earth's revolution around the Sun actually takes approximately 365.2422 days, a yearly calendar that always has exactly 365 days would slowly drift out of alignment with the astronomical seasons. To keep the calendar synchronized with the equinoxes and solstices, an additional day is inserted in some years, resulting in a year that has 366 days. The system that decides which years receive an extra day is what this calculator evaluates.

The Gregorian calendar, introduced in 1582 by Pope Gregory XIII, refined the previous Julian calendar by modifying the leap year rule. The Julian system considered every year divisible by four to be a leap year. Over centuries this produced an error because the average year became 365.25 days, slightly longer than the true solar year. The Gregorian reform shortened the average to 365.2425 days by omitting three leap days every four centuries. The new rule can be succinctly expressed using modular arithmetic. A year is a leap year if it is divisible by four, except those divisible by one hundred, unless they are also divisible by four hundred. In logical symbols:

L ( y ) = ( y e1 0 mod 400 ) e8 ( y e1 0 mod 4 e7 y e0 0 mod 100 )

This expression, while compact, hides centuries of calendrical experimentation. The Julian calendar's assumption of a 365.25-day year worked reasonably well at first, but by the sixteenth century the accumulated drift reached about ten days. Seasons were shifting relative to the calendar, affecting agricultural planning and the scheduling of religious festivals. The Gregorian reform solved the problem by advancing the calendar ten days and adopting the rule above. Leap years thus occur in years like 2020 or 2000, but not in 2100 or 1900.

The calculator implements the logic by evaluating the modulus of the year parameter with respect to 4, 100, and 400. When the user submits a year, the script reports whether that year is leap and also identifies the previous and next leap years. This is accomplished by incrementally scanning downward and upward from the provided year until years satisfying the leap rule are found. Below is a table demonstrating the outcome for several sample years.

Sample leap-year outcomes in the Gregorian calendar
Year Divisible by 4? Divisible by 100? Divisible by 400? Leap Year?
1999 No No No No
2000 Yes Yes Yes Yes
2001 No No No No
2004 Yes No No Yes
2100 Yes Yes No No

Each row illustrates the conditional nature of the rule. Although 2100 is divisible by four, it fails the leap test because it is a century year not divisible by 400. The year 2000, however, satisfies the 400-year criterion and thus remains a leap year, aligning the average calendar year more closely with the solar year. Century years are therefore special corrections inserted to prevent drift. Without them, the calendar would lose roughly three days every four hundred years.

Leap years influence a surprising number of practical activities. Finance professionals use day-count conventions that treat leap years differently when computing interest accruals. Software engineers must manage edge cases for February 29 in date libraries and data storage. Sports statisticians adjust for leap days in performance metrics. Genealogists pay attention to leap years when reconstructing family timelines. Even pop culture references February 29 as a rare birthday, leading to playful "leapling" communities. Accurately detecting leap years is foundational to each of these tasks.

Historically, other cultures devised their own mechanisms for reconciling lunar and solar cycles. The ancient Egyptians employed a civil calendar of 365 days with no leap correction, slowly drifting relative to the Nile's flooding. The Islamic calendar is strictly lunar and makes no attempt to align with the solar year, causing holidays like Ramadan to migrate through the seasons. The Hebrew calendar inserts an entire leap month seven times in a nineteen-year cycle. The Gregorian rule has proven resilient because it balances simplicity with long-term accuracy, making the extra day in February a familiar event in the modern world.

Mathematically inclined readers may appreciate that the average length of the Gregorian year can be computed by examining a 400-year cycle. Within such a span, the leap year rule designates 97 leap years (every fourth year minus the three century years not divisible by 400). The average year length becomes 365 d7 400 + 97 400 = 365 . 2425 days. This is strikingly close to the current estimate of 365.2422 days for the tropical year. The residual error of only about 26 seconds per year means the Gregorian calendar will drift by one day in roughly 3,300 years. Some proposals suggest skipping leap years in years divisible by 4000 to correct this eventual drift, but no civil authority has adopted the idea.

The algorithm implemented here handles any positive or negative integer year, allowing the exploration of dates deep into the past or future. While the Gregorian calendar was not retroactively applied before 1582 in reality, historians often use the proleptic Gregorian calendar for calculations. This approach extends the leap year rule backward to simplify chronological computations. The calculator therefore interprets year 1500 as common and year 1600 as leap even though different regions adopted the Gregorian reform at various times.

How to Use

Using the calculator is straightforward. Enter a whole-number year in the input field, then press the check button. The result area will tell you whether that year is a leap year and will also display the previous leap year and the next leap year. If you enter a non-number or leave the field blank, the calculator asks for a valid year instead.

The input is a year number rather than a full date, because leap-year status depends only on the year itself. You do not need to enter a month or day. For example, if you type 2024, the calculator will report that 2024 is a leap year. If you type 2023, it will report that 2023 is not a leap year and will show 2020 as the previous leap year and 2024 as the next one.

This page accepts negative years as integers as well, which can be useful for mathematical exploration or proleptic Gregorian calculations. Keep in mind, however, that historical date usage was not uniform across countries and eras. The calculator applies one consistent rule for simplicity, so it is best understood as a Gregorian rule checker rather than a full historical calendar conversion tool.

Formula

The leap-year rule can be stated in plain language before looking at the formula. First, if a year is not divisible by 4, it is not a leap year. Second, if it is divisible by 4 but not by 100, it is a leap year. Third, if it is divisible by 100, it must also be divisible by 400 to remain a leap year. This three-part test is what prevents the calendar from drifting too quickly over long periods.

In code, the rule is often written as a compact logical condition:

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

The percent symbol means remainder after division. So y % 4 === 0 means the year divides evenly by 4. The same idea applies to 100 and 400. The calculator uses this exact logic to determine the answer, then searches backward and forward to find the nearest leap years around the entered year.

Another way to understand the formula is to think in layers. Most years that are multiples of 4 qualify. Century years are then removed because they would otherwise add too many leap days. Finally, every 400th year is added back in because removing all century years would overcorrect. That balance is why years such as 1600 and 2000 are leap years, while 1700, 1800, 1900, and 2100 are not.

Example

Suppose you enter the year 1900. At first glance, it looks like it should be a leap year because it is divisible by 4. However, 1900 is also divisible by 100, which triggers the century exception. To pass the final test, it would need to be divisible by 400. Since 1900 divided by 400 does not produce a whole number, the calculator correctly marks it as not a leap year.

Now compare that with 2000. It is divisible by 4, divisible by 100, and also divisible by 400. Because it satisfies the 400-year exception, it is a leap year. This pair of examples is one of the clearest ways to see why the Gregorian rule is more precise than the simple "every four years" rule.

Here is a quick worked example with a more recent year. If you enter 2024, the calculator checks divisibility by 4, 100, and 400. The year 2024 is divisible by 4, not divisible by 100, and therefore qualifies as a leap year. The result will say that 2024 is a leap year, with 2020 as the previous leap year and 2028 as the next leap year.

Limitations and Assumptions

This calculator applies the Gregorian leap-year rule consistently to all integer years. That is useful for education and computation, but it comes with an important assumption: it treats the Gregorian calendar as if it can be extended backward and forward indefinitely. In real history, countries adopted the Gregorian reform at different times, and some used other calendar systems before switching. As a result, a historically accurate answer for a date before adoption may depend on location and context.

The tool also checks leap-year status only. It does not validate full dates such as February 29 on a specific calendar system, and it does not convert between Julian, Gregorian, Hebrew, Islamic, or other calendars. If you need legal, archival, or region-specific historical dating, you may need a specialized chronology source rather than a simple leap-year checker.

Even with those limitations, the calculator is reliable for the modern Gregorian rule and for most educational or programming uses. It is especially helpful when testing date logic, understanding century exceptions, or quickly confirming whether a year contains February 29. For everyday use, that is usually exactly the information people need.

Enter any whole-number year to check whether it is a leap year in the Gregorian calendar.

Enter a year to see if it's leap.