Karnaugh Map Solver
Fill in a Karnaugh map for 2 to 5 variables by clicking its cells, or type the minterms, the don't-cares or a Boolean expression. The solver finds the minimal sum of products and product of sums, draws the groups on the map and lists every minimal solution.
Karnaugh map
Click or tap a cell to step it through 0 → 1 → X (don't care). With a keyboard: the arrow keys move between cells, Space or Enter steps the value, and 0, 1 or X sets it. The small number in a cell is its minterm number; the coloured numbers are the groups it belongs to.
Groups on the map
| Group | Term | Cells covered |
|---|
Enter the function as text
Numbers are separated by commas or spaces. In an expression, letters
written together are ANDed, an apostrophe is NOT and + is OR: A'B + AC.
Symbols and words work too: !A & B | C, A xor B,
not A and B. An expression sets the number of variables and their names;
with the letters A to E, the last letter used decides the size of the map.
Truth table
Row and cell numbers read the variables as a binary number with the first variable as the most significant bit. Everything is calculated in your browser; the map is saved only on this device, so it is still here when you come back, and nothing is sent to a server.
How to use the Karnaugh map solver
- Choose the number of variables, 2 to 5. Rows and columns are in Gray-code order (00, 01, 11, 10), and every cell shows its minterm number.
- Click or tap a cell to step it through 0, 1 and X (don't care), or use the arrow keys with Space, Enter, 0, 1 or X.
- Or type the function: lists of minterms and don't-cares, or a
Boolean expression such as
A'B + AC. Whatever you edit last updates the other two. - Read the minimal SOP and the minimal POS under the map, with their numbers of terms and literals. Step through several minimal solutions with Previous and Next.
- Pick which groups the map shows: the 1s (SOP) or the 0s (POS). The table below lists every numbered group with its term, its cells and whether it is essential.
- Copy result copies the answer; the truth table shows every row.
How it works
A Karnaugh map (K-map) is a truth table folded into a grid. Each cell is one row of the table – one minterm – and its number is the binary value of the variables, with the first variable as the most significant bit: for A, B, C, D the combination 1010 is cell 10. Rows and columns follow Gray code, so a step to a neighbouring cell changes exactly one variable – even across the edges: the left column is next to the right one, the top row next to the bottom one.
Because neighbours differ in one variable, two adjacent 1s merge into a shorter term:
A'B'C'D + A'BC'D = A'C'D, since B takes both values and drops out. The same
works for every rectangular block of 2, 4, 8 or 16 cells:
literals in the term = n − k
where n is the number of variables and the block has 2^k cells.
A literal is a variable or its complement, written with an apostrophe.
A block that cannot be doubled is a prime implicant. It is essential when it holds a 1 that no other prime implicant covers; it then belongs to every minimal solution. The solver finds all prime implicants with the Quine–McCluskey method, takes the essential ones and searches every way of covering the remaining 1s. The winner has the fewest terms and, among those, the fewest literals; all equally good solutions are listed (up to 200).
The SOP (sum of products) groups the 1s: each group is an AND term and
the terms are ORed. The POS (product of sums) groups the 0s: each group
gives an OR term with every variable inverted – 0s where A = 1 and B = 1 become
(A' + B') – and the terms are ANDed. A don't-care (X) is
an input combination whose output does not matter; it may join a group but never has to
be covered. With five variables there are two 4×4 maps, for the first variable equal to
0 and to 1; cells in the same position of both maps are adjacent, so a group can span
both.
Examples
Example 1 – four variables.
F(A,B,C,D) = Σm(0, 1, 2, 5, 8, 9, 10). The four corners 0, 2, 8, 10 form one
group, B'D'. Cells 0, 1, 8, 9 wrap from the top row to the bottom row:
B'C'. Cell 5 can only pair with cell 1: A'C'D. All three groups
are essential, so the only minimal SOP is A'C'D + B'C' + B'D' (3 terms,
7 literals). Grouping the 0s gives the POS (A' + B')(B' + D)(C' + D')
(3 terms, 6 literals).
Example 2 – don't-cares and two solutions.
Σm(1, 3, 7, 11, 15) with d(0, 2, 5). The column 3, 7, 15, 11 is
the essential group CD. The remaining cell 1 fits into two groups of four:
the top row 0, 1, 3, 2 (with the X cells 0 and 2) or the square 1, 3, 5, 7 (with the X
cell 5). The solver reports 2 minimal solutions, A'B' + CD and
A'D + CD, each with 2 terms and 4 literals.
Example 3 – three variables. F(A,B,C) = Σm(3, 4, 6, 7)
gives AC' + BC, and the POS is (A + C)(B + C'). The pair 6, 7
(AB) is a prime implicant too, but both its cells are already covered, so it
is left out.
Example 4 – five variables.
Σm(0, 2, 4, 6, 9, 13, 21, 23, 25, 29, 31) gives
ACE + A'B'E' + BD'E (3 terms, 9 literals). The group BD'E
(cells 9, 13, 25, 29) spans both maps.
Rules for grouping cells
- A group is a rectangle of 1, 2, 4, 8, 16 or 32 cells – always a power of two.
- Groups may wrap around the edges; the four corners form one group of four.
- Make every group as large as possible, then use as few groups as possible.
- Groups may overlap; every 1 needs a group, and no group may contain a 0.
- Diagonal neighbours are not adjacent: the 1s of
AB' + A'B(XOR) cannot be grouped. - For a POS, apply the same rules to the 0s.
Common mistakes
- Binary order instead of Gray code. Columns labelled 00, 01, 10, 11 break adjacency.
- Missing the wrap-around. Two pairs at opposite edges are often one group of four.
- Redundant groups. A group whose cells are all covered by other groups adds a term without changing the function (Example 3).
- Covering every X. Use a don't-care only when it enlarges a group.
- Reading a POS group like an SOP group. A block of 0s with C = 1 and
D = 1 is
(C' + D'), not(C + D).
SOP or POS: which one to use
Without don't-cares both forms describe the same function, so choose the cheaper one by the term and literal counts. An SOP maps onto AND gates feeding an OR gate, or onto NAND gates only; a POS maps onto OR gates feeding an AND gate, or onto NOR gates only. A function with few 1s usually has the shorter SOP, one with few 0s the shorter POS. With don't-cares the two forms may differ in the X cells; both are correct.
Frequently asked questions
What is a Karnaugh map used for?
It simplifies a Boolean function by hand. Shorter terms mean fewer logic gates and gate inputs in a circuit.
Why are the columns ordered 00, 01, 11, 10?
That is Gray code: consecutive labels differ in one bit, so neighbouring cells differ in a single variable and can merge.
Why does the solver show several minimal solutions?
Sometimes a 1 can be covered by different groups of the same size. Such covers have equal numbers of terms and literals, so any of them will do.
Can I use more than five variables?
Not on this map: six variables already need four 4×4 maps. For larger functions use the Boolean Algebra Simplifier, which runs the same minimisation for up to 8 variables.
Is my data sent anywhere?
No. The map is solved in your browser and kept only in this browser's local storage, so it is still there on your next visit. Nothing is uploaded.
Related tools
- Boolean Algebra Simplifier — minimal SOP and POS with the Quine–McCluskey steps.
- Truth Table Generator — the truth table of any logical expression.
- Two's Complement Calculator — signed binary numbers bit by bit.
- Subnet Calculator — network masks in binary.
- Resistor Color Code Calculator — resistor values for your circuit.