Demultiplexing is the process of taking a single input signal and selectively routing it to exactly one of several output lines based on the binary state of its control pins. If you are building a circuit and need to send one data stream to multiple destinations without using a separate microcontroller pin for each destination, a demultiplexer (often abbreviated as demux) is the logic gate array that solves the problem.

In a real circuit, a demultiplexer changes your wiring topology from parallel to serialized routing. Instead of burning up eight GPIO pins to control eight separate devices, you use three pins to select the destination and one pin to carry the actual data. This trades parallel hardware complexity for sequential logic control, freeing up your microcontroller's limited I/O resources.

The Core Concept: One In, Many Out

Think of a railroad switchyard: one incoming train track (the data input) is directed down exactly one of several outgoing tracks (the outputs) depending on how the track switches (the select pins) are thrown. The train doesn't split; it takes exactly one path. Similarly, a digital demux doesn't duplicate your signal across all outputs. It acts as a digitally controlled rotary switch, connecting the single input to the chosen output while leaving all other outputs in their inactive state.

Bench Tip: Most standard logic demuxes have active-LOW outputs. This means the "selected" output drops to 0V (GND), while all unselected outputs remain HIGH (VCC). Always check the datasheet's truth table to confirm whether your specific IC uses active-HIGH or active-LOW routing.

The Math and Pins: A Worked Numeric Example

Let's look at a dedicated 1-of-16 demultiplexer, the NXP 74HC154. This IC requires four select pins ($S_0$ through $S_3$) to address its 16 outputs ($Y_0$ through $Y_{15}$), because $2^4 = 16$. It also has a dedicated data input pin ($D$) and an enable pin.

Suppose you want to route a 5V PWM signal from your microcontroller to output pin $Y_{11}$. Here is the exact pin state required:

  1. Calculate the binary address: Decimal 11 converts to binary 1011.
  2. Set the select pins: Apply these bits to the select lines: $S_3 = 1$ (HIGH), $S_2 = 0$ (LOW), $S_1 = 1$ (HIGH), $S_0 = 1$ (HIGH).
  3. Enable the IC: Pull the Enable pin LOW (assuming active-LOW enable).
  4. Feed the data: Whatever logic state is present on the Data input ($D$) will now appear on $Y_{11}$. If $D$ is HIGH, $Y_{11}$ goes HIGH. If $D$ toggles, $Y_{11}$ toggles.
Propagation Delay Reality Check: At a 5V supply, a 74HC-series demux has a typical propagation delay of about 15ns from the select pins changing to the output updating. At 3.3V, this stretches to roughly 25ns-40ns. In high-speed SPI or memory bus applications, this delay is a hard timing constraint you must account for.

All other outputs ($Y_0$ through $Y_{10}$, and $Y_{12}$ through $Y_{15}$) remain completely unaffected by the data input; they stay locked in their inactive state.

Where You Meet Demultiplexing in Practice

You will rarely see a standalone "demultiplexer" labeled as such in modern consumer electronics, but the function is everywhere. Here is where this concept physically manifests on the bench:

  • SPI Chip Select Routing: Microcontrollers often have hardware SPI busses but lack the GPIO pins to provide a unique Chip Select (CS) line for every sensor. A demux routes a single CS signal to one of eight sensors.
  • Memory Address Decoding: In older or retro-computing architectures (like Z80 or 6502 builds), a demux takes a single "Write Enable" pulse from the CPU and routes it to the specific RAM or ROM chip whose address matches the select pins.
  • LED Matrix Column Driving: When multiplexing a large LED matrix, a demux is often used to sink current from one specific column at a time while the row drivers illuminate the necessary pixels.

Real-World Bench Scenario: Expanding ESP32 SPI Busses

The most common way hobbyists use demultiplexing is by repurposing a decoder IC—specifically the ubiquitous Texas Instruments SN74HC138 3-to-8 line decoder. By feeding your data signal into one of the active-LOW Enable pins ($\overline{E1}$), the 138 functions perfectly as a 1-to-8 demultiplexer.

The Setup

