The short answer: a lunar calendar
Most major Hindu festivals — Diwali, Holi, Navratri, Janmashtami among them — are dated using a lunisolar calendar (the Panchang), not the fixed 365-day Gregorian calendar used for civil purposes worldwide. Because a lunar month is shorter than a solar month, festival dates drift by roughly ten to twelve days earlier each Gregorian year, before an added leap month periodically resets the drift.
Tithi, not the date on a wall calendar
Hindu festivals are fixed to a tithi — a lunar day, defined by a specific angular relationship between the sun and moon, of which there are thirty in a lunar month, fifteen in each fortnight (paksha). Diwali, for instance, falls on Amavasya (the new moon tithi) of the Krishna Paksha in the month of Kartik — a fixed point in the lunar calendar, even though its Gregorian calendar date shifts each year. Holi similarly falls on the Purnima (full moon) of Phalgun.
Why a "leap month" exists
A pure lunar year (twelve lunar months) runs about eleven days shorter than a solar year. Left uncorrected, this drift would eventually push a harvest festival into the wrong season entirely within a couple of decades. To prevent that, the calendar periodically inserts an extra month, called Adhik Maas (or Purushottam Maas), roughly once every 32–33 months, which realigns the lunar calendar back with the solar seasons.
Why some festivals move less than others
Festivals tied more directly to a solar event, like Makar Sankranti (marking the sun's transition into Capricorn), fall on nearly the same Gregorian date each year — usually January 14th — because they follow the solar calendar rather than the lunar one. This is why Sankranti feels comparatively fixed while Diwali and Holi visibly shift across the calendar from year to year.
Where to find the exact date
Because the calculation depends on precise astronomical positions and can vary slightly by region and the specific Panchang used, the practical way to know a festival's date in any given year is to check a current Panchang or a reliable calendar rather than calculating it by rule of thumb.