The leap year rule explained
A year is a leap year if it satisfies the Gregorian calendar rule: divisible by 4, EXCEPT for century years (divisible by 100), which must also be divisible by 400. This means 1900 was not a leap year (divisible by 100 but not 400), but 2000 was (divisible by 400). The next century year exception will be 2100, which will not be a leap year.
The purpose of leap years is to keep the calendar year aligned with the solar year — the time Earth takes to orbit the Sun — which is approximately 365.2422 days. Adding one extra day every 4 years gives 365.25 days per year on average. The century corrections reduce this to 365.2425 days per year, which matches the solar year closely enough that an additional correction will not be needed for about 3 200 years.
Is leap year = (year mod 4 = 0) AND NOT (year mod 100 = 0 AND year mod 400 ≠ 0)
True means leap year (366 days); false means common year (365 days).
Simplified: leap if (year mod 400 = 0) OR (year mod 4 = 0 AND year mod 100 ≠ 0)
Equivalent two-condition form often used in programming.