Logic gates using a 2:1 mux: NOT, AND, OR, NAND, NOR, XOR, live
Every basic logic gate can be made from one 2-to-1 multiplexer: put A on the select line and wire each data input to 0, 1, B or NOT B. AND is D0 = 0, D1 = B; OR is D0 = B, D1 = 1; NOT is D0 = 1, D1 = 0; XOR is D0 = B, D1 = NOT B. The live circuit below builds all seven gates from eight muxes and nothing else.
A 2-to-1 mux outputs D0 when its select S is 0 and D1 when S is 1, so with A on the select, D0 is what the gate must output when A = 0 and D1 is what it must output when A = 1. Each of those is a function of B alone, and a function of one variable can only be 0, 1, B or NOT B. Read the two halves of a gate's truth table and the wiring follows: AND gives 0 when A = 0 and B when A = 1, so D0 = 0 and D1 = B. OR gives B when A = 0 and 1 when A = 1. NAND and NOR are the same with the B half inverted, and XOR passes B or NOT B. NOT B itself is one more mux, with B on the select, 1 on D0 and 0 on D1, so the whole circuit uses only multiplexers and the constants 0 and 1. That is why the 2-to-1 mux is called a universal logic element, like the NAND gate and the NOR gate, as long as constant 0 and 1 are available. Each MUX block here is the 2-to-1 multiplexer from logic gates, saved as a part; open the circuit in the lab to look inside. The same method builds bigger circuits: the half adder using 2:1 muxes and the full adder using 4:1 muxes.
Open this circuit in the lab →
What you need
- 7× 2-to-1 MUX: one per gate, with S = A: NOT, AND, OR, NAND, NOR, XOR, XNOR
- 1× 2-to-1 MUX: NOT B, with S = B, D0 = 1, D1 = 0, shared by NAND, NOR, XOR and XNOR
- 2× constant: 0 (GND) and 1 (VDD) on the data inputs
Step by step
- Place inputs
AandB, a constant 0 and a constant 1, and one probe per gate. - Make NOT B: a mux with B on S, 1 on D0 and 0 on D1.
- For each gate, place a mux with A on S and wire D0 and D1 from the table below.
- Toggle A and B through 00, 01, 10 and 11: every probe follows its gate's truth table.
2:1 mux wiring for each gate (S = A)
| Gate | D0 (A = 0) | D1 (A = 1) | Output |
|---|---|---|---|
| NOT A | 1 | 0 | A' |
| AND | 0 | B | AB |
| OR | B | 1 | A + B |
| NAND | 1 | NOT B | (AB)' |
| NOR | NOT B | 0 | (A + B)' |
| XOR | B | NOT B | A XOR B |
| XNOR | NOT B | B | A XNOR B |
Truth table of the live circuit
| A | B | NOT | AND | OR | NAND | NOR | XOR | XNOR |
|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 1 | 0 | 0 | 1 | 1 | 0 | 1 |
| 0 | 1 | 1 | 0 | 1 | 1 | 0 | 1 | 0 |
| 1 | 0 | 0 | 0 | 1 | 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 | 1 | 0 | 0 | 0 | 1 |
All four rows of all seven outputs are checked on the live circuit before the page is built. NOT here is NOT A; NOT B is the extra mux that feeds the inverted gates. A mux with its output fed back to one input also stores a bit: D latch and D flip-flop using a 2:1 mux.
You can also read the full theory in the lesson on the multiplexer as a universal block. Prefer to build it yourself from scratch? Open the digiwleea lab and place the gates on the canvas, or start from the logic gate simulator.
More builds: Universal gates: NAND only, NOR only
All 246 build guides, by topic
Each of these is one step from a transistor to a working CPU. Build every gate from CMOS transistors and work all the way up in the free digiwleea lab, with the free theory reference alongside.
Open the logic gates using 2:1 multiplexers in the lab →Frequently asked
How do you implement an AND gate using a 2:1 mux?
Put A on the select line, connect D0 to 0 and D1 to B. When A = 0 the output is 0, and when A = 1 it is B, which is A AND B.
How do you implement an OR gate using a 2:1 mux?
Put A on the select line, connect D0 to B and D1 to 1. When A = 0 the output is B, and when A = 1 it is 1, which is A OR B.
How do you implement a NOT gate using a 2:1 mux?
Put A on the select line, connect D0 to 1 and D1 to 0. The output is 1 when A = 0 and 0 when A = 1.
How do you implement an XOR gate using a 2:1 mux?
Put A on the select line, connect D0 to B and D1 to NOT B. With only muxes, NOT B comes from a second mux with B on its select, 1 on D0 and 0 on D1, so XOR takes two 2:1 muxes.
How many 2:1 muxes are needed for a NAND gate?
Two: one makes NOT B, and the second, with A on the select, passes 1 when A = 0 and NOT B when A = 1. With a NOT gate available it is one mux.
Why is a 2:1 multiplexer a universal logic element?
Because it can make NOT and AND (or NAND) using only the constants 0 and 1, and every logic function can be built from those. In general any function of n variables fits a 2^n-to-1 mux, or a 2^(n-1)-to-1 mux with the last variable or its complement on the data inputs.