A mux logic gate (multiplexer) is a combinational digital switch that routes one of several input signals to a single output line based on the binary state of its select pins. In a real circuit, it fundamentally changes your physical wiring topology by allowing a microcontroller with limited GPIO pins to read dozens of sensors or route multiple data streams without requiring a larger, more expensive processor. Think of it like a railroad track switchyard: multiple incoming tracks (inputs) converge, and the switchtower operator (select pins) dictates exactly which single track connects to the main outbound line (output).
The Core Mechanism and a Worked Numeric Example
Multiplexers are classified by their input-to-output ratio, typically expressed as $2^n$-to-1, where $n$ is the number of select pins. An 8-to-1 mux requires exactly 3 select pins ($2^3 = 8$) plus 1 output pin. The binary value applied to the select pins determines which input is forwarded to the output.
Let us run a concrete numeric example using a standard 8-channel digital mux, the 74HC151. Suppose you are building a CNC router limit-switch array and need to monitor 8 mechanical switches, but your ESP32-S3 dev board is running low on available GPIOs.
- Without a Mux: You wire each switch to a dedicated GPIO pin. Total GPIOs consumed: 8.
- With a 74HC151 Mux: You wire the 8 switches to the data inputs (D0 through D7). You connect the three select pins (S0, S1, S2) to three ESP32 GPIOs, and the output pin (Y) to a fourth ESP32 GPIO.
To read the state of the switch wired to input D5, you must drive the select pins to the binary equivalent of 5. Binary 5 is 101. Therefore, you set S2=HIGH (1), S1=LOW (0), and S0=HIGH (1). The mux internally connects D5 to Y. Your microcontroller reads the Y pin and instantly knows the state of switch 5. Total GPIOs consumed: 4 (3 select + 1 data). You just cut your pin requirement in half.
What People Commonly Confuse It With
When ordering parts or reading schematics, it is easy to mix up a multiplexer with similar-looking logic ICs. Here is how to tell them apart on the bench:
Digital Mux vs. Analog Switch vs. Decoder
- Demultiplexer (Demux): The exact opposite. Takes 1 input and routes it to one of $2^n$ outputs. Used for distributing a single signal to multiple destinations.
- Decoder (e.g., 74HC138): Takes a binary input and activates exactly one of $2^n$ output lines (usually pulling it LOW). It does not pass a data signal through; it merely acts as a binary-to-one-hot address translator.
- Analog Switch / Analog Mux (e.g., CD4051B): Uses CMOS transmission gates to pass continuous voltage levels (e.g., a 2.5V audio wave or a 1.8V thermistor reading). A standard digital TTL mux (like the 74HC151) will severely distort analog signals because it only recognizes distinct logic HIGH and LOW thresholds.
Where You Meet This In Practice
You will rarely see a bare mux logic gate in consumer electronics teardowns, as modern SoCs have massive pin counts. However, in prototyping, test equipment, and modular DIY builds, they are indispensable.
1. I2C Bus Address Collisions
The I2C protocol relies on unique 7-bit addresses. If you want to connect four BME280 environmental sensors to a single Raspberry Pi Pico, you have a problem: they all default to address 0x76. Instead of writing custom firmware to bit-bang four separate I2C buses, you drop a TCA9548A I2C multiplexer on the main bus. The TCA9548A acts as a digital switchboard, routing the Pi's SDA/SCL lines to one of 8 downstream channels at a time. According to the NXP I2C Specification, you must account for the added bus capacitance of the mux, but it solves the address collision instantly.
2. Analog Sensor Arrays
Reading an array of 16 soil moisture sensors with a single ADC pin on an Arduino Nano. By cascading two CD4051B analog muxes, you can route any of the 16 analog voltages to the A0 pin, saving 15 ADC pins.
3. Video and Audio Routing
In retro-gaming mods or custom AV setups, high-speed analog muxes (like the ADAU7002 or specialized video crosspoint ICs) route composite or component video signals to a single display input without the signal degradation of mechanical switches.
Decision Tree: Picking the Right Mux Logic Gate
Do not just grab the first mux you find in your parts bin. The wrong choice will result in distorted analog readings or fried 3.3V logic boards. Use this decision matrix to select your part.
| Signal Type | Voltage Level | Channel Count | Recommended Part Number | Typical Price (2026) |
|---|---|---|---|---|
| Digital Logic (Standard) | 5V (TTL/CMOS) | 8-to-1 | 74HC151 (DIP-16) | $0.50 |
| Digital Logic (Low Voltage) | 3.3V or 1.8V | 2-to-1 (Single) | 74LVC1G315 (SOT-23) | $0.15 |
| Analog Voltage / Audio | 3V to 15V | 8-to-1 | CD4051B (DIP-16) | $0.65 |
| I2C Data Bus (SDA/SCL) | 3.3V or 5V | 8-channel | TCA9548A (Module/TSSOP) | $1.50 (Breakout) |
Real-World Gotchas and Bench Measurements
Theory assumes ideal switches. Real silicon has parasitic properties that will ruin your day if you ignore them.
On-Resistance ($R_{ON}$) and Voltage Dividers
When using an analog mux like the CD4051B, the internal switch is not a perfect short; it has an on-resistance. At 5V VCC, the CD4051B has an $R_{ON}$ of roughly 120Ω. If your sensor has a low output impedance (e.g., 100Ω), the mux forms a voltage divider. Your 2.50V signal will drop to roughly 1.38V at the microcontroller's ADC pin. Fix: Buffer high-impedance sources with an op-amp before the mux, or use a low-$R_{ON}$ mux like the 74HC4051 (approx 80Ω at 4.5V) or the ADG708 (approx 4Ω).
Propagation Delay ($t_{pd}$)
Digital muxes are not instantaneous. According to the Texas Instruments SN74HC151 Datasheet, the typical propagation delay from a select pin changing state to the output reflecting the new input is about 14ns at 5V. For reading mechanical switches, this is irrelevant. For routing a 20MHz SPI clock line, this delay will skew your clock-to-data timing and cause bit errors. Never route high-speed clocks through standard logic muxes.
Floating Inputs Destroy ICs
CMOS logic gates draw massive current and can overheat if left floating in the linear region. If you are only using 4 inputs on an 8-channel 74HC151, you must tie the unused D4-D7 pins to GND. Never leave them unconnected.
Frequently Asked Questions
Do I need pull-down resistors on the select pins?
Yes, it is highly recommended. When a microcontroller boots up, its GPIO pins are high-impedance (floating) until initialized in code. During this boot window, the mux's select pins will pick up ambient noise, rapidly switching the output between random inputs. A 10kΩ pull-down resistor on S0, S1, and S2 ensures the mux defaults to D0 during boot.
Can I cascade multiplexers to get 16 or 32 channels?
Absolutely. To build a 16-to-1 mux, use two 8-to-1 muxes for the first stage. Wire their outputs into the inputs of a third 2-to-1 mux. You will use 4 select pins total (S0-S2 control the first stage, S3 controls the second stage). Just remember that cascading adds the propagation delays of both stages together.
Why is my I2C mux (TCA9548A) causing communication timeouts?
I2C is highly sensitive to bus capacitance. Every switch inside the TCA9548A adds a few picofarads of capacitance. If you have long wires and multiple sensors on the downstream channels, the total capacitance can exceed the I2C spec limit of 400pF, rounding off the square waves into unreadable ramps. Keep downstream I2C traces under 6 inches, or lower the bus speed to 50kHz.