You are building a data logger with an ESP32 DevKit v1 and eight SPI thermocouple amplifiers (MAX31855). You share the MOSI, MISO, and SCK lines across all eight chips, but you need individual Chip Select (CS) lines. You are out of GPIOs. You wire a 74HC138 to the ESP32:

  • ESP32 GPIO 16, 17, 18 connected to 138 select pins A, B, C.
  • ESP32 GPIO 19 connected to the 138's $\overline{E1}$ (Enable 1) pin.
  • The 138's $Y_0$ through $Y_7$ outputs connect to the CS pins of the eight sensors.

The Numbers and Outcome

You want to read sensor #5 (binary 101). Your code sets GPIO 16 HIGH, GPIO 17 LOW, and GPIO 18 HIGH. Then, your SPI library pulls GPIO 19 LOW to assert the chip select, clocks the data, and pulls GPIO 19 HIGH to end the transaction. Sensor #5 responds perfectly.

What Went Wrong (The Glitch Nightmare)

When you run the loop to read all eight sensors sequentially, sensors #0 and #4 occasionally return garbage data or trigger unexpectedly.

The Cause: When using standard digitalWrite() commands on the ESP32, the pins do not change state simultaneously. To change the address from 100 (Sensor 4) to 101 (Sensor 5), the microcontroller updates the pins sequentially. For a few microseconds, the select lines pass through intermediate states (like 000 or 100). If your SPI library asserts the Enable/CS line (GPIO 19 LOW) before the select pins have fully settled, or if it leaves it LOW while changing addresses, the 74HC138 routes that active-LOW signal to the wrong sensor, falsely triggering its SPI latch.

The Fix: Never change the select pins while the data/enable line is active. Always ensure the Enable pin is held HIGH (inactive) while you update the A, B, and C select pins. Alternatively, use direct port manipulation (e.g., writing directly to the ESP32's GPIO_OUT_W1TS_REG register) to change all three select pins in a single CPU clock cycle, eliminating intermediate states entirely.

What People Commonly Confuse It With

Because the terminology overlaps, it is easy to order the wrong part or misunderstand a schematic. Here is how to separate the concepts:

Component Direction of Data Flow Primary Function Common IC Example
Demultiplexer (Demux) 1 Input $\rightarrow$ N Outputs Routes a variable data signal to one specific destination. 74HC154, CD4051
Multiplexer (Mux) N Inputs $\rightarrow$ 1 Output Selects one of many input signals to pass to a single destination (like an ADC). 74HC4051, 74HC151
Decoder Binary Code $\rightarrow$ N Outputs Activates a single output based on a binary address; does not route variable data. 74HC138, 74HC42

Note: As shown in the bench scenario above, a decoder can be forced to act as a demux by using its Enable pin as the data input, but a true demux has a dedicated data pin.

FAQ: Troubleshooting and Selection

Can I use a standard 74HC demultiplexer to route analog audio or sensor voltages?

No. Standard 74HC logic ICs are digital; they will clip your signal to VCC and GND, and they cannot pass continuous analog voltages. If you need to route analog signals (like an audio channel or a raw thermocouple millivolt signal), you must use an analog switch or analog multiplexer/demultiplexer like the CD4051 or 74HC4051, which use internal MOSFETs to pass analog voltages within the supply rails.

Why are my unselected outputs floating or causing phantom triggers?

If you are using a demux to drive the bases of transistors or the gates of MOSFETs, the inactive outputs might not be sinking enough current to fully turn off the downstream component, especially if the inputs are left floating. Always tie unused select or enable pins to a definitive logic HIGH or LOW using 10k$\Omega$ pull-up/pull-down resistors. Furthermore, ensure your downstream devices have pull-up resistors on their chip-select lines to keep them inactive when the demux output is HIGH.

What is the maximum frequency I can demultiplex at?

This depends entirely on the logic family and supply voltage. A standard 74HC series IC running at 5V can comfortably handle select-line toggling in the 20 MHz to 30 MHz range. However, if you are demultiplexing a high-frequency data signal (like a 10 MHz clock), the propagation delay mismatch between the data path and the select path can cause duty-cycle distortion. For high-speed RF or clock routing, use dedicated clock fanout buffers rather than general-purpose logic demuxes.