The Algorithmic-Rule for Leap Years and Leap Seconds

Updated on October 6, 2019
Glenn Stok profile image

Glenn Stok has a Master of Science degree. He enjoys studying concepts of time and envisioning theories regarding the space-time continuum.

To keep our Gregorian calendar in sync with mean solar time (UT1 time scale), we need to add a second once in a while in addition to adding a day every four years. However, there is more complexity that we need to consider.

As a Computer Systems Programmer, I once had to write an algorithm to determine the day of the week (Monday, Tuesday, etc.) for any specific calendar day. That required a thorough understanding of how we calculate the days of our calendar. So, I can explain it to you.


Extremely Accurate Time Measurements

We live in a time when we have the resources to do extremely accurate measurements. We have the technology to measure the rotation of the Earth so precisely that we can detect how it is slowing down. We use atomic clocks to keep an accurate account of time.

There are National Standards Agencies in many countries that maintain a network of atomic clocks. They are kept synchronized with extreme accuracy.

In addition, we have the master atomic clock at the U.S. Naval Observatory in Washington, providing the time standard for the U.S. Department of Defense.

The NIST-F1, a cesium fountain atomic clock developed at the NIST laboratories in 2013 at Boulder, Colorado, is more accurate than previous atomic clocks.1

Managing The Extra Fractions of Days

If it takes exactly 365 days for the Earth to revolve around the Sun, then we would have a perfect calendar, and we would not need to make corrections.

If a year had 365 and a quarter days precisely, then adding a day every four years would work wonderfully. Unfortunately, our Earth goes around the Sun in 365.2426 days, so adding a day every four years is adding too much.

We add an extra day, February 29th, every four years. However, we need to skip that addition once in a while.

I'll get a little deeper into the math to explain the details. If that additional fraction over 365 days were exactly .25 (an extra quarter of a day), then every four years adds up to a full day. If that were accurate, we would just add that extra day at the end of February every four years, but we don't. We need to skip some Leap Years.

We Need to Skip a Leap Year Every 100 Years

That fraction I mentioned before, 0.2426, is a little less than a quarter of a day. Therefore, every 100 years, we need to skip the addition of a day in February—otherwise, we would be adding too much.

Skipping a leap year every 100 years only works if the extra time were exactly 0.25. However, we are still off by almost .01 from a quarter day. That .01 adds up to 1 in 100 years. Therefore we need to skip a leap year every 100 years. If we didn't skip it, we'd be adding too many days to the calendar.

But wait! That still isn't perfect! We'll still get out of sync with solar time if we don't take it a step further.

We Need to Add an Extra Day Every 400 Years

As you can see, we still have that extra .0026 that we are off when skipping a leap year every 100 years. If you add that up, with some rounding error, that .0026 is a little over one day every 400 years (.0026 x 400 = 1.04).

That means that skipping a leap year every 100 years needs adjustment as well. We need to add a day back in. We need to keep that leap year every 400 years in order to get that one extra day added back.

The easiest way to add that missing day back in is "not to skip" a leap year when the year is a multiple of 400. In other words, we keep February 29th on the calendar every 400 years even though it is a multiple of 100.

Explaining It in One Sentence

To say it all in one sentence: We add a day every four years, but not every 100 years, unless it’s a 4th century year, at which point we do add that extra day anyway.

Table of Leap Years and the Reasons For It

Leap Year if Multiple of 4
But Skip if Multiple of 100
Unless it's a Multiple of 400
Leap Year?
As indicated in this table, we add a day for leap year every four years, but not every 100 years unless it’s a year divisible by 400.

Leap Seconds are Needed Too

The algorithm for leap years still does not provide perfect accuracy. Adding a few seconds is also required. Climate and geological events can cause the Earth’s revolution around the Sun to fluctuate.

In addition to that, the Earth's rotation around its own axis is not consistent. It tends to slow down and speed up ever so little.

A 9.0 magnitude Earthquake in Japan in 2011 had shifted the Earth's axis by an amount between 10 cm (4 inches) and 25 cm (10 inches). These fluctuations can change the length of a day by a tiny amount, and we need to adjust our calendar accordingly.2

To improve the accuracy of our time clocks, we need to add a second or two every year. It’s called a leap second.3

Scheduling the addition of an extra second to a year is done to make these adjustments.

It's usually added, when needed, as an additional second at midnight, Coordinated Universal Time (UTC), on June 30th or December 31st.

Prior Leap Second Time Adjustments

The International Earth Rotation and Reference Systems Service is the agency that decides when to make leap second time adjustments. They apply a leap second whenever necessary to keep our clock from being more than 0.9 of a second off.

Here is a table of dates when a second was added. Each addition was at midnight (UTC):

  • December 31, 2008
  • December 31, 2005
  • June 30, 2012
  • June 30, 2015
  • December 31, 2016
  • June 30, 2018

Final Thoughts

Physical events, such as earthquakes, can nudge the Earth just enough to require adding another leap second so that our clocks remain in sync with the way we represent time.

It's an ongoing struggle to keep our time measurements as accurate as possible. With the present technology, we have the means to do that.


  1. Physical Measurement Laboratory. (October 19, 2018).“NIST-F1 Cesium Fountain Atomic Clock.” NIST Time and Frequency Division
  2. "2011 Tōhoku earthquake and tsunami." Wikipedia
  3. "Leap second." Wikipedia

