Given a number N, you just need to count the multiples of 5, 25, 125… Until N to calculate the number of trailing zeros. We need not calculate the multiples of 2 since they are obviously much higher than multiples of 5.

This article on https://brilliant.org/wiki/trailing-number-of-zeros/ gives a brilliant explanation and intuition of why this thing works. Do check it out!