LogicGates.org Open the simulatorSimulator

2-to-4 decoder

A decoder is a combinational circuit that takes an n-bit binary number and raises exactly one of its 2ⁿ outputs, the one whose index matches the input.

Turns a 2-bit number into one hot line.

Circuit diagram

Toggle the inputs and follow the signals: green wires are high, red are low. The highlighted row of the truth table below is the one you have set.

y0 1 y1 0 y2 0 y3 0

Truth table

AB y0y1y2y3
00 1000
01 0100
10 0010
11 0001

Boolean expressions

y0
¬a ∧ ¬b high for 00
y1
¬a ∧ b high for 01
y2
a ∧ ¬b high for 10
y3
a ∧ b high for 11

How it works

A decoder raises exactly one output, the one whose number matches the input. Each output is a single AND of the inputs in the right polarities, which means a decoder is really all the minterms of its inputs made available at once.

Where it is used

  • Address decoding: picking which chip or register a bus address refers to.
  • Driving a display, where each output lights one element.
  • Building any function at all, by ORing together the minterms you want.

Build it

Two NOTs and four ANDs. Toggle the inputs and watch exactly one output light at a time.

Open the simulator

Or draw it from the expressions above with the circuit diagram generator, in either symbol standard, and export it as SVG, PNG, Verilog or VHDL.

Reference card

The diagram above as an image, black on white, for notes or a slide.

2-to-4 decoder logic circuit diagram with inputs a = A, b = B: y0 from ¬a ∧ ¬b, y1 from ¬a ∧ b, y2 from a ∧ ¬b, y3 from a ∧ b Click to download: 2-to-4 decoder circuit diagram

Questions about the 2-to-4 decoder

What is a decoder used for?

Address decoding, where the high bits of a bus address select one chip or register; driving displays and indicator lamps, one output per element; and generating the minterms of a function, since a decoder's outputs are exactly the minterms of its inputs, so any function is an OR of the right ones.

What is the difference between a decoder and an encoder?

They are inverses. A decoder turns a binary number into a single active line, one hot out of many. An encoder turns a single active line back into its binary number. A 2-to-4 decoder and a 4-to-2 encoder undo each other.

How does a 2-to-4 decoder work?

Each output is one AND gate fed by the inputs in the right polarity: Y0 is ¬A ∧ ¬B, Y1 is ¬A ∧ B, Y2 is A ∧ ¬B and Y3 is A ∧ B. Two inverters and four AND gates make the whole circuit, and adding an enable input to every AND gives a decoder that can be switched off.

The other circuits