This neat graph shows the date (in GMT) of the summer solstice (the moment the sun reaches it northernmost position in the sky, or the beginning of summer in the northern hemisphere) through the years. As the summer solstice occurs on the same astronomical date each year (although changes may occur on much larger time scales), the graph basically shows the difference between real, astronomical time and the Gregorian calendar. Each year, the Gregorian calendar is approximately 0.26 day faster than the astronomical calendar, which is corrected by a leap day once every four years. This 4-year cycle is clearly visible in the graph. To compensate for the largest part of the remainder of the difference, there is no leap year in 1800, 1900, 2100, 2200, as can be clearly seen in the graph, too. Note that the summer solstice in 1800 and in 2200 are not on equal dates; this shows that the leap year compensation as describes before is not perfect and more complicated schemes are necessary to keep the Gregorian calendar synchronized over even longer time scales.
In the Gregorian calendar most years that are evenly divisible by 4 are leap years. In each leap year, the month of February has 29 days instead of 28. Adding an extra day to the calendar every four years compensates for the fact that a period of 365 days is shorter than a solar year by almost 6 hours. However, some exceptions to this rule are required since the duration of a solar year is slightly less than 365.25 days. Years that are evenly divisible by 100 are not leap years, unless they are also evenly divisible by 400, in which case they are leap years. For example, 1600 and 2000 were leap years, but 1700, 1800 and 1900 were not. Similarly, 2100, 2200, 2300, 2500, 2600, 2700, 2900 and 3000 will not be leap years, but 2400 and 2800 will be. By this rule, the average number of days per year will be 365 + 1/4 − 1/100 + 1/400 = 365.2425, which is 365 days, 5 hours, 49 minutes, and 12 seconds.
The Gregorian calendar was designed to keep the vernal equinox on or close to March 21, so that the date of Easter (celebrated on the Sunday after the 14th day of the Moon—i.e. a full moon—that falls on or after March 21) remains correct with respect to the vernal equinox. The vernal equinox year is about 365.242374 days long (and increasing). The marginal difference of 0.000125 days between the Gregorian calendar average year and the actual year means that, in around 8,000 years, the calendar will be about one day behind where it is now. But in 8,000 years, the length of the vernal equinox year will have changed by an amount that cannot be accurately predicted. Therefore, the current Gregorian calendar suffices for practical purposes, and the correction suggested by John Herschel of making 4000 a non-leap year will probably not
be necessary.
Source: Calendopaedia - The Gregorian Calendar; graphic from Wikipedia