Skip to content

Encoders and decoders: 2-to-4 and 3-to-8 decoders, 4-to-2, 8-to-3 and priority encoders

A decoder turns an n-bit code into 2ⁿ output lines, exactly one of them active: each output is one minterm of the inputs. An encoder does the reverse, turning one active line out of 2ⁿ into its n-bit number, and a priority encoder picks the highest-numbered line when several are active.

This guide gives the truth tables of the 2-to-4 and 3-to-8 decoders, with enable inputs and active-low outputs, the 4-to-2 and 8-to-3 encoders and why two active inputs break them, and the priority encoder with its Karnaugh maps. It also builds any function from a decoder and an OR gate. The truth tables are computed by the Tangibool engine, and each claim links to a free checker that tests it on every row.

Decoder vs encoder at a glance

DecoderEncoder
Inputsn bits, a binary number2ⁿ lines, one of them active
Outputs2ⁿ lines, one of them activen bits, the number of the active line
Example3-to-8: 101 activates output 58-to-3: input 5 active gives 101
Each output isone minterm of the inputsan OR of the inputs whose number has that bit set
Typical usememory address decoding, displays, demultiplexingkeyboards, interrupt requests, position sensors
Classic chips74138 (3-to-8), 74139 (dual 2-to-4)74148 (8-to-3 priority encoder)

Decoders

2-to-4 decoder

A 2-to-4 decoder has two inputs, A1 (the 2 bit) and A0 (the 1 bit), and four outputs. Output Yk is 1 exactly when the inputs spell the number k. T stands for 1 and F for 0:

Truth table: Y0, Y1, Y2, Y3
#A1A0Y0Y1Y2Y3
0FALSEFALSETRUEFALSEFALSEFALSE
1FALSETRUEFALSETRUEFALSEFALSE
2TRUEFALSEFALSEFALSETRUEFALSE
3TRUETRUEFALSEFALSEFALSETRUE

Computed by the Tangibool engine

Each row has exactly one T among the outputs, on the diagonal. Each output is an AND of the inputs, each one inverted or not, which is exactly a minterm: Y0 = A1′·A0′, Y1 = A1′·A0, Y2 = A1·A0′ and Y3 = A1·A0. That exactly one output is active, whatever the inputs, can itself be checked: EXACTLY(1; Y0, Y1, Y2, Y3) is a tautology when the outputs are written out as their minterms.

The circuit is two NOT gates, for A1′ and A0′, and four two-input AND gates.

3-to-8 decoder

Three inputs give eight outputs, one per minterm:

Truth table: Y0, Y1, Y2, Y3, Y4, Y5, Y6, Y7
#A2A1A0Y0Y1Y2Y3Y4Y5Y6Y7
0FALSEFALSEFALSETRUEFALSEFALSEFALSEFALSEFALSEFALSEFALSE
1FALSEFALSETRUEFALSETRUEFALSEFALSEFALSEFALSEFALSEFALSE
2FALSETRUEFALSEFALSEFALSETRUEFALSEFALSEFALSEFALSEFALSE
3FALSETRUETRUEFALSEFALSEFALSETRUEFALSEFALSEFALSEFALSE
4TRUEFALSEFALSEFALSEFALSEFALSEFALSETRUEFALSEFALSEFALSE
5TRUEFALSETRUEFALSEFALSEFALSEFALSEFALSETRUEFALSEFALSE
6TRUETRUEFALSEFALSEFALSEFALSEFALSEFALSEFALSETRUEFALSE
7TRUETRUETRUEFALSEFALSEFALSEFALSEFALSEFALSEFALSETRUE

Computed by the Tangibool engine

Row 5, inputs 101, activates Y5 and nothing else. The circuit is three NOT gates and eight three-input AND gates. An n-to-2ⁿ decoder in general needs 2ⁿ AND gates, which is why large decoders are built from smaller ones.

Enable inputs and active-low outputs

Real decoder chips add an enable input, which switches every output off, and often make the outputs active-low: the selected output goes to 0 and the others stay at 1. The 74139, a dual 2-to-4 decoder, has an active-low enable G′ and active-low outputs, with inputs B (2) and A (1):

G′BAY0′Y1′Y2′Y3′
1XX1111
0000111
0011011
0101101
0111110

With an enable E, each output is E ANDed with its minterm: Y2 = E·B·A′. Active-low outputs are the complements of those. The 74138 3-to-8 decoder has three enables, one active-high and two active-low, all of which must be on.

