In the ancient world there were several societies, including Egyptian, that used a calendar that was 365 days long. However the current civil calendar that is recognised by almost all governments in the world started life with the Romans.

The Romans had started dating things and using a calendar in 735 BC, when they set 304 days in the year, and started the year on March 1st. It didn’t take them long to figure out this was wrong and in about 700 BC they changed the year to have 355 days.

However they weren’t consistent about it. With politicians adding and taking away dates at whim. Up to 47 BC there were about 356 days in the average year. Up to this point it was (and still is) very difficult to determine what the actual date was when things occurred.

Julius Caeser got various experts from across the empire to come up with a new consistent calendar, creating the Julian Calendar. 46 BC had 67 extra days added to bring things more or less back into line. In 45 BC the beginning of the year was made January 1st, the length of the year was set at 365 days (366 for leap years) and the length of the months set to how we now know them. Leap years were still a little haphazard and scholars still disagree which years were considered leap years. However the rules were formalised and by 4 AD every fourth year was considered a leap year, making the year an average of 365.25 days.

The Christian concept of "AD", Anno Domini = in the year of our Lord (and therefore BC = Before Christ), was not defined until "531 AD" by a monk, Dionysius Exiguus (Dennis the Small). He counted backward to where he supposed 1 AD should be. However he got it wrong. This means Herod died in 4 BC, and he was supposed to be alive when Jesus was born. So calendar remains at least 4 years out.

In 1582 the Gregorian Calendar (named after Pope Gregory XIII) was introduced to bring even more accuracy to the calendar. The actual year is about 11 minutes short of 365.25 days. In other words, it had been gaining 3 extra days every 400 years and so the calendar had slipped by about 10 days by this point. So in that year October 4th was followed by October 15th to allow for correction.

Most of the Catholic world adopted this calendar with other nations adopted it as various times over the centures. There are still parts of the world which still do not use the Gregorian Calendar, notably Ethiopia. Britains and its possesions added 11 days in 1752 when September 2nd was followed by September 14th.

The year as defined in the Gregorian Calendar has 365.2575 days in it. 365 days in a typical year. Except if the number of the year is divisible by 4 then the year has one extra day (February 29th). Except if the number of the year is divisible by 100 then it does not have an extra day. Except if the number of the year is divisible by 400, when that day is added again. This gives the Gregorian Calendar a 400 year cycle.

Even more accuracy!
The length of a day is getting longer, 1.7 milliseconds longer every century due to tidal friction and other factors. This has meant that leap seconds are sometimes added to the year to keep the calendar accurate to the second – 24 leaps seconds since 1972 (up to 2009). Also the standard definition of a second, day and year have changed due to increases in accuracy and the variability of the earth’s rotation.

The (variable) length of the year can be measured in several ways.

Length of year in 2000days
Sideral year (time to orbit 360 degrees)365.2564
Tropical year † (vernal equinox to same, absolute)365.24219
Between two March (vernal) equinoxes (relative to sun in sky)365.24237
Between two June solstices365.24162
Between two September equinoxes365.24201
Between two December solstices365.24274

† this is the one used