Karnaugh Maps: Simplify Boolean Functions Step by Step
A step by step guide to Karnaugh maps: how to fill a 4 variable map, group cells, use don't cares and write the simplest sum of products, with a worked example.
A picture of the truth table
A Karnaugh map, or K-map, is a truth table redrawn as a grid, so that you can simplify a function by looking at it. Each cell of the grid is one row of the truth table. The key idea is that cells next to each other differ in exactly one variable, so a pair of neighbours with a 1 in both can be written without that variable.
This is the same work as Boolean algebra, but easier and less likely to go wrong, for up to four or five variables.
Building the map
A four variable map has 16 cells, in four rows and four columns. Label the rows with AB and the columns with CD. The labels must follow Gray code order, 00, 01, 11, 10, and not binary order. In Gray code only one bit changes between neighbours, and that is what makes the neighbours work.
Write a 1 in each cell whose minterm is in the function, and a 0 elsewhere. Both the top and bottom edges, and the left and right edges, count as neighbours, so the map wraps around like a tube. The four corners are also neighbours of one another.
The grouping rules
- Group the 1s in rectangles of 1, 2, 4, 8 or 16 cells. The size must be a power of 2.
- Make each group as large as you can. A large group removes more variables.
- Cover every 1 at least once. A cell may be used in more than one group.
- Use as few groups as possible.
- A group of 2 removes one variable, a group of 4 removes two, and a group of 8 removes three.
To write the term of a group, keep the variables that are the same for every cell in the group, and drop the ones that change. A variable that is 1 is written plain. A variable that is 0 is written with an apostrophe.
Worked example
Simplify F(A, B, C, D) = Σm(0, 1, 2, 5, 8, 9, 10). The map looks like this.
Group 1: the four corners (0, 2, 8, 10) → B' D' Group 2: the two left columns of rows 00 and 10 (0, 1, 8, 9) → B' C' Group 3: cells 1 and 5 → A' C' D F = B' D' + B' C' + A' C' D
| AB \ CD | 00 | 01 | 11 | 10 |
|---|---|---|---|---|
| 00 | 1 | 1 | 0 | 1 |
| 01 | 0 | 1 | 0 | 0 |
| 11 | 0 | 0 | 0 | 0 |
| 10 | 1 | 1 | 0 | 1 |
The original function has seven minterms of four variables each. The result has three terms of two or three variables. Check one cell: minterm 5 is A = 0, B = 1, C = 0, D = 1. The term A' C' D is 1 for these values, as it should be.
Don't care conditions
Sometimes an input combination never happens, or the output does not matter for it. Mark those cells with an X. You may treat each X as a 1 if that makes a bigger group, and ignore it otherwise. Don't cares give simpler results.
A common case is a decoder for BCD digits. The codes 1010 to 1111 never occur, so six cells are don't cares. This is the case for the seven segment decoder, and the reason its equations are short.
Product of sums
You can also group the 0s. Each group then gives a sum term. The function is the AND of those sums. In a sum term, a variable that is 0 in the group is written plain, and one that is 1 is written with an apostrophe. This gives the product of sums form, which is good for building the circuit from NOR gates.
Checking and limits
- Check the answer by filling a truth table for a few rows, or by testing it on the breadboard.
- A K-map is practical up to four variables, and with care to five. Larger problems use the Quine-McCluskey method or software.
- A minimal answer is not always unique. Two different groupings can give two equal size answers.
The final step is to build the circuit. Write the sum of products, then wire the AND terms to an OR gate, or use NAND gates for both levels.
Try it in the virtual lab
SinBench has free 3D benches and interactive demos for this topic. Open one to try the ideas above with real instruments, no sign up needed.
Questions and answers
Why does a K-map use Gray code order?
Gray code changes only one bit between neighbouring cells, so neighbouring cells differ in one variable. That lets you drop that variable when you group them.
How big can a K-map group be?
A group must hold a power of 2 cells: 1, 2, 4, 8 or 16. Bigger groups remove more variables.
What is a don't care in a K-map?
It is an input combination whose output does not matter. It can be used as a 1 or a 0, whichever gives larger groups.
Does the edge of a K-map wrap around?
Yes. The left and right edges are neighbours, and so are the top and bottom edges. The four corners also form a group.
Related topics
Boolean Algebra and De Morgan's Laws
Learn the Boolean identities, absorption and consensus, and De Morgan's laws, with worked simplification examples and truth table proofs you can check.
Digital Logic DesignNAND and NOR as Universal Gates
See why NAND and NOR are universal gates. Build NOT, AND, OR and XOR from NAND only and from NOR only, count the gates and use two level NAND logic.
Digital Logic DesignBCD to Seven Segment Decoder: The 7447 and Common Anode Displays
Learn how a 7447 drives a common anode seven segment display: BCD input, active low outputs, segment patterns, resistors, the lamp test and ripple blanking.