How does a digital filter work?
Consider a moving average over N samples- this is a simple FIR filter where each new output is the average of the past N samples. It is easy to see how high frequency noise can be filtered out (so is a low pass filter), and the longer time duration we include in the averaging window the lower will be the frequency cut off (just compare a stock market 30 day moving average to a 1 day moving average).

A moving average is a poor low pass filter, having a frequency response that approaches a Sinc function, which rolls off relatively slowly in frequency. By doing a weighted moving average where different samples are given different weights in the averaging process, we can significantly improve the frequency response - and coming up with the correct weights is the science of digital filter design.

IIR filters are similar except we are performing the average with previous outputs instead of past inputs.