The Gregorian rule has three clauses. You get up to four. First guess how long it takes to slip by a full day, then try to beat it over 10,000 years.
The Gregorian calendar averages 365.2425 days per year. The real mean tropical year (equinox to equinox) is 365.24219. After how many years has the Gregorian calendar drifted a full day away from the seasons?
A year is a leap year if it passes the clauses below, checked top to bottom, and the last matching clause wins. Set a clause to 0 to switch it off. The Julian rule is clause 1 alone with 4.
Positive: the calendar has added more days than the sun needed, so the equinox lands earlier on the calendar page. Negative: the opposite. The curve is a sawtooth because leap days arrive in whole days. The gray band is within half a day.
The Julian year is 365.25 days. Per the sources below it gains one day every 128 years, and by 1582 the equinox had slipped about 10 days since the Council of Nicaea in 325, so Thursday 4 October 1582 was followed by Friday 15 October. Drag the year to see how far the Julian calendar has drifted from the seasons by that year, using the same simulator.
1582
Adding a clause trades complexity for accuracy. The Gregorian rule already needs two exceptions to get from 365.25 to 365.2425, and that remaining gap of 0.00031 days is the 27 seconds you saw. Any rule is just a fraction of leap years per year. Your rule works when its fraction lands near 0.24219. Spotting those fractions is what the reformers did, and a century clause is the cheapest way to shave 0.0075 off the Julian mean.
One caveat: the tropical year itself changes slowly, so all drift numbers use the fixed value 365.24219 days (mean in the year 2000). Over 10,000 years the true figure is therefore a bit uncertain; the Wikipedia article on the tropical year cites an estimate that Gregorian would end up between three hours and four days behind.
Everything here is computed in your browser. No data is sent anywhere.