In a 400 year cycle of the Gregorian calendar there are 146097 days. There are 365 days in a normal year, there are 24 leap days in 3 of the centuries, and an extra leap day in the century year that's divisible by 400.
$$400 \times 365 + 4 \times 24 + 1 = 146097$$
Now $146097= 20871 \times 7$, so there are exactly 20871 weeks in 400 years, so the first day of each cycle (The 1st of January of a century year divisible by 400) always falls on the same weekday (Saturday).
* * *
FWIW, this leap-year ratio gives a mean year length of 365.2425 days in the Gregorian calendar. This is a reasonable approximation of the current mean tropical year length (365.24219 ephemeris days of 86400 seconds) and the equinox year length (365.242374 ephemeris days), but it's not perfect, and the Earth's rotation speed is gradually slowing down (i.e., the length of a mean solar day is getting longer) so future adjustments will be required