The length of the year in the Western calendar has its origin in the Roman calendar. Since 46 BC, Julius Caesar wanted to establish 365-day years with a leap year every 4 years. However, it will take some time before the Julian calendar is properly applied.
The scope of this calendar refers to the length of the tropical year. This is the time it takes for the Sun to return to the same position in the sky. During this time, the Sun moves from its northernmost position to its southernmost position relative to the equator and vice versa. This results in the frequency of the seasons that the calendar wants to reflect.
A tropical year lasts 365.242190 days or 365 days 5 hours 48 minutes 45.2 seconds, so it is not an integer number of days. A good approximation was made by introducing a year of 366 days every 4 years as already provided for in the Julian calendar. This gives a year with an average duration of 365.25 days.
Over time, a small difference (0.0078 days per year) began to be a problem. Thus, because of the imperfection of the Julian calendar, spring in the 16th century was moved to March 11. In order to put everything in order, Pope Gregory XIII decided in 1582 that October 4 should be followed by October 15. In addition, at the request of the astronomers of the time, he implemented the following new rule: a year divisible by 100 will not be leapfrogging, unless it is a multiple of 400. the first rule alone produces an average year of 365.24 days every 100 years. The second rule is to get very close to the tropical year, i.e. 365.2425 days every 400 years. It is only after 3000 years that the inaccuracy deviates by one day.
However, this timetable was not immediately adopted by all countries. Russia waited until 1917, which is why the October revolution is now commemorated in November. Sweden became so confused in the 18th century that it was necessary to give 30 days in February in 1712. Greece adopted the Gregorian calendar in 1923.
Several people noted that some sources contradict each other. Thus, the southern regions of present-day Belgium moved to the Gregorian calendar from 1582 to 1583. In some places (Flanders and Hainaut) Christmas Day was not celebrated in 1582, since December 21, 1582 was immediately followed by January 1, 1583. Even if Brabant and Zeeland had made the transition earlier (14-25 December), it was not without difficulties. The Liege échevinage introduced the Gregorian reform in February 1583.
You can find more information about calendars on, for example, The Calender FAQ.