Skip to content
KmapGen

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.

Variables
4-variable Karnaugh map (click cells to edit)ABCD00011110000111100011130204151706112113X151141809011110

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

3 product terms, 6 literals
2 equally minimal answers:

Minimal POS (product of sums)

F = (A + D)(A' + B + D')

2 sum terms, 5 literals
Unique minimal answer.

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––0 essential wraps left–right edges

    A = 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––1 essential

    A = 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–1

    B = 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.

PrimeTermPatternm1m3m5m7m8m10m12m13m14
P1 *A'D0––1⊗⊗××
P2BD–1–1×××
P3 *AD'1––0⊗⊗××
P4AB11––×××

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

1sCellsPattern
110001✓
81000✓
230011✓
50101✓
101010✓
121100✓
370111✓
131101✓
141110✓
4151111✓

Groups of 2

1sCellsPattern
11,300–1✓
1,50–01✓
8,1010–0✓
8,121–00✓
23,70–11✓
5,701–1✓
5,13–101✓
10,141–10✓
12,13110–✓
12,1411–0✓
37,15–111✓
13,1511–1✓
14,15111–✓

Groups of 4

1sCellsPattern
11,3,5,70––1PI
8,10,12,141––0PI
25,7,13,15–1–1PI
12,13,14,1511––PI
5. Truth table, Σm, ΠM and canonical forms
#ABCDF
000000
100011
200100
300111
401000
501011
601100
701111
810001
910010
1010101
1110110
1211001
1311011
1411101
151111X

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).

AA′BDD′F

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.

4-variable K-map: minterm numbers
AB \ CD 00011110
00 m0m1m3m2
01 m4m5m7m6
11 m12m13m15m14
10 m8m9m11m10

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 sizeLiterals leftTypical shapes
14single cell
23horizontal or vertical pair, including edge-wrapping pairs
42row, column, 2×2 square, the four corners, a square split across an edge
81two adjacent rows or columns (rows 00 and 10 count as adjacent)
160F = 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.

Solved 4-variable K-map for Σm(0, 1, 2, 4, 5, 6, 8, 9, 12, 13, 14)ABCD000111100001111010110312141507161121130151141819011010
F = Σm(0, 1, 2, 4, 5, 6, 8, 9, 12, 13, 14) → F = A'D' + BD' + C'
  1. 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.
  2. 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.
  3. 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:

Solved 4-variable K-map for Σm(1, 3, 7, 11, 15) + d(0, 2, 5)ABCD0001111000011110X01113X204X517060120131150140809111010
F = Σm(1, 3, 7, 11, 15) + d(0, 2, 5) → F = A'B' + CD (one of 2 minimal answers)
  1. 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.
  2. 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.

Solved 4-variable K-map for Σm(1, 3, 7, 11, 15) + d(0, 2, 5)ABCD0001111000011110X01113X204X517060120131150140809111010
F = Σm(1, 3, 7, 11, 15) + d(0, 2, 5) → F = A'D + CD (one of 2 minimal answers)
  1. 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.
  2. 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.