Enables make decoders easy to cascade. A 4-to-16 decoder is two 3-to-8 decoders sharing the three low bits, with the fourth bit enabling one directly and the other through an inverter.

A decoder with an enable is also a demultiplexer: feed a data signal into the enable, and it appears on the one output the inputs select, while all the others stay off.

Any function from a decoder and an OR gate

Since a decoder's outputs are the minterms of its inputs, any function of those inputs is an OR of some of the outputs, the ones on which the function is 1. That is the minterm expansion of the function, built in hardware.

  • Majority of three is 1 on rows 3, 5, 6 and 7, so it is Y3 + Y5 + Y6 + Y7 of a 3-to-8 decoder. Written out as minterms, that OR is the majority function, (A·B) + (A·C) + (B·C).
  • A full adder is one 3-to-8 decoder and two OR gates: the sum is Y1 + Y2 + Y4 + Y7, which is A ⊕ B ⊕ C, and the carry-out is Y3 + Y5 + Y6 + Y7, the majority again.

With active-low outputs the OR becomes a NAND, by De Morgan's law: the NAND of the selected active-low outputs is 1 when any of them is 0.

Encoders

4-to-2 encoder

A 4-to-2 encoder has four inputs I0 to I3, of which exactly one is meant to be active, and two outputs Y1 Y0 that give its number in binary:

Active inputY1Y0
I000
I101
I210
I311

Each output bit is the OR of the inputs whose number has that bit set: Y1 = I2 + I3 and Y0 = I1 + I3. I0 appears in neither, because its number is 00.

When exactly one input is active, the encoder is right. Decoding its output recovers the input: for input 1, the decoder term Y1′·Y0 is (I2 + I3)′·(I1 + I3), and the truth table generator confirms that whenever exactly one input is active, it equals I1.

Why two active inputs break an encoder

A plain encoder assumes one active input, and the assumption matters. With I1 and I3 both active, Y1 Y0 = 11, the code for I3; input 1 has vanished. With I1 and I2 both active, the output is again 11, the code of an input that is not active at all. Without the one-input assumption, the round trip above fails, and the checker's counterexample is exactly the case with I1 and I3 both active.

There is a second gap: with no input active, the outputs are 00, the same as for I0. Encoders therefore add a valid output V, which is 1 when any input is active: V = I0 + I1 + I2 + I3, the same as “not all inputs are 0”.

8-to-3 encoder

Active inputY2Y1Y0
I0000
I1001
I2010
I3011
I4100
I5101
I6110
I7111

So Y2 = I4 + I5 + I6 + I7, Y1 = I2 + I3 + I6 + I7 and Y0 = I1 + I3 + I5 + I7: three four-input OR gates.

Priority encoder

A priority encoder resolves the two-active-inputs problem by rule: the highest-numbered active input wins, and the lower ones are ignored. For four inputs, with the valid output V:

I3I2I1I0Y1Y0V
0000XX0
0001001
001X011
01XX101
1XXX111

X in an input column means “either value”: once I3 is active, the other inputs do not matter. X in an output column means “don't care”: with no input active, V = 0 says the code is meaningless.

Deriving the outputs with Karnaugh maps

Expand the table to all 16 input rows, with I3 as the most significant bit and the no-input row taken as 0:

  • Y1 is 1 whenever I3 or I2 is active, rows 4 to 15. On the map that is two groups of eight, and the Karnaugh map solver gives Y1 = I3 + I2, which matches the table.
  • Y0 is 1 when I3 is active, rows 8 to 15, or when I1 is the highest active input, rows 2 and 3. The Karnaugh map solver groups those as I3 and I2′·I1, so Y0 = I3 + I2′·I1, which matches the table.
  • V = I3 + I2 + I1 + I0.

The engine's table of all three outputs:

