A zero at the end of a number comes from a factor of 10 = 2 × 5. So the number of trailing zeros of n! equals the number of complete (2, 5) pairs in its prime factors.
Even numbers appear every second step, but multiples of 5 only every fifth step, so n! always has more twos than fives. The fives run out first, and the count of fives is the count of zeros.
Some numbers carry more than one five: 25 = 5 × 5 carries two, 125 carries three. That gives the standard formula, where each term is the whole-number part of the division:
Zeros in n! = n/5 + n/25 + n/125 + n/625 + …
Stop when the divisor is larger than n.