Get the Mach newsletter.

Everyone knows a year lasts 365 days. The number is right on your calendar — except during leap years, when you get an annoying reminder that the 365-day year doesn’t quite match up with the true year, as defined by how long it takes the Earth to complete one orbit around the sun.

Forcing the human calendar to stay in sync with nature’s cycles requires some awkward contortions. Every four years, February has 29 days instead of the usual 28. So 2020 will be a 366-day year. But if a year is divisible by 100, there’s no extra day — unless the year is divisible by 400, in which case there is an extra day after all. In other words, 2100 will not be a leap year, but 2400 will.

It’s all a bit of a mess, but it’s necessary.

Why do we have leap years?

There would be no need for leap years if Earth’s orbit took exactly 365 days. In reality, the solar year is a messy 365.2422 days. Thus at the 365-day mark, Earth hasn’t quite circled all the way back to its starting point.

That lag of a 0.2422 day might seem small, but it adds up. If we had nothing but 365-day years, the calendar would keep slipping relative to the seasons. After three centuries, Jan. 1 would come in autumn. After six centuries, it would land in summer.

That was the strange situation in Rome in the 1st century BCE, when the calendar had slipped a full two months out of alignment with the seasons. In the words of University of Houston historian Richard Armstrong, “The Roman calendar was in a terrible mess.”

Who created the leap year?

In 46 BCE, Julius Caesar declared that the current year would last 445 days, bringing the calendar back into alignment with the seasons. Irritated Roman officials referred to it as the annus confusionis. Armstrong calls it simply “the longest year in history.” To limit any future confusion, Caesar instituted a new calendar (now called the Julian calendar) that added a leap day to February once every four years.

That was the beginning of the leap year as we know it today, but not the end. The Julian calendar produces years that average 365.25 days long — much better than the Roman calendar it replaced, but still not a perfect match with the actual solar year.

By the 16th century, the error had added up to a quite-noticeable 10 days. In response, Pope Gregory XIII replaced the Julian calendar with the more refined “Gregorian” one, which introduced the modern schedule of leap days. He also restored the seasons and holidays to their original place by decreeing a leap in time: Oct. 4, 1582 was followed by Oct. 15.

Does every culture have a leap year?

Ancient people were well aware that the years didn’t divide evenly into days or lunar months, so they devised a number of solutions.

The Hindu, Chinese and Hebrew calendars incorporated leap months to keep pace with the seasons. (Holidays based on those traditional calendars still follow a lunar pattern, which is why they move around relative to our Gregorian months and days.)

Ancient Egyptians used a fixed 365-day year, but Egypt’s Ptolemy III devised a leap-year calendar in 238 BCE, well ahead of Julius Caesar. And five centuries before Pope Gregory XIII, Persian astronomer Omar Khayyam measured the length of the year as 365.24219858156 days and devised an elaborate leap-year schedule to match it.

In 1973, Russian math historians Adolph Yushkevich and Boris Rosenfeld analyzed Khayyam’s scheme and deemed it superior in accuracy to the Gregorian calendar.

Will our calendars need to change again?

According to Yushkevich and Rosenfeld, our current calendar is accurate to one day in 3,333 years. That means we have until sometime around the year 5000 to decide whether to declare an extra leap day, or to reform our calendar yet again.

Do other worlds have leap years?

There’s no natural reason for a planet to complete a round number of rotations (days) over the course of one orbit (its year). Every world therefore would require its own version of leap years if you wanted to use a calendar with a whole number of days.

On Mars, for instance, a year lasts 668.599 Martian days. The late Frank Bauregger, an engineer and space enthusiast, designed a highly accurate Mars Calendar of 668 days, with leap days in all years divisible by 2 or 5.

The strangest leap year in the solar system happens on Venus, where one rotation of the planet takes longer than its entire year. Further muddying things, Venus rotates backward. The net result of all those motions is that the solar day (the time from one sunrise to the next) lasts an agonizing 117 Earth days on Venus, and a Venusian year is just 1.92 Venusian solar days long. No matter how you work the problem, that’s never going to come out nice and even. Then again, Venus is covered with thick clouds of sulfuric acid, so if you go there you won’t be watching the sun anyway.

What is a “leap second”?

On 27 occasions since 1972, the International Earth Rotation and Reference Systems Service — the organization that keeps track of our planet’s motion in space — has added an extra “leap” second into the length of a day. The reason for the adjustment is that the gravitational pull of the sun and moon drags on the Earth as it rotates, slowing it down and lengthening the day. The effect is tiny, but in the age of atomic clocks, it's significant enough to require adjustments.

The last leap second occurred at midnight on Dec. 31, 2016. It brought the solar day back in alignment with Universal Time, the global standard clock used on the internet as well as in aviation and other sensitive applications. Unlike leap years, leap seconds are unpredictable because Earth’s rotation fluctuates irregularly in response to weather and the slow churning of hot rock deep underground.

The next leap second will happen on June 30, 2020 — maybe. Or maybe not. In this case, there’s no way to plan your calendar. All you can do is sit back and let the time police do their job.

WANT MORE STORIES ABOUT ASTRONOMY?

FOLLOW NBC NEWS MACH ON TWITTER, FACEBOOK, AND INSTAGRAM.

Corey S. Powell contributed.