Karnaugh Map Tutorial: Simplify Boolean Logic by Hand (with Don’t-Cares)
A Karnaugh map turns Boolean simplification into a visual game: you re-draw the truth table as a grid where neighbouring cells differ by exactly one variable, circle the biggest power-of-two blocks of 1s, and read the minimal sum-of-products straight off the page — no algebra theorems to memorize. This tutorial works through 2-, 3- and 4-variable maps, the grouping rules, how to read a group back into a product term, and the headline trick that beginners miss: don’t-care terms that you bend to 0 or 1 to grow even larger groups. Check any result in the Karnaugh Map Solver.
What a K-map is — and why Gray code
A Karnaugh map is just a truth table re-arranged into a grid so that any two cells that touch differ by exactly one input variable. That adjacency is what lets you spot a simplification by eye: if two neighbouring cells are both 1 and only one variable changes between them, that variable does not matter and drops out of the term.
The adjacency is achieved by labeling the rows and columns in Gray code order — 00, 01, 11, 10 — rather
than the plain binary counting order 00, 01, 10, 11. In Gray code every step flips just one bit; in binary counting the
jump from 01 to 10 flips two bits at once, which would break adjacency. Getting this ordering wrong
breaks the whole method, so it is the one rule to nail down first.
| Position | Gray code (correct) | Binary counting (wrong for K-maps) |
|---|---|---|
| 1st | 00 | 00 |
| 2nd | 01 | 01 |
| 3rd | 11 | 10 |
| 4th | 10 | 11 |
⚠️ The same Gray-code idea powers rotary encoders and the truth-table-to-Boolean workflow: change one variable per step so transitions are unambiguous. On a K-map it is what makes neighbouring 1s combinable.
2-variable map (A, B)
With two variables the map is a 2×2 grid: variable A labels the rows (0, 1) and variable B labels
the columns (0, 1). Each cell holds the output for that A,B combination. Minterms are numbered m = 2·A + B (A is the
most-significant bit), so m0 = 00, m1 = 01, m2 = 10, m3 = 11.
Take F = Σm(1, 2, 3) — F is 1 for AB = 01, 10 and 11, and 0 only for AB = 00:
| A \ B | B = 0 | B = 1 |
|---|---|---|
| A = 0 | 0 (m0) | 1 (m1) |
| A = 1 | 1 (m2) | 1 (m3) |
Now circle the largest power-of-two blocks of 1s. Two groups of 2 cover everything:
- The whole B = 1 column (m1, m3) — here A changes but B stays 1, so the term is just
B. - The whole A = 1 row (m2, m3) — here B changes but A stays 1, so the term is just
A.
OR the two terms together: F = A + B. The shared cell m3 is covered by both groups, which is allowed.
3-variable map (A, B, C)
With three variables the map is a 2×4 grid. Put A on the rows (0, 1) and the pair BC on the columns,
labeled in Gray code 00, 01, 11, 10. Minterms are numbered m = 4·A + 2·B + C, so the column order maps to
m0, m1, m3, m2 in row A = 0 and m4, m5, m7, m6 in row A = 1.
Take F = Σm(0, 1, 2, 3, 7):
| A \ BC | 00 | 01 | 11 | 10 |
|---|---|---|---|---|
| A = 0 | 1 (m0) | 1 (m1) | 1 (m3) | 1 (m2) |
| A = 1 | 0 (m4) | 0 (m5) | 1 (m7) | 0 (m6) |
Two groups cover all five 1s:
- The entire A = 0 row (m0, m1, m3, m2) is a group of 4. Across it B and C both change while only A stays constant at 0, so the four-cell group eliminates two variables and gives the single-variable term
A′(A-bar). - The BC = 11 column pair m3 and m7 is a group of 2. Across it A changes while B and C stay 1, so it gives
B·C.
The simplified sum-of-products is F = A′ + B·C, down from five minterms to two short terms.
4-variable map (A, B, C, D) & wrap-around
Four variables give a 4×4 grid. The rows are the pair AB in Gray code 00, 01, 11, 10 and the columns are
the pair CD, also Gray-coded 00, 01, 11, 10. Minterm number is m = 8·A + 4·B + 2·C + D. Here is
a map for an example function with a group of 4 and a group of 2:
| AB \ CD | 00 | 01 | 11 | 10 |
|---|---|---|---|---|
| 00 | 1 (m0) | 1 (m1) | 0 (m3) | 0 (m2) |
| 01 | 0 (m4) | 0 (m5) | 0 (m7) | 0 (m6) |
| 11 | 0 (m12) | 0 (m13) | 0 (m15) | 0 (m14) |
| 10 | 1 (m8) | 1 (m9) | 0 (m11) | 0 (m10) |
The 1s sit at m0, m1, m8, m9. Two ways to read it, both correct and minimal:
- Group of 4 (wrap-around): m0, m1 (top row, CD = 00/01) together with m8, m9 (bottom row, CD = 00/01) form a 2×2 block — but only because the top and bottom rows are adjacent. The AB labels 00 (top) and 10 (bottom) differ by one bit, so the grid wraps vertically. Across this block of 4, C and A both change while B = 0 and D-free... reading off: B stays 0 and C stays 0, A and D change → term
B′·C′. - Equivalently you can take the group of 4 as
B′·C′directly: the four 1s are exactly the cells where B = 0 and C = 0.
So F = B′·C′. The key info-gain here is the wrap-around adjacency:
- The top and bottom edges are neighbours (rows AB = 00 and AB = 10 differ by one bit).
- The left and right edges are neighbours (columns CD = 00 and CD = 10 differ by one bit).
- The four corner cells (m0, m2, m8, m10) are all mutually adjacent and can form a single group of 4 — a trap beginners miss because the cells look far apart on the page.
The grouping rules
These five rules are the spine of the whole method — follow them in order:
- Groups must be rectangular (including the wrap-around rectangles) and contain only 1s — never enclose a 0.
- Group size must be a power of two: 1, 2, 4, 8 or 16 cells. Sizes like 3, 5 or 6 are not allowed.
- Make each group as large as possible — a bigger group means fewer literals. A group of 2 eliminates 1 variable, a group of 4 eliminates 2, and a group of 8 eliminates 3.
- Use as few groups as possible to cover every 1. Groups may overlap, and they may wrap around the edges and corners.
- Each group becomes one AND term (a product). OR all the product terms together and you have the simplified sum-of-products.
When you are unsure whether you have found the minimal cover, paste the function into the Boolean Algebra Simplifier and compare term counts.
Reading a group → term
Translating a circled group back into a product term follows one rule: a variable that stays constant across the whole group appears in the term, while a variable that changes drops out.
- If the constant variable is held at 1, it appears uncomplemented (e.g.
A). - If it is held at 0, it appears complemented (e.g.
A′). - Any variable that takes both 0 and 1 inside the group is dropped.
Explicit example, from the 3-variable map above: the group of 2 covering m3 and m7. Comparing the two cells, A = 0 and A = 1 (changes,
so A drops out), B = 1 in both (constant 1 → B), C = 1 in both (constant 1 → C). Read-off: B·C.
That is exactly the term we used.
Don’t-care terms (X)
Some input combinations can never physically occur (for example, BCD codes 1010–1111 on a decimal display) or produce an output that simply does not matter to the design. Mark those cells with an X for don’t-care. The payoff: you may read each X as either 0 or 1, choosing whichever makes a larger group.
Mini-example — a 3-variable function with F = Σm(1, 3) and don’t-cares at m5, m7:
| A \ BC | 00 | 01 | 11 | 10 |
|---|---|---|---|---|
| A = 0 | 0 (m0) | 1 (m1) | 1 (m3) | 0 (m2) |
| A = 1 | 0 (m4) | X (m5) | X (m7) | 0 (m6) |
Without the don’t-cares the only group is m1 + m3 (a pair giving A′·C). But if you treat the two X cells as 1,
the four cells m1, m3, m5, m7 form a clean group of 4: across it A and B both change while C stays 1, so the whole block
collapses to the single literal F = C. The don’t-cares absorbed into the group shrank the
answer from a two-literal term to one literal — that is why don’t-cares are the headline differentiator. Mark cells as X in the
Karnaugh Map Solver to see the larger group form automatically.
When to stop / limits
Be honest about the boundary: K-maps are practical up to about 4 variables. You can push to 5 or 6 variables with stacked or mirrored maps, but tracking adjacency by eye gets error-prone fast. Beyond that, the visual method stops paying off and you switch to the Quine–McCluskey algorithm, which performs the identical minimization as a systematic tabulation instead of a picture — well suited to being done by a program.
For everyday work, lean on the tools. Generate the truth table first with the Logic Gate Truth Table Generator, run it through the Karnaugh Map Solver to get the grouped result, and cross-check the algebra with the Boolean Algebra Simplifier. If you arrived here from a truth table, the sibling guide on turning a truth table into a Boolean expression covers the step before the map.
FAQ
- Why are K-map cells in Gray code order?
- A Karnaugh map only works because physically adjacent cells differ by exactly one variable, and Gray code (00, 01, 11, 10) is the labeling that guarantees this — each step flips just one bit. If you instead labeled the columns in plain binary counting order (00, 01, 10, 11) the jump from 01 to 10 would flip two bits, so neighbouring cells would no longer be true logical neighbours and your groupings would simplify wrongly. That single ordering rule is the whole trick behind the map. The Karnaugh Map Solver lays the grid out in Gray code for you so you never have to second-guess the labels.
- What size can a K-map group be?
- Every group must be a rectangle of all 1s whose size is a power of two: 1, 2, 4, 8 or 16 cells. The rule of thumb is to make each group as large as you legally can, because a bigger group eliminates more variables — a group of 2 drops one variable, a group of 4 drops two, and a group of 8 drops three. You then use as few groups as possible to cover every 1, and groups are allowed to overlap and to wrap around the edges and corners. The Boolean Algebra Simplifier is handy for double-checking that the sum-of-products you read off is actually minimal.
- What is a don’t-care in a K-map?
- A don’t-care, written X, marks an input combination that can never physically occur or whose output simply does not matter for the design. Because the output is unconstrained there, you are free to treat each X as either 0 or 1 — whichever choice lets you build a larger group. In practice you read an X as 1 when it lets a group of 2 grow into a group of 4 (or a 4 into an 8), and as 0 when including it would force an extra group for no benefit. Used well, don’t-cares often shrink the final expression dramatically; the Karnaugh Map Solver lets you mark cells as X and shows the simplification both ways.
- How many variables can a Karnaugh map handle?
- A K-map is practical up to about 4 variables, and you can stretch it to 5 or 6 using stacked or mirrored maps, but the visual adjacency gets hard to track past that. Beyond roughly six variables the map becomes error-prone and people switch to the Quine–McCluskey algorithm, which is the same minimization done as a systematic table rather than a picture. For anything large, feed the truth table into a tool: the Karnaugh Map Solver handles the common cases and the Boolean Algebra Simplifier checks the algebra. Generate the truth table first with the Logic Gate Truth Table Generator if you do not have it yet.