Karnaugh map solver
Simplify a Boolean function with a Karnaugh map. Click the cells or type the minterms and don't cares, and the solver draws the groups, gives the simplest SOP or POS and explains each step. You can also check an answer you worked out yourself.
Click a cell to switch it between 0, 1 and X (don't care).
How the solver got this answer
Truth table
Runs in your browser. Nothing you type is uploaded.
How to use the K-map solver
- Pick the number of variables, from 2 to 5. The map redraws with the rows and columns already in the right order.
- Fill the map. Click a cell to switch it between 0, 1 and X (don't care), or type the minterm numbers, for example 0, 2, 5, 7, and press Enter. You can also load a Boolean expression such as
A'B + BCDor edit the truth table under the tool. - Read the answer. The simplest expression appears at the top, each group is drawn on the map in its own color, and hovering over a term highlights its cells. Switch "Simplify to" between SOP and POS to get the other form.
- Check your own work. Type the answer you worked out on paper into "Check your answer". The tool tells you if it matches the map and, if it does not, outlines the first cell where it goes wrong. Tick practice mode to hide the solver's answer until you are ready.
"How the solver got this answer" lists every prime implicant, marks the essential ones and explains which groups were picked to cover the rest. The same answer is also written as Python, C and Verilog so you can paste it into code.
What a Karnaugh map is
A Karnaugh map, or K-map, is a truth table redrawn as a grid so that you can see which outputs can be combined. Take this function of three inputs:
| Cell | A | B | C | F |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 1 |
| 1 | 0 | 0 | 1 | 0 |
| 2 | 0 | 1 | 0 | 1 |
| 3 | 0 | 1 | 1 | 1 |
| 4 | 1 | 0 | 0 | 0 |
| 5 | 1 | 0 | 1 | 0 |
| 6 | 1 | 1 | 0 | 1 |
| 7 | 1 | 1 | 1 | 1 |
Written as a list, the output is 1 for minterms 0, 2, 3, 6 and 7, often shortened to F = Σm(0, 2, 3, 6, 7). Each row of the truth table becomes one cell of the map. A goes down the side, B and C go across the top:
| A \ BC | 00 | 01 | 11 | 10 |
|---|---|---|---|---|
| 0 | 10 | 01 | 13 | 12 |
| 1 | 04 | 05 | 17 | 16 |
The small number in each cell is its row in the truth table. Notice that the columns run 00, 01, 11, 10 and not in counting order. That order is the whole trick, and the next section explains it.
Why the rows and columns go 00, 01, 11, 10
Going across the top, only one bit changes between neighboring columns: 00 to 01 changes C, 01 to 11 changes B, 11 to 10 changes C again. This is Gray code order, and it means any two cells that touch differ in exactly one input.
When two touching cells are both 1, the input that changes between them cannot matter. Cells 2 (A=0, B=1, C=0) and 3 (A=0, B=1, C=1) are both 1, so the output is 1 whenever A is 0 and B is 1, whatever C is. That is the Boolean algebra step A'BC' + A'BC = A'B, done by eye instead of on paper.
The order also wraps around. The last column, 10, differs from the first, 00, in one bit, so the left and right edges count as touching, and so do the top and bottom. In a 4-variable map that makes the four corners a valid group of four, because each corner touches the two corners beside it through the wraparound.
Rules for grouping cells
- Group only 1s (or 0s for a product of sums). Don't care cells marked X may join a group if they make it bigger.
- A group must hold 1, 2, 4, 8 or 16 cells, a power of two, and be a rectangle. Three cells in an L shape is not a group.
- Groups may wrap around the edges and the corners, because those cells are neighbors in Gray code order.
- Make every group as large as possible. A group of 4 drops two variables, a group of 2 drops one.
- Use as few groups as possible, but every 1 has to be in at least one group. Groups may overlap.
- Read each group by keeping only the variables that do not change inside it. A variable that is 1 throughout is written plain, one that is 0 throughout gets a prime, as in
B'.
Worked example: a 3-variable K-map
Back to F = Σm(0, 2, 3, 6, 7). Two groups cover every 1:
| A \ BC | 00 | 01 | 11 | 10 |
|---|---|---|---|---|
| 0 | 10 | 01 | 13 | 12 |
| 1 | 04 | 05 | 17 | 16 |
BA'C'
- The block of four in the two right-hand columns, cells 2, 3, 6 and 7. A changes inside it and so does C, but B is 1 in all four cells, so the group reads
B. - The pair in the top row that wraps around the edge, cells 0 and 2. A is 0 and C is 0 in both, while B changes, so it reads
A'C'.
The answer is F = B + A'C': one OR gate, one AND gate and two inverters, instead of the five three-input AND terms in the truth table. Type B + A'C' into "Check your answer" above with this map loaded and the tool confirms it, and the Boolean algebra simplifier reaches the same answer with each law written out.
Worked example: a 4-variable K-map with corners
F = Σm(0, 2, 5, 7, 8, 10, 13, 15) is the example loaded when the page opens. It looks scattered, but two groups of four cover it:
| AB \ CD | 00 | 01 | 11 | 10 |
|---|---|---|---|---|
| 00 | 10 | 01 | 03 | 12 |
| 01 | 04 | 15 | 17 | 06 |
| 11 | 012 | 113 | 115 | 014 |
| 10 | 18 | 09 | 011 | 110 |
B'D'BD
- The four corners, cells 0, 2, 8 and 10. They touch each other through the wraparound. B and D are 0 in all four, so the group is
B'D'. - The square in the middle, cells 5, 7, 13 and 15, where B and D are both 1:
BD.
So F = B'D' + BD. That is 1 exactly when B and D are equal, which is B XNOR D, the inverse of what the XOR calculator gives for those two bits. Missing the corner group is the most common way to get this map wrong.
Don't care conditions
Some input combinations never happen, such as the unused states of a counter built from flip-flops. A circuit that reads a decimal digit in binary-coded decimal never sees inputs 10 to 15, so you do not care what it outputs for them. Those cells get an X, and you can treat each X as 1 or 0, whichever makes the groups bigger.
Here F = Σm(1, 3, 7, 11, 15) with don't cares at 0, 2 and 5:
| AB \ CD | 00 | 01 | 11 | 10 |
|---|---|---|---|---|
| 00 | X0 | 11 | 13 | X2 |
| 01 | 04 | X5 | 17 | 06 |
| 11 | 012 | 013 | 115 | 014 |
| 10 | 08 | 09 | 111 | 010 |
A'DCD
Counting cell 5 as a 1 lets cells 1, 3, 5 and 7 form a group of four, A'D, alongside the group CD (cells 3, 7, 11 and 15). The result is F = A'D + CD. Without the don't cares the best you can do is CD + A'B'D, which needs one more literal. Cells 0 and 2 give a second option: counted as 1s, they let cells 0 to 3 form the group A'B', so F = A'B' + CD is just as short. Both answers are correct, and the solver shows A'D + CD.
Product of sums (POS)
A sum of products, like B + A'C', ORs together AND terms. A product of sums does the reverse: it ANDs together OR terms. To get it from a K-map, group the 0s instead of the 1s, then write each group with every variable inverted.
| A \ BC | 00 | 01 | 11 | 10 |
|---|---|---|---|---|
| 0 | 10 | 01 | 13 | 12 |
| 1 | 04 | 05 | 17 | 16 |
(B + C')(A' + B)
The 0s of our 3-variable function are cells 1, 4 and 5. Cells 1 and 5 give (B + C'), because B is 0 and C is 1 in both, and inverting each gives B and C'. Cells 4 and 5 give (A' + B). So F = (B + C')(A' + B), the same function as B + A'C', written the other way. The swap from 0s to inverted variables is De Morgan's law applied to each group. POS is the better choice when the map has fewer 0s than 1s, or when the circuit will be built from NOR gates.
5-variable K-maps
A flat grid stops working after four variables, because each cell can only have four neighbors on paper. The usual fix is two 4-variable maps side by side, one for A = 0 and one for A = 1. A cell in one map is also a neighbor of the cell in the same position in the other map.
| BC \ DE | 00 | 01 | 11 | 10 |
|---|---|---|---|---|
| 00 | 10 | 01 | 03 | 12 |
| 01 | 04 | 15 | 17 | 06 |
| 11 | 012 | 013 | 015 | 014 |
| 10 | 18 | 09 | 011 | 110 |
| BC \ DE | 00 | 01 | 11 | 10 |
|---|---|---|---|---|
| 00 | 116 | 017 | 019 | 118 |
| 01 | 020 | 121 | 123 | 022 |
| 11 | 028 | 029 | 031 | 030 |
| 10 | 124 | 025 | 027 | 126 |
C'E'B'CE
The corners of both maps form one group of eight, C'E', because the corners touch inside each map and the two maps touch each other. Cells 5, 7, 21 and 23 sit in the same place in both maps and give B'CE. The answer is F = C'E' + B'CE. Select 5 variables in the solver to work with two maps the same way. Past five variables, people switch to software.
Prime implicants and essential prime implicants
A prime implicant is a group that cannot be made any bigger. An essential prime implicant is one that is the only way to cover at least one cell, so it has to be in the answer. The solver's "How the solver got this answer" box shows both lists for whatever map you enter.
Take F = Σm(1, 3, 4, 5, 6). It has four prime implicants: A'C, B'C, AB' and AC'. Cell 3 is covered only by A'C and cell 6 only by AC', so both are essential. That leaves cell 5, which B'C and AB' both cover. Either one gives a correct and equally short answer:
F = A'C + AC' + B'CF = A'C + AC' + AB'
So a K-map can have more than one right answer. If your answer differs from the solver's, check it with "Check your answer" before assuming it is wrong. Some maps have no essential prime implicants at all. F = Σm(0, 1, 5, 7, 8, 10, 14, 15) has 8 prime implicants and every cell is covered by at least two of them, so you have to try combinations. The solver does that for you and picks the smallest set.
When a K-map cannot simplify anything
Some functions have no two neighboring 1s. The 3-input odd-parity function, 1 when an odd number of inputs are 1, puts its 1s in a checkerboard:
| A \ BC | 00 | 01 | 11 | 10 |
|---|---|---|---|---|
| 0 | 00 | 11 | 03 | 12 |
| 1 | 14 | 05 | 17 | 06 |
A'B'CA'BC'AB'C'ABC
Each 1 sits alone, so the sum of products keeps all four full terms: A'B'C + A'BC' + AB'C' + ABC. That is not a failure of the method. The function is A XOR B XOR C, and XOR does not shrink into ANDs and ORs. It is exactly the sum bit of a full adder, which is why adders are built from XOR gates rather than from a simplified AND-OR circuit.
K-map, Boolean algebra or Quine-McCluskey?
| Method | Best for | Weak spot |
|---|---|---|
| K-map | 2 to 4 variables, 5 with care. Fast, and you can see the answer. | Hard to draw past 5 variables, and a wraparound group is often missed. |
| Boolean algebra | Proving two expressions are equal, short expressions, any number of variables. | No clear order of steps, so you can miss the simplest form. |
| Quine-McCluskey | Computers and medium-sized functions. It is the table method this solver runs. | Too slow to do by hand beyond a few variables. |
The Quine-McCluskey method, worked out by Willard Quine and Edward McCluskey in the 1950s, does the same thing as a K-map with lists instead of pictures: it merges minterms that differ in one bit until no more merges are possible, then picks the fewest prime implicants that cover everything.
Common mistakes
- You group three cells in a row. Groups must be 1, 2, 4, 8 or 16 cells. Split it into two overlapping pairs, or find a group of four that includes the third cell.
- You write the columns as 00, 01, 10, 11. In counting order 01 and 10 differ in two bits, so groups across that border come out wrong. Always use 00, 01, 11, 10.
- You miss the corners or the edges. On a 4-variable map, check the four corners and the left and right edges before you finish.
- You make small groups when a bigger one fits. Two pairs that together form a square should be one group of four, with one fewer variable.
- You read a group with the wrong prime. For SOP, a variable that is 0 throughout the group is written with a prime. For POS it is the other way around.
- You add a group that is already covered. If every cell in a group is also in some other group, leave it out.
Where the Karnaugh map came from
Edward Veitch described a chart for simplifying truth functions in 1952. Maurice Karnaugh, then at Bell Labs, reworked it into the map with Gray code order in his 1953 paper "The Map Method for Synthesis of Combinational Logic Circuits", according to his biography. Today it is mostly a teaching tool and a quick check for small logic, while design software minimizes the large circuits.
Questions people ask
What is a K-map used for?
To simplify a Boolean expression, so a logic circuit needs fewer gates. You enter the truth table as a grid, group neighboring 1s, and read off the shortest sum of products or product of sums.
How do you solve a 4-variable K-map?
Put AB down the side and CD across the top, both in the order 00, 01, 11, 10. Fill in the 16 outputs, circle the largest groups of 1, 2, 4, 8 or 16 cells, including groups that wrap around edges and corners, and write one term per group using only the variables that stay the same inside it.
Can a K-map group have 3 or 6 cells?
No. A group must be a rectangle of 1, 2, 4, 8 or 16 cells. Each doubling removes one variable, which is why only powers of two work.
What is a don't care in a K-map?
An input combination that never happens or whose output does not matter. It is marked X, and you may count it as 1 when it makes a group bigger, or ignore it.
What is the difference between SOP and POS?
Sum of products ORs together AND terms, such as B + A'C', and comes from grouping the 1s. Product of sums ANDs together OR terms, such as (B + C')(A' + B), and comes from grouping the 0s. Both describe the same function.
How many variables can a K-map handle?
Comfortably 4, and 5 with two side-by-side maps. Six variables need four maps and are hard to read, so beyond that the Quine-McCluskey method or a program is used. This solver handles 2 to 5.
Is there only one correct answer?
No. When two prime implicants can cover the same leftover cell, both answers are equally simple. A'C + AC' + B'C and A'C + AC' + AB' are both correct for Σm(1, 3, 4, 5, 6).
Who invented the Karnaugh map?
Maurice Karnaugh at Bell Labs, in 1953. He built on a chart Edward Veitch had published the year before, which is why it is sometimes called a Veitch diagram or KV map.

