K-Map Solver
Karnaugh map calculator for 2 to 6 variables. Click cells or type minterms, maxterms, a truth table or an expression, mark don’t-cares, and get every minimal SOP and POS answer with its groups drawn on the map and each step explained.
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 = A'C + BD + B'C
Minimal POS (product of sums)
F = (A' + B' + D)(B + C)(C + 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.
-
A'C group of 4 · cells 2, 3, 6, 7 · pattern
0–1–essentialA = 0, C = 1 in every cell; B, D change inside the group and drop out. It is essential: m6 is covered by no other prime implicant.
-
BD group of 4 · cells 5, 7, 13, 15 · pattern
–1–1essentialB = 1, D = 1 in every cell; A, C change inside the group and drop out. It is essential: m5 is covered by no other prime implicant.
-
B'C group of 4 · cells 2, 3, 10, 11 · pattern
–01–wraps top–bottom edgesB = 0, C = 1 in every cell; A, D 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 | m2 | m3 | m5 | m6 | m7 | m10 | m11 | m13 | m15 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| P1 * | A'C | 0–1– | × | × | ⊗ | × | |||||
| P2 | B'C | –01– | × | × | × | × | |||||
| P3 | CD | ––11 | × | × | × | × | |||||
| P4 * | BD | –1–1 | ⊗ | × | × | × | |||||
| P5 | AB' | 10–– | × | × | |||||||
| P6 | AD | 1––1 | × | × | × |
Essential: P1, P4. Still uncovered after the essentials: m10, m11.
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 + P5)(P2 + P3 + P5 + P6)
Cheapest choices (fewest terms, then fewest literals): P2, P5. 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 | 2 | 0010 | ✓ |
| 8 | 1000 | ✓ | |
| 2 | 3 | 0011 | ✓ |
| 5 | 0101 | ✓ | |
| 6 | 0110 | ✓ | |
| 9 | 1001 | ✓ | |
| 10 | 1010 | ✓ | |
| 3 | 7 | 0111 | ✓ |
| 11 | 1011 | ✓ | |
| 13 | 1101 | ✓ | |
| 4 | 15 | 1111 | ✓ |
Groups of 2
| 1s | Cells | Pattern | |
|---|---|---|---|
| 1 | 2,3 | 001– | ✓ |
| 2,6 | 0–10 | ✓ | |
| 2,10 | –010 | ✓ | |
| 8,9 | 100– | ✓ | |
| 8,10 | 10–0 | ✓ | |
| 2 | 3,7 | 0–11 | ✓ |
| 3,11 | –011 | ✓ | |
| 5,7 | 01–1 | ✓ | |
| 5,13 | –101 | ✓ | |
| 6,7 | 011– | ✓ | |
| 9,11 | 10–1 | ✓ | |
| 9,13 | 1–01 | ✓ | |
| 10,11 | 101– | ✓ | |
| 3 | 7,15 | –111 | ✓ |
| 11,15 | 1–11 | ✓ | |
| 13,15 | 11–1 | ✓ |
Groups of 4
| 1s | Cells | Pattern | |
|---|---|---|---|
| 1 | 2,3,6,7 | 0–1– | PI |
| 2,3,10,11 | –01– | PI | |
| 8,9,10,11 | 10–– | PI | |
| 2 | 3,7,11,15 | ––11 | PI |
| 5,7,13,15 | –1–1 | PI | |
| 9,11,13,15 | 1––1 | 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 | 0 |
| 2 | 0 | 0 | 1 | 0 | 1 |
| 3 | 0 | 0 | 1 | 1 | 1 |
| 4 | 0 | 1 | 0 | 0 | 0 |
| 5 | 0 | 1 | 0 | 1 | 1 |
| 6 | 0 | 1 | 1 | 0 | 1 |
| 7 | 0 | 1 | 1 | 1 | 1 |
| 8 | 1 | 0 | 0 | 0 | X |
| 9 | 1 | 0 | 0 | 1 | X |
| 10 | 1 | 0 | 1 | 0 | 1 |
| 11 | 1 | 0 | 1 | 1 | 1 |
| 12 | 1 | 1 | 0 | 0 | 0 |
| 13 | 1 | 1 | 0 | 1 | 1 |
| 14 | 1 | 1 | 1 | 0 | 0 |
| 15 | 1 | 1 | 1 | 1 | 1 |
Minterm list: F = Σm(2, 3, 5, 6, 7, 10, 11, 13, 15) + d(8, 9)
Maxterm list: F = ΠM(0, 1, 4, 12, 14) · D(8, 9)
Canonical SOP (one term per 1): A'B'CD' + A'B'CD + A'BC'D + A'BCD' + A'BCD + AB'CD' + AB'CD + 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)
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).
What is a K-map?
A Karnaugh map (K-map) is a grid version of a truth table, introduced by Maurice Karnaugh at Bell Labs in 1953, in which neighboring cells differ in exactly one input variable. Circling rectangular blocks of 1s whose size is a power of two reveals which variables can be dropped, so a Boolean function can be simplified by eye into a minimal sum of products (or, grouping the 0s, a minimal product of sums).
How to use the K-map solver
- Pick the number of variables (2–6). Rename them if your course uses other letters, such as
x y z. - Enter the function in whichever form you have: click the map cells, type the minterm list (
Σm) or the maxterm list (ΠM), fill the truth table, or type a Boolean expression. Every input accepts don’t-cares. - Read the minimal SOP and POS. When several answers are equally short, each one has a number button; the map redraws its groups.
- Open the steps to see why each group was chosen, which prime implicants are essential, and the Quine–McCluskey table behind the answer.
- Copy the result as plain text, LaTeX or C/Verilog operators, download the map as SVG or PNG, or copy a link that reopens the same map.
Why the answers are guaranteed minimal
Grouping by eye works on small maps but can stop at a cover that is correct yet one term too long. Online solvers do it too: when we gave seven solvers from Google’s first page the 4-variable function Σm(0, 1, 2, 5, 6, 7) on November 22, 2026, two returned four terms and one returned six, although three are enough, and none of the others mentioned that a second three-term answer exists.
KmapGen does not guess. It lists every prime implicant with the Quine–McCluskey method, takes the essential ones, then solves the rest of the chart exactly with Petrick’s method, keeping every cover that ties for the lowest cost (fewest terms, then fewest literals). The code is tested against an independent brute-force search over all prime covers on thousands of random functions of 2 to 4 variables and dozens of 5- and 6-variable ones, and every answer is checked against the truth table.
How a Karnaugh map works
A K-map is the truth table folded into a grid. For four variables, the rows are labeled by AB and the columns by CD, both in the order 00, 01, 11, 10. Because that order is a Gray code, two cells that share a side always differ in exactly one variable, and so do the cells at opposite ends of a row or column: the map wraps around like a torus.
When two adjacent cells are both 1, the variable that differs between them does not matter, so the two minterms merge into one shorter term (AB’CD + AB’CD’ = AB’C). A block of 4 cells drops two variables, a block of 8 drops three. Solving the map means covering all the 1s with the fewest and largest such blocks.
K-maps for 2 to 6 variables
| Variables | Cells | Layout | Largest group | Guide |
|---|---|---|---|---|
| 2 | 4 | 2×2 (A rows, B columns) | 4 cells = constant 1 | 2-variable K-map |
| 3 | 8 | 2×4 (A rows, BC columns) | 8 | 3-variable K-map |
| 4 | 16 | 4×4 (AB rows, CD columns) | 16 | 4-variable K-map |
| 5 | 32 | two 4×4 maps, A = 0 and A = 1 | 32 | 5-variable K-map |
| 6 | 64 | four 4×4 maps, AB = 00, 01, 11, 10 | 64 | 6-variable K-map |
Input formats the solver accepts
- Minterms:
0, 2, 5-7(ranges allowed).Σm(…)is accepted too. - Maxterms: the rows where F = 0; everything else becomes 1 unless it is a don’t-care.
- Expressions:
A'B + AC',!a & b | c,(x + y)(x' + z),A xor B,p -> q. A header such asF(C,B,A) =sets the variable order. - Numbering: the first variable is the most significant bit, so with A, B, C, D the cell ABCD = 1001 is m9.
Frequently asked questions
What is a K-map?
A Karnaugh map (K-map) is a grid that holds a Boolean function’s truth table, one cell per input combination. The rows and columns are labeled in Gray code (00, 01, 11, 10), so neighboring cells differ in exactly one variable. Circling rectangles of 1s whose size is a power of two shows, by eye, which variables can be dropped, giving a simplified sum of products.
How do I solve a K-map?
Fill the map from the truth table or minterm list, then circle the largest possible groups of 1s (1, 2, 4, 8… cells, rectangular, wrapping around the edges), using as few groups as possible and making sure every 1 is in at least one group. Each group becomes one product term: keep the variables that stay constant across the group and drop the ones that change. The step-by-step guide walks through full examples.
Why is 11 written before 10 in a K-map?
Because the labels follow the Gray code. Going from 01 to 11 changes one bit, and from 11 to 10 changes one bit; going from 01 to 10 would change two. With Gray-code order, any two cells that touch (including across the outer edges) differ in a single variable, which is what makes grouping work.
Can a K-map have more than one correct answer?
Yes. Some functions have two or more different minimal expressions with the same number of terms and literals. The classic case is a “cyclic” map where no group is essential, such as Σm(0, 1, 2, 5, 6, 7) with three variables. This solver lists every minimal answer and lets you draw each one.
What does X (don’t care) mean in a K-map?
An X marks an input combination that never occurs or whose output does not matter. You may treat each X as a 1 when it makes a group larger and as a 0 otherwise; you never have to cover an X. See don’t-care conditions.
How many variables can a K-map have?
Maps are practical up to six variables: 2 variables use a 2×2 grid, 3 use 2×4, 4 use 4×4, 5 use two 4×4 maps and 6 use four. Beyond that, adjacency across many maps becomes hard to see, so the Quine–McCluskey method (which this solver runs underneath) is used instead.
Is a K-map easy to learn?
For up to four variables, yes: most students can solve a 4-variable map reliably after a few practice problems. The usual mistakes are forgetting that the edges wrap around, using a group of 3 or 6 cells, and stopping at a cover that is valid but not minimal. Checking your answers against a solver that proves minimality is the fastest way to catch them.
What is the difference between SOP and POS answers?
SOP (sum of products) groups the 1s and ORs together AND terms, like AB + C’D. POS (product of sums) groups the 0s and ANDs together OR clauses, like (A + B)(C’ + D). Both describe the same function; one can be shorter than the other, so the solver shows both. More in minterms, maxterms, SOP and POS.
Sources
- M. Karnaugh, “The Map Method for Synthesis of Combinational Logic Circuits,” Transactions of the AIEE, Part I, 72(5):593–599, 1953.
- W. V. Quine, “The Problem of Simplifying Truth Functions,” The American Mathematical Monthly, 59(8):521–531, 1952.
- E. J. McCluskey, “Minimization of Boolean Functions,” Bell System Technical Journal, 35(6):1417–1444, 1956.
- S. R. Petrick, “A Direct Determination of the Irredundant Forms of a Boolean Function from the Set of Prime Implicants,” Air Force Cambridge Research Center, Technical Report AFCRC-TR-56-110, 1956.
Related tools and guides
- 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.
- 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.
- Truth table generator Generate the truth table of any Boolean expression (AND, OR, NOT, XOR, NAND, NOR, →, ↔) with step columns, minterms, SOP/POS and CSV or LaTeX export.
- Boolean simplifier Simplify a Boolean expression step by step: De Morgan, distributive, absorption, consensus and more, ending on a proven minimal SOP, plus the minimal POS.
- Quine–McCluskey method The Quine–McCluskey tabular method explained with a full worked example: grouping by ones, combining, prime implicant chart and Petrick's method.
- 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.