Skip to content
K-Map Solver
Tutorial

How to solve a 4-variable Karnaugh map, step by step

By K-Map Solver · · 3 min read

A 4-variable Karnaugh map with three coloured groups, one of them the four corner cells.
In this article
  1. 1. Lay the grid out in Gray-code order
  2. 2. Mark the ones and the don't-cares
  3. 3. Group the ones in rectangles of 1, 2, 4, 8 or 16
  4. 4. Use the edges
  5. 5. Read each group as a product term
  6. 6. Check the answer

A four-variable Karnaugh map has sixteen cells, one for every combination of A, B, C and D. It is small enough to solve by eye and big enough that every trick matters: wrap-around, overlapping groups and don't-cares. Here is a routine that works every time.

1. Lay the grid out in Gray-code order

Label the rows with AB and the columns with CD, and write both in the order 00, 01, 11, 10. Between any two neighbours exactly one variable changes, and that is what makes grouping possible. Reading A as the most significant bit, row 0 holds minterms 0, 1, 3, 2 and row 1 holds 4, 5, 7, 6.

2. Mark the ones and the don't-cares

Put a 1 in every cell where the function is true and an X where you do not care. Our running example is F = Σm(0, 2, 7, 10, 14) with don't-cares at 5 and 8.

3. Group the ones in rectangles of 1, 2, 4, 8 or 16

A group must be a rectangle holding a power-of-two number of cells. Bigger groups give shorter terms: a group of two drops one variable, a group of four drops two, a group of eight drops three.

  • Cover every 1 at least once; groups may overlap.
  • Make each group as large as possible.
  • An X may join a group when it makes the group bigger, but an X never has to be covered.
  • Use as few groups as you can.

4. Use the edges

The top and bottom rows are neighbours, and so are the left and right columns. The four corners form a single group of four. In the example, cells 0, 2, 8 and 10 are the corners; they all have B = 0 and D = 0, so together they give B'D'. Cell 8 is a don't-care that we happily borrow to complete the corner group.

5. Read each group as a product term

Keep the variables that do not change inside the group and drop the ones that do. Cells 5 and 7 are 0101 and 0111: A = 0, B = 1 and D = 1 stay fixed while C changes, so the term is A'BD. Cells 10 and 14 are 1010 and 1110: A = 1, C = 1, D = 0 stay and B changes, giving ACD'.

Worked example: sum of products

The running example, solved. Add the three terms and you have the whole function.

F = Σm(0, 2, 7, 10, 14) + d(5, 8)

ABCD0001111000011110

Simplified result

F = B'D' + A'BD + ACD'

  • B'D' — minterms (0, 2, 8, 10), includes don't-care 8
  • A'BD — minterms (5, 7), includes don't-care 5
  • ACD' — minterms (10, 14)

6. Check the answer

Evaluate the expression for every row of the truth table. It must give 1 on every 1, and 0 on every 0; only the don't-cares may go either way. The solver does this for you in the “Checked against your function” badge and the verification table, but it is a good habit to do it once by hand.