Skip to content
Tutorials Center
My learning

Topics

Lesson 27 of 57 · Combinational Building Blocks

Multiplexers and Demultiplexers

Learn multiplexers and demultiplexers: 2:1 to 8:1 MUX equations, building big muxes from small ones, implementing any Boolean function with a MUX, and Python models.

Computers are full of choices. Which register feeds the adder? Which of eight inputs does this pin listen to? A multiplexer (MUX) is the digital switch that makes the choice: it has several data inputs, a few select lines, and one output, and the select lines say which input is connected to the output. Its mirror image, the demultiplexer (DEMUX), takes one input and sends it to one of several outputs.

Multiplexers matter far beyond switching signals. A mux can implement any Boolean function, which makes it a universal logic block, and it is the part that picks the result in processors, memories and FPGA lookup tables. In this lesson you will write the equations, build large muxes from small ones, and use a mux to implement a logic function without drawing a single gate.

The 2:1 multiplexer

The smallest mux has two data inputs D0 and D1, one select line S, and one output Y. If S = 0 the output copies D0; if S = 1 it copies D1. As an equation:

Y = D0·S′ + D1·S

That is two AND gates, one inverter and one OR gate. Think of S as the position of a railway switch: it decides which of two tracks reaches the output.

Larger multiplexers

A mux with n select lines has 2ⁿ data inputs, written 2ⁿ:1. A 4:1 mux has two select lines S1 S0 and four inputs; an 8:1 mux has three select lines and eight inputs. The general equation is a sum of products in which every data input is gated by a minterm of the select lines:

Y = D0·S1′·S0′ + D1·S1′·S0 + D2·S1·S0′ + D3·S1·S0 (for 4:1)

Only the term whose select code matches can be 1, so exactly one data input reaches the output. You never have to build the big gate network, though. Bigger muxes are just trees of 2:1 muxes: a 4:1 mux is three 2:1 muxes (two in the first layer driven by S0, one in the second driven by S1), and an 8:1 mux is seven.

Anatomy of a multiplexer

Data inputs 2 to the n of them, D0 onward.
Select lines n bits choose which input wins.
One output Y copies the chosen input.

n select lines give 2^n inputs.

1 / 2

The program below models these circuits. mux4 and mux8 are written as trees of mux2, exactly as the hardware is built. It prints the 2:1 truth table, runs an 8:1 mux over all select codes, and checks that the tree equals plain indexing.

Python Building 4:1 and 8:1 multiplexers from 2:1 muxes

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

A mux is a lookup table: implementing any function

Look at the 8:1 run above. The output is simply data[select]. Treat the three select lines as the inputs A B C of a Boolean function and wire the data inputs to constants 0 and 1, and the mux outputs exactly the function whose truth table you wired in. The row number is the select code, and the data input is the output for that row.

This is why a mux is called a universal logic block: with n select lines it implements any function of n variables, with no gate minimization at all. (FPGAs use this idea: their lookup tables are small muxes whose data inputs are memory bits, as you will see in PLAs, FPGAs and lookup tables.)

You can do better. A function of n variables fits in a mux with only n - 1 select lines. Use n - 1 of the variables as select lines and look at what the function does as the last variable C changes, for each fixed A B. There are only four possibilities for the pair (value when C = 0, value when C = 1):

  • (0, 0): the function is always 0, so wire the data input to 0.
  • (1, 1): always 1, so wire it to 1.
  • (0, 1): it follows C, so wire it to C.
  • (1, 0): it is the opposite of C, so wire it to C′ (one inverter).

A 3-variable function therefore needs just a 4:1 mux and at most one inverter. The program checks both methods on the majority and parity functions over all eight input combinations.

Python Implement logic functions with 8:1 and 4:1 muxes

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

For the majority function the 4:1 data inputs are 0, C, C, 1. Read it as a sentence: "if A B is 00, the output is 0 whatever C is; if exactly one of A B is 1, the output follows C; if both are 1, the output is 1." The parity function needs C, C′, C′, C, which is the XOR of A, B and C expressed as a mux. The same trick can be applied once more: the data inputs are themselves functions of fewer variables, which a smaller mux can build.

The demultiplexer

A demultiplexer does the opposite job. A 1:4 DEMUX has one data input D, two select lines and four outputs. The selected output copies D, and all other outputs stay at 0:

Y0 = D·S1′·S0′, Y1 = D·S1′·S0, Y2 = D·S1·S0′, Y3 = D·S1·S0

If you hold D = 1, exactly one output is 1, namely the one named by the select code. That is a decoder; a decoder with an enable input is a demultiplexer when the enable acts as the data input.

Used together, a mux and a demux can share one wire among several signals. The sender's mux steps through its inputs one at a time (time-division multiplexing), and the receiver's demux, stepped in sync, hands each symbol to the right output. The program below sends four words down one simulated wire and gets them back.

Python A 1:4 demultiplexer and a shared wire

Press Run (or Ctrl + Enter) to see the result here.

Program input · what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Where multiplexers are used

  • Processors: choosing between register values, immediate values and memory data before the ALU, and choosing the final result afterwards (see the ALU lesson).
  • Memories and buses: reading one word out of many, and sharing a bus between devices.
  • Communication: serializing several channels onto a single link.
  • Programmable logic: every lookup table in an FPGA is a mux tree.
  • Adder-subtractors and shifters: a bank of 2:1 muxes selects between shifted and unshifted data.

When you meet a circuit that says "if X then use P else use Q", picture a 2:1 mux. The software condition ? p : q is a 2:1 mux in disguise, one per bit.

Check your understanding

Quick check · 5 questions

of 5 answered You scored / 5 · perfect!

  1. 1. How many select lines does an 8:1 multiplexer need?

    n select lines choose among 2^n inputs. Eight inputs need 3 select lines because 2^3 = 8.
  2. 2. Which equation describes a 2:1 multiplexer?

    When S is 0 the first term passes D0, and when S is 1 the second term passes D1.
  3. 3. You use a 4:1 mux (select lines A and B) to build a 3-variable function. For A B = 01 the function equals C′. What do you connect to input D1?

    The select code 01 chooses D1, and the function must be the opposite of C there, so D1 is wired to C passed through an inverter.
  4. 4. How many 2:1 multiplexers form an 8:1 multiplexer when built as a tree?

    The first layer needs four 2:1 muxes, the second two and the third one, which is 4 + 2 + 1 = 7.
  5. 5. What is the relationship between a decoder with an enable input and a demultiplexer?

    A decoder activates exactly one output according to its select code. Feeding the data signal into the enable pin makes only the selected output follow that signal, which is what a demultiplexer does.

Summary

  • A multiplexer connects one of 2ⁿ data inputs to its output, chosen by n select lines: Y = D0·S′ + D1·S for 2:1.
  • Large muxes are trees of 2:1 muxes (an 8:1 mux is seven of them).
  • A mux is a lookup table: wiring a truth table to the data inputs implements any function of n variables with n select lines.
  • With data inputs from {0, 1, C, C′}, a mux with n - 1 select lines implements any function of n variables.
  • A demultiplexer routes one input to one of 2ⁿ outputs and is a decoder with the enable used as data.
  • Muxes appear everywhere that hardware must choose: processors, buses, memories and FPGAs.

Next: Decoders, Encoders and Priority Encoders.