Skip to content
digiwleeaTools
LearnGlossaryAboutCheat sheetHow a CPU worksBuild a CPUToolsOpen the lab →

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.

Live circuit: click the inputs to toggle them and watch the outputs update. It runs the real simulator, right here on the page.

Open this circuit in the lab →

Embed or cite this circuit

Free to embed on a course page, blog or worksheet: paste this code. The circuit stays live, and the small digiwleea badge links back here.

To cite it: digiwleea, “logic gates using 2:1 multiplexers”, https://digiwleea.wleeaf.dev/tools/build/logic-gates-using-mux/

What you need

Step by step

  1. Place inputs A and B, a constant 0 and a constant 1, and one probe per gate.
  2. Make NOT B: a mux with B on S, 1 on D0 and 0 on D1.
  3. For each gate, place a mux with A on S and wire D0 and D1 from the table below.
  4. 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)

GateD0 (A = 0)D1 (A = 1)Output
NOT A10A'
AND0BAB
ORB1A + B
NAND1NOT B(AB)'
NORNOT B0(A + B)'
XORBNOT BA XOR B
XNORNOT BBA XNOR B

Truth table of the live circuit

ABNOTANDORNANDNORXORXNOR
001001101
011011010
100011010
110110001

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.