How to build a 3-to-8 decoder from logic gates
A 3-to-8 decoder turns a 3-bit binary number A2 A1 A0 into eight output lines Y0 to Y7, exactly one of which is 1: the line whose number matches the input. With three inputs there are 23 = 8 combinations, so eight outputs.
It is the 2-to-4 decoder one size up, and the same idea scales to any width: n input bits select one of 2n lines. Decoders are how an address picks one memory row, how an opcode switches on one operation, and, with an extra data input, they become demultiplexers. The live circuit starts at 000, so Y0 is lit.
Open this circuit in the lab →
What you need
- 3× NOT: the complements NOT A2, NOT A1, NOT A0
- 4× AND: the four A1 A0 combinations (00, 01, 10, 11), shared by both halves
- 8× AND: each pair term combined with A2 or NOT A2, one per output line
Step by step
- Place the address inputs
A2,A1andA0and invert each with aNOTgate. - Decode the low two bits first: four
ANDgates for A1' A0', A1' A0, A1 A0' and A1 A0. This is a 2-to-4 decoder. - Split each of those four lines by the top bit: AND it with
NOT A2for outputs Y0 to Y3 and withA2for Y4 to Y7. Eight ANDs, eight outputs. - Probe
Y0toY7and count through the inputs 000 to 111: the single 1 steps from Y0 to Y7.
3-to-8 decoder truth table
| A2 | A1 | A0 | Y0 | Y1 | Y2 | Y3 | Y4 | Y5 | Y6 | Y7 |
|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 1 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 |
| 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 |
| 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 |
| 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |
Each output is one minterm of the three inputs, for example Y5 = A2 AND NOT A1 AND A0. That is why a decoder plus an OR gate can implement any 3-input Boolean function: OR together the outputs for the rows where the function is 1. The 74HC138 is the classic 3-to-8 decoder chip; it adds enable inputs and active-low outputs.
You can also read the full theory in the lesson on decoders. 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.
Build more parts from gates
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 3-to-8 decoder in the lab →Frequently asked
How does a 3-to-8 decoder work?
Each of its eight outputs is an AND of the three inputs, each taken either straight or inverted, so each output is 1 for exactly one input combination. The input value, read as a binary number, names the output that goes high.
How many AND gates does a 3-to-8 decoder need?
Eight 3-input AND gates, one per output, plus three inverters. With only 2-input gates, as here, you can share work: four ANDs decode A1 A0, and eight more combine those with A2 or NOT A2, for twelve 2-input ANDs in total.
How do you build a 3-to-8 decoder from 2-to-4 decoders?
Use two 2-to-4 decoders on A1 A0 and enable one with NOT A2 (giving Y0 to Y3) and the other with A2 (giving Y4 to Y7). This page's circuit is the same idea with the shared 2-to-4 stage ANDed with A2 and NOT A2.
What is a 3-to-8 decoder used for?
Selecting one of eight things from a 3-bit number: memory chips or rows, registers, devices on a bus, or the control line for an instruction. With an OR gate it also implements any 3-variable logic function from its minterms.