Why do digital filters work?
Consider a discrete-time input signal of the form:
$$ x[n] = \cos(\omega_0 n) ~~~,~~~-\infty &lt; n &lt; \infty, ~~~~~ n\in \mathcal{Z}$$
where the radian frequency $\omega_0$ is set between 0 and $\pi$ radians per sample.
Now, consider two basic discrete-time (digital) filters which are defined through addition and subtraction of their input $x[n]$ for producing their outputs $y_1[n]$ and $y_2[n]$ as:
$$y_1[n] = (x[n]+x[n-1])/2 ~~~,~~~ \text{sum filter}$$ and
$$y_2[n] = (x[n]-x[n-1])/2 ~~~,~~~ \text{difference filter}$$
Lets make a qualitative analysis of these two filters by setting their input frequency $\omega_0$ to low (close to $0$), and high (close to $\pi$) values, and then observing the corresponding outputs respectively;
First, assume that $\omega_0$ is set to low frequencies: Then the consecutive input samples $x[n]$ and $x[n-1]$ will have highly similar values, as a low frequency sine wave will not change much from one sample to the other. When this is the case, their sum will add up, whereas their difference will cancel.
Therefore, $y_1[n]$ will be approximately equal to the input's value $x[n]$, while the output $y_2[n]$ will be close to zero, due to cancelling of $x[n]$ by $x[n-1]$ when subtracted. Then we conclude that the sum filter passes the low frequencies while the difference filter attenuates (blocks) them.
For the second part of the analysis, set $\omega_0$ to high frequencies: then the values of the input samples $x[n]$ and $x[n-1]$ will be of opposite polarities, as the cosine will be rapidly changing from sample to sample. Then, their sum  will cancel, whereas their difference will add up.
Therefore, $y_1[n]$ will be approximately zero, while $y_2[n]$ will be following the input. Then we see that the sum filter blocks high frequencies while the difference filter passes them.
Combining these two analyses we conclude that the sum filter is a lowpass filter, which passes low frequencies and attenuates high frequencies, while the difference filter is a highpass filter, which attenuates low frequencies and passes high frequencies.
Following this basic basic setting, more complex filters are realized through using more samples at farther delays, and are weighted properly. Then the passband and stopband cutoff frequencies, the transition bandwidth and ripples are all determined by those delays and weights applied into the summing (or differencing) samples and the number of samples (length of filter) used in the sums (or differences).
Those weights are then called as the filter coefficients (or its impulse response $h[n]$ for the FIR filter) that characterize the filter.