The formula for calculating whether a year is a leap year or not is as follows: if a year can be evenly divided by 4 (such as 2012), then it is a leap year unless it can also be evenly divided by 100 (such as 2100). There is one further exception: if a year can be evenly divided by 400 (such as 2000), then it is a leap year.
A day on Earth does not really last 24 hours. It takes 23 hours, 56 minutes and 4.1 seconds for the Earth to make a complete rotation. Because of this, the Earth actually rotates about 365.24 times per year. Adding an extra day every four years helps to synchronize the calendar year with the solar year. If the discrepancy were exactly one quarter of a year, then every four years would be a leap year without variation. Since the difference is 0.24 instead of 0.25, one leap year is skipped three times out of every 400 years. Leap year originated in the 16th century, when people realized that the vernal equinox was falling on March 11 instead of March 21. Pope Gregory XIII adjusted the calendar by moving the date ahead by 11 days and instituted the practice of adding an extra day to the calendar every four years.