Note: these multiplexers exist in different forms. The idea is always the same, but pins can be located and marked differently. Surprisingly.
What I use looks like this:
CJMCU-4051 74HC4051 8 Channel Analog Multiplexer
How the multiplexer works?
It has N (in this particular case, 3) command pins. Pins are binary,
they accept 0 or 1 (LOW of HIGH signal) and therefore, we can use 3 pins to pass 2^2 = 8
different combinations, like :
0, 0, 0 (LOW, LOW, LOW) for 0
0, 1, 1 for 3.
The binary values are used here the same way we use it in C++ bytes, so if you are familiar with Arduino programming you should know the concept: a digital value equals 2^0 * voltage_on_first_pin + 2^1 * voltage_on_second_pin + 2^2 * voltage_on_third_pin + ...
So to encode 7, we need 2^0 + 2^1 + 2^2 (HIGH, HIGH, HIGH).
On the following picture you can see the 0, 0, 0 command turning on the 0th input (X0).
In the same time, if we provide the 1, 1, 0 command, X3 is activated.