4-Variable K-Map Solver
Solve a 4-variable Karnaugh map (AB × CD) with don’t-cares and every minimal answer, then work through the layout, corner groups and two full examples.
Every cell not listed as a maxterm or don't-care is a 1.
Tap an output to cycle 0 → 1 → X.
Operators: ' ! ~ NOT · AB & * · AND · + | OR · ^ ⊕ XOR ·
nand, nor, xnor, ->, <->. Variables are sorted (A, B, C…) unless you write F(C,B,A) = ….
Click or tap a cell to change it. Keyboard: Tab to the map, arrows move, Enter or Space cycles, 0 / 1 / X set the value. Small numbers are minterm numbers.
Minimal SOP (sum of products)
F = AD' + A'D + BD
Minimal POS (product of sums)
F = (A + D)(A' + B + D')
Step-by-step solution
1. Groups on the map (SOP)
The 1s are covered by 3 groups. In each product term, a variable that stays 1 across the group appears as is and one that stays 0 appears complemented. Hover or tap a term to highlight its group.
-
AD' group of 4 · cells 8, 10, 12, 14 · pattern
1––0essential wraps left–right edgesA = 1, D = 0 in every cell; B, C change inside the group and drop out. It is essential: m8, m10 are covered by no other prime implicant.
-
A'D group of 4 · cells 1, 3, 5, 7 · pattern
0––1essentialA = 0, D = 1 in every cell; B, C change inside the group and drop out. It is essential: m1, m3 are covered by no other prime implicant.
-
BD group of 4 · cells 5, 7, 13, 15 · pattern
–1–1B = 1, D = 1 in every cell; A, C change inside the group and drop out.
2. Prime implicants and essential primes
Each row is a prime implicant (a group that cannot be made larger). A ⊗ marks a minterm covered by a single prime: that prime is essential (*) and must be in every minimal answer.
| Prime | Term | Pattern | m1 | m3 | m5 | m7 | m8 | m10 | m12 | m13 | m14 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| P1 * | A'D | 0––1 | ⊗ | ⊗ | × | × | |||||
| P2 | BD | –1–1 | × | × | × | ||||||
| P3 * | AD' | 1––0 | ⊗ | ⊗ | × | × | |||||
| P4 | AB | 11–– | × | × | × |
Essential: P1, P3. Still uncovered after the essentials: m13.
3. Petrick's method: choosing the cheapest cover
Every uncovered minterm needs at least one of the primes that cover it. Petrick's method writes that as a product of sums and looks for its cheapest products:
P = (P2 + P4)
Cheapest choices (fewest terms, then fewest literals): P2, P4. Each choice plus the essential primes is one minimal answer.
4. Quine–McCluskey tabulation
Cells are sorted by their number of 1 bits. Two entries in neighboring groups combine when their patterns differ in exactly one position (that position becomes –). ✓ = combined further; PI = could not be combined, so it is a prime implicant.
Groups of 1
| 1s | Cells | Pattern | |
|---|---|---|---|
| 1 | 1 | 0001 | ✓ |
| 8 | 1000 | ✓ | |
| 2 | 3 | 0011 | ✓ |
| 5 | 0101 | ✓ | |
| 10 | 1010 | ✓ | |
| 12 | 1100 | ✓ | |
| 3 | 7 | 0111 | ✓ |
| 13 | 1101 | ✓ | |
| 14 | 1110 | ✓ | |
| 4 | 15 | 1111 | ✓ |
Groups of 2
| 1s | Cells | Pattern | |
|---|---|---|---|
| 1 | 1,3 | 00–1 | ✓ |
| 1,5 | 0–01 | ✓ | |
| 8,10 | 10–0 | ✓ | |
| 8,12 | 1–00 | ✓ | |
| 2 | 3,7 | 0–11 | ✓ |
| 5,7 | 01–1 | ✓ | |
| 5,13 | –101 | ✓ | |
| 10,14 | 1–10 | ✓ | |
| 12,13 | 110– | ✓ | |
| 12,14 | 11–0 | ✓ | |
| 3 | 7,15 | –111 | ✓ |
| 13,15 | 11–1 | ✓ | |
| 14,15 | 111– | ✓ |
Groups of 4
| 1s | Cells | Pattern | |
|---|---|---|---|
| 1 | 1,3,5,7 | 0––1 | PI |
| 8,10,12,14 | 1––0 | PI | |
| 2 | 5,7,13,15 | –1–1 | PI |
| 12,13,14,15 | 11–– | PI |
5. Truth table, Σm, ΠM and canonical forms
| # | A | B | C | D | F |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | 0 | 0 | 0 | 1 | 1 |
| 2 | 0 | 0 | 1 | 0 | 0 |
| 3 | 0 | 0 | 1 | 1 | 1 |
| 4 | 0 | 1 | 0 | 0 | 0 |
| 5 | 0 | 1 | 0 | 1 | 1 |
| 6 | 0 | 1 | 1 | 0 | 0 |
| 7 | 0 | 1 | 1 | 1 | 1 |
| 8 | 1 | 0 | 0 | 0 | 1 |
| 9 | 1 | 0 | 0 | 1 | 0 |
| 10 | 1 | 0 | 1 | 0 | 1 |
| 11 | 1 | 0 | 1 | 1 | 0 |
| 12 | 1 | 1 | 0 | 0 | 1 |
| 13 | 1 | 1 | 0 | 1 | 1 |
| 14 | 1 | 1 | 1 | 0 | 1 |
| 15 | 1 | 1 | 1 | 1 | X |
Minterm list: F = Σm(1, 3, 5, 7, 8, 10, 12, 13, 14) + d(15)
Maxterm list: F = ΠM(0, 2, 4, 6, 9, 11) · D(15)
Canonical SOP (one term per 1): A'B'C'D + A'B'CD + A'BC'D + A'BCD + AB'C'D' + AB'CD' + ABC'D' + ABC'D + ABCD'
Canonical POS (one clause per 0): (A + B + C + D)(A + B + C' + D)(A + B' + C + D)(A + B' + C' + D)(A' + B + C + D')(A' + B + C' + D')
Row number = minterm number, with A as the most significant bit.
6. Logic circuit (AND–OR)
Two-level AND–OR realization: one AND gate per term (a single-literal term is wired straight through), then one OR gate. 6 gates including inverters, 9 gate inputs. Replacing every AND and the final OR with NAND gates gives the equivalent NAND–NAND circuit with the same wiring (single-literal terms then need their complement).
4-variable K-map layout
Sixteen cells, AB on the rows and CD on the columns, both in Gray-code order. Memorize the pattern of the numbers: the third and fourth rows and columns are swapped compared with counting 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 |
Every cell has exactly four neighbors (up, down, left, right, with wrap-around). For example m0 is adjacent to m1, m2, m4 and m8, and m5 is adjacent to m1, m4, m7 and m13.
| Group size | Literals left | Typical shapes |
|---|---|---|
| 1 | 4 | single cell |
| 2 | 3 | horizontal or vertical pair, including edge-wrapping pairs |
| 4 | 2 | row, column, 2×2 square, the four corners, a square split across an edge |
| 8 | 1 | two adjacent rows or columns (rows 00 and 10 count as adjacent) |
| 16 | 0 | F = 1 |
Worked example: F = Σm(0, 1, 2, 4, 5, 6, 8, 9, 12, 13, 14)
Start with the largest group: the eight cells with C = 0 (columns 00 and 01). The remaining 1s, m2, m6 and m14, sit in column 10. Two quads that wrap from column 10 back to column 00 cover them: m0, m2, m4, m6 (A′D′) takes m2 and m6, and m4, m6, m12, m14 (BD′) takes m14.
- A'D': group of 4 (m0, m2, m4, m6), wrapping left–right edges, essential. A = 0, D = 0 in every cell; B, C change inside the group and drop out.
- BD': group of 4 (m4, m6, m12, m14), wrapping left–right edges, essential. B = 1, D = 0 in every cell; A, C change inside the group and drop out.
- C': group of 8 (m0, m1, m4, m5, m8, m9, m12, m13), essential. C = 0 in every cell; A, B, D change inside the group and drop out.
Result: F = A'D' + BD' + C', 3 terms and 5 literals. Open this example in the solver.
Worked example with don’t-cares
F = Σm(1, 3, 7, 11, 15) + d(0, 2, 5). The column CD = 11 gives CD. The 1s m1 and m3 can join either the don’t-cares m0 and m2 (giving A′B′) or the don’t-care m5 and the 1 m7 (giving A′D), so there are two minimal answers:
- A'B': group of 4 (m0, m1, m2, m3). A = 0, B = 0 in every cell; C, D change inside the group and drop out.
- CD: group of 4 (m3, m7, m11, m15), essential. C = 1, D = 1 in every cell; A, B change inside the group and drop out.
Result: F = A'B' + CD, 2 terms and 4 literals. Open this example in the solver.
- A'D: group of 4 (m1, m3, m5, m7). A = 0, D = 1 in every cell; B, C change inside the group and drop out.
- CD: group of 4 (m3, m7, m11, m15), essential. C = 1, D = 1 in every cell; A, B change inside the group and drop out.
Result: F = A'D + CD, 2 terms and 4 literals. Open this example in the solver.
More on when to use an X in don’t-care conditions.
Frequently asked questions
How do you number the cells of a 4-variable K-map?
Rows are AB and columns are CD, both in the order 00, 01, 11, 10. The cell in row AB and column CD holds minterm number 8A + 4B + 2C + D. The top row reads m0 m1 m3 m2, then m4 m5 m7 m6, m12 m13 m15 m14 and m8 m9 m11 m10.
Which cells are the corners of a 4-variable K-map?
m0, m2, m8 and m10. All four have B = 0 and D = 0, so they form one group of four, B′D′, because the map wraps around both horizontally and vertically.
What is the largest group in a 4-variable K-map?
Sixteen cells (the whole map, F = 1). An 8-cell group (two full rows or two full columns, possibly wrapping) leaves a single literal; a 4-cell group leaves two literals.
Can a 4-variable K-map have more than one minimal answer?
Yes, and it is common with don’t-cares. For example Σm(1, 3, 7, 11, 15) + d(0, 2, 5) has two answers, A′B′ + CD and A′D + CD, both with 2 terms and 4 literals.
Related tools and guides
- 5-variable K-map Solve a 5-variable Karnaugh map. How the two 4×4 maps (A = 0, A = 1) work, which cells are adjacent across them, and a worked example with steps.
- 3-variable K-map Solve a 3-variable Karnaugh map (A, BC) online. Gray-code layout, cell numbers, wrap-around groups and worked examples in SOP and POS.
- K-map grouping rules The rules for grouping cells in a Karnaugh map: powers of two, rectangles, wrap-around edges and corners, overlap, largest groups, fewest groups.
- How to solve a K-map How to solve a Karnaugh map in 6 steps, with worked 3- and 4-variable examples, a cyclic map with two answers, and the mistakes that cost marks.