Learn › Topic 4
Karnaugh maps for 2, 3 and 4 variables with don't-care conditions
7 min read · bitGateLab Team
Simplifying with Boolean algebra works, but it depends on you "seeing" which law to apply. The Karnaugh map turns that search into a visual exercise: it arranges the truth table in a grid where neighboring cells differ in a single variable, and simplifying becomes a matter of circling groups of ones. Here you will learn to build maps of 2, 3 and 4 variables, to group correctly (including the edges that "wrap around") and to take advantage of don't-care conditions.
The idea: neighboring cells, one variable apart
The adjacency law says that AB + AB = A: two terms that differ in a single variable merge, and that variable disappears. The Karnaugh map arranges the minterms so that any pair of cells sharing a side meets that condition. To achieve this, the row and column headings do not follow the binary order 00, 01, 10, 11, but the Gray code: 00, 01, 11, 10. Only one bit changes between two consecutive values, and also between the last and the first (10 and 00). That is why the map behaves as if its opposite edges were glued together.
Maps of 2 and 3 variables
The two-variable map has 4 cells: A on the rows and B on the columns. The three-variable map has 8 cells: A on the rows and BC on the columns, in Gray order. The number inside each cell shows the minterm it corresponds to:
| A \ BC | 00 | 01 | 11 | 10 |
|---|---|---|---|---|
| 0 | m0 | m1 | m3 | m2 |
| 1 | m4 | m5 | m7 | m6 |
Notice that m3 and m2 appear in that order: it is the effect of the Gray code, and the cause of many mistakes when filling in the map by hand.
Grouping rules
- Groups may contain only ones (or X's, as you will see later), never zeros.
- The size of each group must be a power of 2: 1, 2, 4, 8 or 16 cells.
- Groups are rectangles of adjacent cells, including adjacency across the edges. Diagonals do not count.
- Make each group as large as possible: a group of 2k cells eliminates k variables.
- Use the smallest number of groups that covers all the ones. Groups may overlap.
To read a group, check each variable: if it keeps the same value in every cell of the group, it appears in the term (without a bar if it is 1, with a bar if it is 0); if it changes, it is eliminated.
Example 1: three variables. Simplify F(A, B, C) = Σm(1, 3, 4, 5, 7).
| A \ BC | 00 | 01 | 11 | 10 |
|---|---|---|---|---|
| 0 | 0 | 1 | 1 | 0 |
| 1 | 1 | 1 | 1 | 0 |
- Columns 01 and 11 are full: a group of 4 (m1, m3, m5, m7). In it A changes, B changes and C is always 1. Term: C.
- That leaves m4. It is grouped with m5 (its neighbor to the right): A = 1, B = 0 in both, C changes. Term: AB.
- F = C + AB.
Check m6 (110): C = 0 and AB = 0, so F = 0, the same as in the map.
The 4-variable map and adjacency at the edges
With four variables the map has 16 cells: AB on the rows and CD on the columns, both in Gray order.
| AB \ CD | 00 | 01 | 11 | 10 |
|---|---|---|---|---|
| 00 | m0 | m1 | m3 | m2 |
| 01 | m4 | m5 | m7 | m6 |
| 11 | m12 | m13 | m15 | m14 |
| 10 | m8 | m9 | m11 | m10 |
The left column is a neighbor of the right one, and the top row is a neighbor of the bottom one. As a result, the four corners (m0, m2, m8, m10) form a valid group of 4 cells: in all of them B = 0 and D = 0, so they read as BD.
Example 2: groups that cross the edges. Simplify F(A, B, C, D) = Σm(0, 1, 2, 5, 8, 9, 10).
| 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 |
- m0, m1, m8, m9: columns 00 and 01 of the top and bottom rows (neighbors across the edge). B = 0 and C = 0. Term: BC.
- m0, m2, m8, m10: the four corners. Term: BD.
- That leaves m5 (0101). Its best neighbor holding a 1 is m1 (0001): A = 0, C = 0, D = 1 and B changes. Term: ACD.
- F = BC + BD + ACD.
You went from 7 minterms of 4 literals each (28 literals) to 3 terms with 7 literals in total.
Don't-care conditions (X)
Sometimes certain input combinations never occur, or their output has no consequences. For example, in a BCD digit the codes 1010 to 1111 do not exist. Those rows are marked with an X (known as a don't care) and listed separately as d(...). When grouping, each X may be taken as a 1 if it helps you form a larger group, or ignored if it does not. An X never needs to be covered.
Example 3: with X conditions. Simplify F(A, B, C, D) = Σm(1, 3, 7, 11, 15) + d(0, 2, 5).
| AB \ CD | 00 | 01 | 11 | 10 |
|---|---|---|---|---|
| 00 | X | 1 | 1 | X |
| 01 | 0 | X | 1 | 0 |
| 11 | 0 | 0 | 1 | 0 |
| 10 | 0 | 0 | 1 | 0 |
- The column CD = 11 is full (m3, m7, m15, m11): term CD.
- m1 is still missing. Taking the X's of m0 and m2 as ones, the whole top row is a group of 4: term AB.
- F = CD + AB.
There is another solution that is just as good: take the X of m5 and group m1, m3, m5, m7, which gives AD. Then F = CD + AD. Both have 2 terms and 4 literals, and both agree in every row that does matter. It is normal for a function to have more than one minimal form.
Common mistakes
- Ordering the headings in binary (00, 01, 10, 11) instead of Gray. The map no longer has neighbors that differ in a single variable, and the groups come out wrong.
- Forming groups of 3 or 6 cells. Only powers of 2 are allowed.
- Forgetting the adjacency of the edges and of the four corners, which leaves groups smaller than necessary.
- Adding a group whose cells are all already covered by others. It is redundant and adds gates.
- Forcing yourself to cover the X's. They are used only when they enlarge a group.
Try it in the simulator
The Karnaugh map module arranges the function in Gray order, marks the groups and writes the minimal expression, so you can compare your grouping with the one the tool proposes.
- Create a four-variable function and enter the ones from example 2.
- Group them yourself on paper first and write down your result.
- Look at the groups the map marks and the resulting expression; if it differs from yours, check which of your groups was not as large as possible.
- Enter example 3, marking cells 0, 2 and 5 as X, and watch how the simplification changes when you remove those X's.
- Convert the result to a circuit and toggle the inputs to confirm that it matches the table.
Exercises
- Simplify F(A, B, C) = Σm(0, 2, 4, 6).
Answer
The columns BC = 00 and BC = 10 are neighbors across the edge and both are full. In all four cells C = 0: F = C.
- Simplify F(A, B, C, D) = Σm(0, 2, 5, 7, 8, 10, 13, 15).
Answer
Corners: BD. Center block m5, m7, m13, m15: BD. F = BD + BD, which is the XNOR of B and D.
- Simplify F(A, B, C, D) = Σm(4, 5, 6, 7, 12, 13, 14, 15).
Answer
The rows AB = 01 and AB = 11 form a group of 8; only B stays at 1. F = B.
- A BCD digit (A is the most significant bit) must turn on an output when its value is 5 or more. Simplify F = Σm(5, 6, 7, 8, 9) + d(10, 11, 12, 13, 14, 15).
Answer
With the X's, the rows AB = 11 and AB = 10 form a group of 8: A. The block m5, m7, m13, m15 gives BD and the block m6, m7, m14, m15 gives BC. F = A + BD + BC = A + B(C + D).
With more than four or five variables the map becomes hard to read; for those cases there is a tabular procedure, the Quine-McCluskey method.