LogicGates.org Open the simulatorSimulator
Roadmap

Karnaugh maps

Lesson 2 of 4 in this stage, about 14 minutes

The truth table folded so that neighbours touch, and loops of 1s that turn into short terms.

Two rows that share a reason

In the last lesson, rows 6 and 7 of a truth table were both 1, and both for the same reason: a and b were 1 and c did not matter. Their minterms, a·b·c̅ and a·b·c, differ only in c. ORed together they say "a and b, with c either way", which is just a·b. This is the one rule that every method in this stage relies on: two terms that differ in exactly one input merge into one term without that input. Finding such pairs in a truth table is hard, because the rows that differ in one bit are scattered. Row 3 (011) and row 4 (100) sit next to each other and differ in every bit; row 1 (001) and row 5 (101) differ in one bit and sit four lines apart.

Fold the table so neighbours touch

A Karnaugh map, named after Maurice Karnaugh who published it in 1953, is the truth table rearranged into a grid so that any two cells that are side by side differ in exactly one input. For two inputs that is a 2 by 2 grid: a picks the row, b picks the column. For three inputs the grid is 2 rows by 4 columns: a picks the row and the pair bc picks the column. The trick is the order of the column headings. Counting order would be 00, 01, 10, 11, but going from 01 to 10 changes both bits, so those two columns would not be neighbours. Instead the headings run 00, 01, 11, 10, where each step changes one bit.

Here is the two-input map. The cell numbers are the row numbers from the truth table. Click the cells: with two 1s side by side the widget draws a group and writes the term it stands for.

Two inputs. Click a cell to change it.

a b 01
0
1
Groups

Expression a

Circling groups

Once the 1s are on the map, minimising becomes pattern spotting. Draw a loop round any rectangle of 1s whose size is 1, 2 or 4 cells (or 8 or 16 on bigger maps: always a power of two). Each loop is one product term. To write it, look at the inputs: any input that has the same value in every cell of the loop stays in the term, plain if that value is 1 and barred if it is 0. Any input that changes inside the loop drops out. A loop of two drops one input, a loop of four drops two, so bigger loops give shorter terms. Then OR the terms of all the loops together.

The rules for the loops, all of which follow from that:

  • Every 1 must be inside at least one loop, or the expression would miss a row.
  • A loop may contain only 1s. One 0 inside it would make the term fire on a row that should be 0.
  • Loops may overlap. Using a 1 twice costs nothing, and it often lets both loops be bigger.
  • Make each loop as big as you can, and use as few loops as you can.
  • The map wraps: the left column is next to the right column, because 00 and 10 differ in one bit.
Why?: why must a loop be a power of two?

A loop of two merges one pair and drops one input. A loop of four is two such pairs that themselves differ in a second input, so it drops two. Every doubling drops one more input. Three cells cannot be described that way: there is no set of inputs whose "either way" gives exactly three rows. Three 1s in a line are a loop of two plus a loop of two that overlap, and that is two terms, not one.

Worked example. A function of a, b and c is 1 on rows 0, 2, 5 and 7. Find its minimal expression with a map.

Draw the map with a down the side and bc across the top in the order 00, 01, 11, 10. Row a = 0 holds m0, m1, m3, m2 in that order, and row a = 1 holds m4, m5, m7, m6. Put 1s in m0, m2, m5 and m7. In the top row the 1s are in the first and last columns, bc = 00 and bc = 10. Those columns are neighbours because the map wraps, so they form a loop of two. Inside it a is 0 throughout and c is 0 throughout, while b changes, so the term is a̅·c̅. In the bottom row m5 and m7 sit side by side, bc = 01 and bc = 11. There a is 1 and c is 1 while b changes: a·c. Every 1 is covered, so the answer is a̅·c̅ + a·c, two terms instead of four minterms.

The map below starts with that function. Click cells to add and remove 1s and watch the loops move.

Click a square to change it. The groups and the expression follow.

a bc 00011110
0
1
Groups

Expression a̅·c̅ + a·c

Common mistake: looping cells that only look adjacent

Two cells that touch at a corner are not neighbours: moving diagonally changes two inputs. Nor are three cells in a row a loop, however tempting. And the wrap round the edge only joins the two end columns (or the top and bottom rows); it does not make a cell adjacent to one two steps away in the same row. If in doubt, write the two cells in binary and count the bits that differ. Neighbours differ in exactly one.

Reading the result

The expression from a map is a sum of products, the same shape as the canonical one from the last lesson, but with fewer and shorter terms. Each loop is one AND gate, or no gate at all if only one input is left, and one OR gate collects them. The Karnaugh map solver on this site draws the loops for up to six inputs, and the widget above uses the same engine, so its loops are the solver's loops.

What to remember

  • Two terms that differ in exactly one input merge into one term without that input.
  • A Karnaugh map is the truth table laid out with headings in Gray order, so neighbouring cells differ in one bit.
  • Loop rectangles of 1s of size 1, 2, 4 or 8; each loop is one term, and inputs that change inside it drop out.
  • Bigger loops mean shorter terms; overlapping is free; the map wraps round its edges.
  • OR the terms of the loops together for the minimal sum of products.

Check yourself

Get 5 right in a row and the lesson is done. A wrong answer costs the run, not the lesson.

0 right in a row. 0 / 0 this visit

A loop on a three-input map covers the cells m4, m5. Which term does the loop stand for?

100, 101

Already know this? and come back to the quiz any time.

Go deeper