A year is almost exactly 365 days...almost, but not quite. For millennia, people have tried to create calendars that account for that "not quite" bit. It's why we have leap days and why, just once, there was a February 30.
The Moon's Calendar
It's only relatively recently - say, the last 2,500 years or so - that people seemed to care all that much about the year. To be sure, people were aware of seasons and how temperatures and weather patterns seemed to cycle through and repeat every few hundred days or so. But these were practical matters, more linked to agriculture and the harvest, rather than a matter that required precise measurement. The knowledge that a year lasts roughly 365 days is quite ancient and independently discovered countless times throughout the world, but this knowledge didn't inform the creation of the first calendars.
That fell to another, far more easily observed physical phenomenon: the phases of the Moon. The time between two full moons is on average just over 29.5 days, meaning it was easy to build a lunar calendar in which the months - a word that of course is derived from "Moon" - alternate between 29 and 30 days. Adding twelve of these alternating months together gives a year of 354 days, which isn't a bad approximation of the length of a year, all things considered.
Most early calendars prioritized the cycles of the Moon over the length of the year, with years being defined so that they had a whole number of months. This means that a leap month has to be added every two or three years to keep the twelve lunar months roughly in sync with their respective times of the year.
A 5th century BCE astronomer known as Meton of Athens is credited with discovering the Metonic Cycle, which notes that 19 solar years and 235 lunar months are almost exactly equal, with only about two hours difference between them. This means that there need to be seven leap months every 19 years to keep the lunar and solar calendars in harmony, an insight that makes long-term calendar-making a breeze. This fact was known to the Greeks, Babylonians, and Chinese, among other ancient cultures.
The Great February Shortening
Our current Gregorian calendar is the successor of the earlier Julian calendar, which in turn traces its origins back to a calendar that was devised sometime during Rome's semi-legendary beginnings. 2,700 or so years later, it's impossible to know exactly what happened - particularly when the credit for the original Roman calendar is attributed to the city's mythical founder Romulus - but we can say that the earliest Romans likely imported a true lunar calendar from the Greeks, which at some point they converted to a loose solar calendar.
I say "loose" because while this new calendar had 365 days and its 30-day and 31-day months no longer accurately tracked the phases of the Moon, the Romans clearly weren't too bothered about overly precise timekeeping. For one thing, there were only ten months, which correspond to the modern March through December and totaled 304 days of the year.
This, incidentally, is why the ninth through twelfth months have names - September, October, November, December - that derive from the Latin words for seven through ten. Those once were their positions in the Roman calendar. The end of the year between the final month December and first month March belonged to no specific month. This might seem like horribly shoddy timekeeping, but the early Romans were primarily concerned with practical questions of the harvest. The wintry period between December and March didn't factor into the harvest, so what was the point of assigning specific months to describe them?
Again, this is all shrouded in legend and tradition, but the story is that Numa Pompilius, the likely mythical second king of Rome, reformed the calendar by adding January and February to the beginning of the year and attempting to switch things back to a lunar calendar. Complicating matters was the Roman belief that odd numbers were lucky, so Numa made eight months last 29 days and four others be 31 days longs for a total of 356 days.
But, of course, that was an even number, rather defeating the point of the whole odd-obsessed exercise, so one month was made even and, to minimize the bad fortune, shorter than all the others. And if you're going to pick a shortest, unluckiest month, I think everyone in the northern hemisphere can agree that there is no more perfect candidate for that dubious honor than February. Adding a leap month of 27 days and shortening February for an extra-long year of 377 or 378 days every so often kept Numa's calendar on track with the solar year.
While this system may seem hopelessly chaotic and unwieldy, Numa's calendar worked well enough for hundreds of years, only breaking down twice. The first instance came around 191 BCE, apparently due to the chaos wrought by the Carthaginian general Hannibal in the Second Punic War. The second breakdown occurred in the waning years of the Roman Republic, as the topic of when to add a leap month - more generally known as intercalation - became a charged political issue.
It isn't hard to see why. The republic was governed by a pair of consuls who both served for a term of one year. But depending on how it was defined, a year could be either 355, 377, or 378 days, which meant certain consuls would get to hold power for significantly longer than their predecessors and successors. The decision to lengthen the year fell to the pontifex maximums, a post that had begun as the high priest of the Roman religion but had since evolved into a powerful political post coveted by the elite. As Julius Caesar and his political rivals jockeyed for control, the decision to add leap months stopped being about keeping the calendar aligned with the year and started being almost exclusively about sticking it to one's political enemies.
By the time Julius Caesar had assumed his title of "dictator in perpetuity" in 46 BCE, the calendar was badly out of alignment and nobody was really sure what day it was anymore. Caesar's time in Egypt had brought him into contact with the scholars of Alexandria, who informed him that some centuries prior a Greek scholar - either Cleostratus in the 5th century or Eudoxus of Cnidus in the 4th, we're not sure which - had determined the true length of the year was just about 365.25 days long. The historians Plutarch and Pliny the Elder, both writing about a century later, say that upon his return to Rome Caesar enlisted the aid of the Mediterranean world's greatest philosophers and mathematicians to implement a new calendar, with the Alexandrian astronomer Sosigenes getting the main credit for the new calendar.
The result of all this was something very close to the calendar we use today, as two days were added to January, Sextilis - later renamed August by Caesar's successor, who not coincidentally was named Augustus - and December to bring them up to 31 days, and a single day was added to April, June, September, and November to get them to 30. It should be pointed out that the most logical thing to do would probably have been to have seven 30-day months and five 31-day months to get to 365, but for reasons that are likely lost to history Caesar decided to keep February just 28 days long, giving it the small consolation of a leap day every four years to keep the calendar in line with the year.
There's a legend that Augustus swiped a day from February to make his month as long as Caesar's month July, but it's just that - a legend, and an easily debunked one at that. Perhaps, just like Numa (or whoever actually came up with the original Roman calendar) the makers of the Julian calendars simply disliked February and wanted the wintry cold over with as quickly as possible. Whatever the specific motivations, the new calendar was in place and went into effect in 45 BCE, with Caesar forced to add three leap months to 46 BCE - making the year an insane 445 days long - to bring the calendar back into alignment with the actual solar year.
Too Many Leap Days
As I said before, Caesar had been told that the year was almost 365.25 days long. The difference is small enough that adding a leap day every four years seems like a perfectly decent approximation, and the discrepancy isn't the sort of thing easily noticed over the length of a human lifetime. Certainly, Caesar's use of February 29 in his calendar represented a huge upgrade over his inspiration for a true solar calendar, that used by the Egyptians, which simply used exactly 365 days and made no effort to correct this error, resulting in what became known as the "wandering calendar."
But the problem is that the solar year is actually 365.24219 days, or 11 minutes and 14.784 seconds short of the year as defined by the Julian calendar. Caesar, or at least his learned team of advisers, should have been aware of this problem, considering the Greek polymath Hipparchus had come up with that measurement back in the 2nd century BCE. But perhaps for ease of use - and the fact that this discrepancy wouldn't represent any real problems for at least a thousand years - the makers of the Julian calendar ignored this problem.
By the 16th century, the problem could no longer be put to one side. The calendar had drifted nearly two weeks from the actual solar year, meaning anything to do with the lunar calendar was now hopelessly out of sync. The specific impetus to reform the calendar came from Pope Gregory XIII. Because the date of the Easter celebration was tied to the timing of the spring equinox, the Catholic Church wanted to restore the calendar so that the equinox again fell on its "correct" date of March 21. This date was actually when the equinox fell on 325 CE, the year of the Council of Nicaea that had first established when Easter would fall. By that time, the equinox had already drifted three days from when Julius Caesar first promulgated his calendar, meaning the equinox should arguably fall on March 24...but then, one arbitrary date is really as good as another.
For this new Gregorian calendar to work, two major changes were required. First, ten days would need to be deleted in order to correct the drift. Italian astronomer and key contributor to the new calendar Aloysius Lilius argued this should be accomplished by skipping leap days for the next forty years, but his German colleague Christopher Clavius persuaded the Pope that it would be better to simply skip ten days all in one go. That's just what the Church and a handful of Catholic countries did on Thursday, October 5, 1582, which they immediately followed with Friday, October 14. Most other countries that later made the switch also decided to simply skip ahead to realign the calendar, such as when Great Britain and its American colonies jumped from September 2 to September 14 in 1752.
The other crucial reform of the Gregorian calendar was to fix the number of leap years. We often say February 29 happens once every four years, but that elides over the precise point our current calendar is meant to fix. The leap day actually occurs 97 times every 400 years, as years divisible by 100 but not 400 (so 1900 and 2100, but not 2000) are no longer leap years. That effectively makes the Gregorian year 365.2425 days long, which means the calendar won't lose a day for roughly 5,000 years.
The 19th century astronomer John Herschel actually proposed a way to improve even that level of precision by skipping the leap day on years divisible by 4000 - it wasn't accepted, but obviously there's still plenty of time to implement his idea. Still, on timescales of multiple thousands of years, it's not worth worrying about a day here or there, as the very gradual slowing of the Earth's rotation is going to throw off the calendar anyway.
The Making of February 30
So then, that's pretty much everything you need to know about February 29. But what about February 30? The date isn't totally unknown, at least not in certain technical areas that use artificially standardized calendars of twelve 30-day months. But that's hardly the same thing as an actual real, historical date of February 30. Well, that has happened - but only once.
To be sure, some attempts at calendar reform danced around the idea of lengthening February. The French revolutionary calendar I talked about in the recent decimal time post involved standard months of thirty days each, but these were all new months with no specific links to the traditional twelve. The Soviet Union played around with five-day and six-day weeks in its early planning calendars, which has led to the idea that they instituted standard 30-day months, but that isn't true. Their attempts at standardizing the workweek were simply overlaid onto the traditional Gregorian calendar, so February remained unchanged.