Truth table: Y1, Y0, V
#I3I2I1I0Y1Y0V
0FALSEFALSEFALSEFALSEFALSEFALSEFALSE
1FALSEFALSEFALSETRUEFALSEFALSETRUE
2FALSEFALSETRUEFALSEFALSETRUETRUE
3FALSEFALSETRUETRUEFALSETRUETRUE
4FALSETRUEFALSEFALSETRUEFALSETRUE
5FALSETRUEFALSETRUETRUEFALSETRUE
6FALSETRUETRUEFALSETRUEFALSETRUE
7FALSETRUETRUETRUETRUEFALSETRUE
8TRUEFALSEFALSEFALSETRUETRUETRUE
9TRUEFALSEFALSETRUETRUETRUETRUE
10TRUEFALSETRUEFALSETRUETRUETRUE
11TRUEFALSETRUETRUETRUETRUETRUE
12TRUETRUEFALSEFALSETRUETRUETRUE
13TRUETRUEFALSETRUETRUETRUETRUE
14TRUETRUETRUEFALSETRUETRUETRUE
15TRUETRUETRUETRUETRUETRUETRUE

Computed by the Tangibool engine

Row 6 (I2 and I1 active) gives Y1 Y0 = 10, input 2, the higher of the two. Compared with the plain encoder, only Y0 has changed: the term I2′ stops I1 from setting Y0 when I2 is also active. When exactly one input is active, the priority encoder and the plain encoder give the same outputs.

The 74148 is an 8-to-3 priority encoder with active-low inputs and outputs, plus enable-in and enable-out pins that let two of them be cascaded into a 16-to-4 priority encoder.

Where encoders and decoders are used

  • Memory and peripherals. An address decoder turns the high bits of an address into a chip-select signal, so only one memory chip or device answers.
  • Displays. A decoder drives one of several digits, LEDs or rows at a time, and a BCD to seven-segment decoder is a special decoder whose outputs light segments.
  • Interrupts. A priority encoder tells a processor which interrupt request to serve first when several arrive together.
  • Keyboards and sensors. An encoder reduces many switch lines to a short binary number.
  • Instruction decoding. A processor decodes the bits of each instruction to activate the circuits that carry it out.

Common mistakes

  1. Feeding a plain encoder two active inputs. It outputs a code that may match neither, as shown above. Use a priority encoder when more than one input can be active.
  2. Forgetting the valid output. Without V, “no input” and “input 0” give the same code.
  3. Missing active-low signals. On the 74138 and 74139 the selected output is the one that goes low; on the 74148 the inputs are active-low too.
  4. Mixing up the directions. A decoder goes from a binary number to one line; an encoder goes from one line to a binary number.
  5. Forgetting the enables. A 74138 with an enable left inactive keeps all eight outputs off.

Try it yourself

  1. Write each output as a Boolean expression, for example I3 OR (NOT I2 AND I1) for the priority encoder's Y0.
  2. Open the truth table generator to see every row, or the Karnaugh map solver with a minterm list such as Σm(I3, I2, I1, I0; 2, 3, 8, 9, 10, 11, 12, 13, 14, 15) to see the groups.
  3. To check an assumption such as “exactly one input is active”, write it with EXACTLY(1; I0, I1, I2, I3) and test “assumption implies output” for a tautology in the truth table generator.

Frequently asked questions

What is a decoder in digital logic?

A circuit with n inputs and 2ⁿ outputs that activates exactly one output, the one whose number the inputs spell. Each output is one minterm of the inputs.

What is the truth table of a 3-to-8 decoder?

Eight rows, one per input combination from 000 to 111; on row k, output Yk is 1 and all the others are 0.

What is the truth table of a 2-to-4 decoder?

Inputs 00, 01, 10 and 11 activate outputs Y0, Y1, Y2 and Y3 respectively, one at a time.

What is an encoder?

A circuit with 2ⁿ inputs, one of them active, and n outputs that give the number of the active input in binary.

What is a priority encoder?

An encoder that gives the number of the highest-priority active input, usually the highest-numbered one, when several are active, and a valid output that is 0 when none is.

What is the difference between an encoder and a decoder?

A decoder goes from an n-bit number to one active line out of 2ⁿ; an encoder goes from one active line out of 2ⁿ to its n-bit number.

How do you implement a function with a decoder?

Connect the function's variables to the decoder's inputs and OR together the outputs for the rows where the function is 1. A full adder needs one 3-to-8 decoder and two OR gates.

Why does an encoder need a valid output?

Because with no input active the outputs are all 0, which is also the code for input 0. The valid output tells the two cases apart.

Written by Muaz Notiar. The Tangibool engine (semantics tangibool-semantics/1, engine 1.0.0) computed the 3 truth tables marked “Computed by the Tangibool engine”, and the 11 tool results the guide links to were re-run through the tools' own code in the build of and match what the text says. © 2026 Foreranger LTD.