© 2012 Glenn Stok


    0 of 8192 characters used
    Post Comment
    • Glenn Stok profile imageAUTHOR

      Glenn Stok 

      23 months ago from Long Island, NY

      mr-d115 - That’s great work you did on the analysis, and a good catch.

      Assuming nothing else is affecting the numbers, that .96 hour lost every 400 years is equivalent to 10 seconds per year. Therefore adding one second every year is not enough, as you are pointing out.

      There is another piece to the puzzle that needs to be included in your calulations. The Earth's rotation is slowing down. In 400 years that’s another .006 seconds, which I admit isn’t close the the 10 second loss you calculated, so your question remains a pertinent consideration.

      There is one other thing. The period of the Earth's rotation is slightly irregular. So more needs to be considered in the calculation.

      As a last straw, more leap seconds can always be added. One every other month over a 400 year period will put your calculation in sync. But that’s only necessary if nothing else is affecting the calculation, as I mentioned at the start of my reply.

      Interesting discussion. Thanks for your worthy comment and effort.

    • profile image


      23 months ago

      The calculation .0026 x 400 = 1.04 shows that we fall behind by 1.04 days every 400 years and explains why we need to add an extra leap day every 400 years. But what about the .04 days that we still fall behind every 400 years. .04 x 24 hours = .96 or about 1 hour every 400 years. You indicated a concern for compensating for lost seconds with leap seconds. Is any compensation made for that lost .96 hour every 400 years?

    • Kristen Howe profile image

      Kristen Howe 

      4 years ago from Northeast Ohio

      My pleasure Glenn. I always wondered about the leap year and never heard of leap seconds.

    • Glenn Stok profile imageAUTHOR

      Glenn Stok 

      4 years ago from Long Island, NY

      Kristen Howe - It sure is interesting. The Earth's rotation is slowing down, requiring the addition of leap seconds. Thanks for the vote up. Much appreciated.

    • Kristen Howe profile image

      Kristen Howe 

      4 years ago from Northeast Ohio

      Glen, this was real interesting to know we had a extra leap second last month and next year is a leap year. This was well-written and intriguing to know the history behind the leap year. Voted up!


    This website uses cookies

    As a user in the EEA, your approval is needed on a few things. To provide a better website experience, uses cookies (and other similar technologies) and may collect, process, and share personal data. Please choose which areas of our service you consent to our doing so.

    For more information on managing or withdrawing consents and how we handle data, visit our Privacy Policy at:

    Show Details
    HubPages Device IDThis is used to identify particular browsers or devices when the access the service, and is used for security reasons.
    LoginThis is necessary to sign in to the HubPages Service.
    Google RecaptchaThis is used to prevent bots and spam. (Privacy Policy)
    AkismetThis is used to detect comment spam. (Privacy Policy)
    HubPages Google AnalyticsThis is used to provide data on traffic to our website, all personally identifyable data is anonymized. (Privacy Policy)
    HubPages Traffic PixelThis is used to collect data on traffic to articles and other pages on our site. Unless you are signed in to a HubPages account, all personally identifiable information is anonymized.
    Amazon Web ServicesThis is a cloud services platform that we used to host our service. (Privacy Policy)
    CloudflareThis is a cloud CDN service that we use to efficiently deliver files required for our service to operate such as javascript, cascading style sheets, images, and videos. (Privacy Policy)
    Google Hosted LibrariesJavascript software libraries such as jQuery are loaded at endpoints on the or domains, for performance and efficiency reasons. (Privacy Policy)
    Google Custom SearchThis is feature allows you to search the site. (Privacy Policy)
    Google MapsSome articles have Google Maps embedded in them. (Privacy Policy)
    Google ChartsThis is used to display charts and graphs on articles and the author center. (Privacy Policy)
    Google AdSense Host APIThis service allows you to sign up for or associate a Google AdSense account with HubPages, so that you can earn money from ads on your articles. No data is shared unless you engage with this feature. (Privacy Policy)
    Google YouTubeSome articles have YouTube videos embedded in them. (Privacy Policy)
    VimeoSome articles have Vimeo videos embedded in them. (Privacy Policy)
    PaypalThis is used for a registered author who enrolls in the HubPages Earnings program and requests to be paid via PayPal. No data is shared with Paypal unless you engage with this feature. (Privacy Policy)
    Facebook LoginYou can use this to streamline signing up for, or signing in to your Hubpages account. No data is shared with Facebook unless you engage with this feature. (Privacy Policy)
    MavenThis supports the Maven widget and search functionality. (Privacy Policy)
    Google AdSenseThis is an ad network. (Privacy Policy)
    Google DoubleClickGoogle provides ad serving technology and runs an ad network. (Privacy Policy)
    Index ExchangeThis is an ad network. (Privacy Policy)
    SovrnThis is an ad network. (Privacy Policy)
    Facebook AdsThis is an ad network. (Privacy Policy)
    Amazon Unified Ad MarketplaceThis is an ad network. (Privacy Policy)
    AppNexusThis is an ad network. (Privacy Policy)
    OpenxThis is an ad network. (Privacy Policy)
    Rubicon ProjectThis is an ad network. (Privacy Policy)
    TripleLiftThis is an ad network. (Privacy Policy)
    Say MediaWe partner with Say Media to deliver ad campaigns on our sites. (Privacy Policy)
    Remarketing PixelsWe may use remarketing pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to advertise the HubPages Service to people that have visited our sites.
    Conversion Tracking PixelsWe may use conversion tracking pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to identify when an advertisement has successfully resulted in the desired action, such as signing up for the HubPages Service or publishing an article on the HubPages Service.
    Author Google AnalyticsThis is used to provide traffic data and reports to the authors of articles on the HubPages Service. (Privacy Policy)
    ComscoreComScore is a media measurement and analytics company providing marketing data and analytics to enterprises, media and advertising agencies, and publishers. Non-consent will result in ComScore only processing obfuscated personal data. (Privacy Policy)
    Amazon Tracking PixelSome articles display amazon products as part of the Amazon Affiliate program, this pixel provides traffic statistics for those products (Privacy Policy)
    ClickscoThis is a data management platform studying reader behavior (Privacy Policy)