Most people learn one rule about leap years: every fourth year gets an extra day. It is right often enough to be useful and wrong often enough to matter. The full rule is three rules stacked on top of each other, and it is the reason 2000 was a leap year, 2100 will not be, and 2400 will be again.
A year is not a quarter of a day
The first rule fixes the obvious problem. A tropical year — the interval from one March equinox to the next — is about 365.2422 days, which is close to 365 and a quarter. Adding one day every four years approximates the fraction well, and that is exactly what the Julian calendar did from 46 BC.
The second rule fixes the approximation's error. A quarter is 0.25; the real fraction is 0.2422, so the Julian year is about eleven minutes too long. Over four centuries that is roughly three days, which is why the Gregorian reform of 1582 dropped ten days and then removed three leap days every four hundred years: centuries are not leap years. The average year became 365.24 days after that rule, much closer to the truth.
The rule that catches 2100
The third rule fixes the second rule’s error. A year of 365.24 days is still short of the tropical 365.2422 — by about 0.0022 days, or three minutes a year, which is a day every four and a half centuries. To trim that, every fourth century is a leap year after all: 1600, 2000, 2400. The result is an average year of 365.2425 days, which now runs about 26 seconds a year long — a day in roughly 3,300 years.
What a leap day is worth
The rule has social consequences that reach further than the calendar. A leap day is a real date, and it belongs to somebody: people born on 29 February exist in law as well as in fact, and different countries decide differently whether they celebrate in common years on 28 February or 1 March. Payroll systems, subscription billing and annual leave all have to decide what a year means when it has 366 days. Software that stores a year as a number and assumes 365 days has produced a long, quiet trail of off-by-one errors.
What makes the leap year interesting is that it is a compromise between two incompatible things: the length of the day, which is set by the Earth’s rotation, and the length of the year, which is set by its orbit. Neither divides evenly into the other, and no calendar can make them. The Gregorian rule is not a discovery about the solar system; it is a very good piece of bookkeeping that has kept civil dates within a day of the seasons for four centuries, and the residual error is small enough to be left to a future century to settle.