Rules
How to decide a leap year
The Gregorian 4/100/400 rule, where it comes from, days in the year and the weekday of January 1 — three views that cross-check each other.
The Gregorian leap rule is a three-tier 4/100/400 rule. It fixes the year at 365.2425 days, only about 26 seconds off the Earth's 365.2422-day orbit.
Rule 1
A year divisible by 4 is usually a leap year.
Rule 2
But a century year divisible by 100 is not a leap year (e.g. 1700, 1800, 1900, 2100).
Rule 3
Yet a century year divisible by 400 is a leap year after all (e.g. 1600, 2000, 2400).
Days
A leap year has 366 days (extra February 29); a common year has 365.
Weekday
Weekday of Jan 1 = (year + floor((year-1)/4) - floor((year-1)/100) + floor((year-1)/400)) mod 7.