How to build a 2-to-4 decoder from logic gates
A 2-to-4 decoder turns a 2-bit address into exactly one active output line, and is built from two NOT gates and four AND gates.
A decoder is how a binary number selects one thing: one memory row, one register, one device. The 2-bit input A1 A0 picks which of the four outputs Y0..Y3 goes high; the other three stay low. Every RAM, register file, and instruction decoder contains one.
Open this circuit in the lab →
What you need
- 2× NOT — the inverted address bits, NOT A1 and NOT A0
- 4× AND — one per output: each ANDs a unique true/inverted combination
Step by step
- Place two inputs: the address bits
A1(the twos place) andA0(the ones place). - Invert each address bit with a
NOTgate, givingNOT A1andNOT A0. - Wire
NOT A1andNOT A0into the firstAND: its outputY0fires for address 00. - Wire
NOT A1andA0into the second AND (Y1, address 01);A1andNOT A0into the third (Y2, address 10);A1andA0into the fourth (Y3, address 11). - Probe all four outputs. Step the address through 00, 01, 10, 11 and watch exactly one output line follow it.
2-to-4 decoder truth table
| A1 | A0 | Y0 | Y1 | Y2 | Y3 |
|---|---|---|---|---|---|
| 0 | 0 | 1 | 0 | 0 | 0 |
| 0 | 1 | 0 | 1 | 0 | 0 |
| 1 | 0 | 0 | 0 | 1 | 0 |
| 1 | 1 | 0 | 0 | 0 | 1 |
Exactly one output is 1 in every row: that is the decoder's one-hot guarantee. Scale the same pattern up (3 inverters and 8 ANDs gives 3-to-8) and you have the row selector inside a RAM.
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 and course.
Open the 2-to-4 decoder in the lab →Frequently asked
What gates are needed for a 2-to-4 decoder?
Two NOT gates and four AND gates. Each AND matches one address: it combines the true or inverted version of each address bit, so exactly one AND fires per input combination.
What is a decoder used for?
Selecting one of many things with a binary number: the row lines inside RAM, the write-enable of one register in a register file, or turning an opcode into control signals. Whenever an address must activate exactly one line, a decoder does it.
What is the difference between a decoder and a demultiplexer?
The same hardware, used differently. A decoder activates one output line chosen by the address; a demultiplexer additionally routes a data input onto that chosen line (an enable input on the decoder's ANDs turns it into a demux).