A calendar year of 365 days is a convenient approximation, not an exact match for how long Earth actually takes to orbit the sun — and leap years exist purely to correct the small but steadily accumulating gap between the calendar and the astronomical reality.
The real length of a year
Earth's orbit takes approximately 365.2425 days, not a clean 365. Left uncorrected, that extra roughly quarter-day per year would accumulate into a full day of drift every four years, and over centuries the calendar would drift noticeably out of sync with the seasons — eventually putting winter months where summer used to fall.
The actual leap year rule
The rule is more precise than 'every four years': a year is a leap year if divisible by 4, except century years, which are leap years only if also divisible by 400. That's why 2000 was a leap year, but 1900 and 2100 are not — the exception refines the correction so the calendar stays even more closely aligned with the true orbital period over very long timescales.
How this shows up in date calculations
Any calculation spanning a February in a leap year needs to count 29 days for that month rather than 28, which affects exact day counts, age calculations, and anniversaries. Our date difference and age calculators handle this automatically using real calendar dates, rather than a fixed 365-day approximation, which is why they stay accurate across any span you choose, however many leap years it happens to include.