# What is a 2 to 4 line decoder?

Could I get a basic description of a 2 to 4 line decoder? I've tried looking online but they make it too complicated for me to understand.

A decoder takes in an address and then activates the output line corresponding to it. Pulling that line high or low depending on the decoder.

image source: wikipedia

The 2to4 means it takes a 2 bit address and controls 4 outputs. The number of outputs is always $2^{inputs}$.

They typically have an enable input to make it ignore the input and turn all outputs off. That way you can cascade them.

• Thank you so much! (First post, whoops!) But this helped so much, thanks for the edit in particular. Oct 8, 2017 at 12:38

Also called a 2 to 4 demux - it's simply a way of converting a binary number into a selected line. That line alone is asserted (or goes high) while the rest stay low. So

00  -  line 0 goes high
01  -  line 1 goes high
10  -  line 2 goes high
11  -  line 3 goes high


The most common use used to be to convert part of an address from a CPU into a select line to select a particular RAM or ROM chip.

• Demux is slightly different, as a demux implies routing a signal through. You can build one with an decoder by either connecting the data signal to the 'enable' signal or by using AND gates on each decoder output. Oct 8, 2017 at 21:37
• Yes, apologies - you are absolutely right. A demultiplexer routes 1 data input to one of 2^n selected lines (0,1,2,3 in the above case), based on the value on its n control lines (00,01,10,11 in the above case). My bad... Oct 9, 2017 at 9:44

Two input lines can take four different states: 00, 01, 10 and 11. For each of these, a different output line (but always only one) is enabled:

in | out
00 | 1000
01 | 0100
10 | 0010
11 | 0001


This is useful for example when addressing different ICs connected to a shared bus, e.g. for SPI you would connect SCLK, MISO and MOSI to all devices, and the CS for each to one of the decoder outputs, then you could select with two GPIOs which of the four connected devices you want to talk to. Without a decoder, you'd need four GPIOs, and you'd need to take extra care to never activate two devices at the same time.