Karnaugh map solver
Click cells to cycle 0, 1, and X. Read the simplified expressions below the map.
How this tool works
A Karnaugh map is a grid that arranges a logic function's outputs so adjacent 1s can be grouped by eye, giving its simplest sum-of-products form without algebra. Toggle a 2 to 6 variable Karnaugh map by clicking each cell (it cycles 0, 1, then a don't-care X), or type a list of minterms instead. Five and six variables are drawn as two or four maps side by side. The solver returns both the minimized sum-of-products (SOP) and product-of-sums (POS) boolean expressions right away, and it uses any don't-cares to make the groups bigger and each answer shorter.
How to use it
- Pick the number of variables (2 to 6) with the buttons at the top. The variables are named
AtoF, withAthe most significant bit. For 5 variables the map splits into two 4-variable maps (A = 0 and A = 1) and for 6 into four (one per value of A B); the same cell on neighbouring maps counts as adjacent. See 5 and 6 variable K-maps for worked examples. - Click any cell to set its output: each click cycles
0to1toX(don't-care) and back to0. The smallm4style label in each cell is its minterm number. - Prefer typing? Enter the ON minterms (the rows of the truth table that output 1) in the first box, for example
1, 3, 5, 7, and any don't-cares in the second. The grid and the boxes stay in sync, so editing one updates the other. - Read the two results under the map. The sum of products (SOP) box groups the 1s and gives an OR of AND terms; the product of sums (POS) box groups the 0s and gives an AND of OR terms. A trailing prime mark means NOT, so
A'is NOT A, side-by-side letters are an AND,+is an OR, and each bracket in the POS is one OR term.
Worked example
Choose 3 variables and set the four cells where A = 1 to 1.
Those are minterms 4, 5, 6, and 7 (binary 100, 101, 110, 111). On the map they
form one solid block of four, the entire bottom row where the row header reads
1 for A.
Inside that block of four, B takes both values (0 and 1) and C takes both values
(0 and 1), so neither B nor C decides the output. Only A is constant at 1 across
the whole group. A group of four cells removes two variables, and what is left is
the single literal that did not change. So the minimized result is just
F = A: the output is 1 exactly when A is 1, no matter what
B and C do. That four-term truth table collapses to one letter.
How Karnaugh map minimization works
A Karnaugh map is a truth table folded into a grid with one special property: neighbouring cells differ in exactly one input bit. That is why the row and column headers run in Gray-code order (00, 01, 11, 10) rather than plain binary, so a step in any direction flips a single variable.
Because neighbours differ by one bit, a rectangular group of 1s whose size is a power of two (1, 2, 4, 8, ...) always shares a fixed set of variables, while the rest cancel. Each group becomes one product term made only of the variables that stay constant: a variable held at 1 appears as itself, one held at 0 appears primed, and a variable that changes inside the group drops out. The bigger the group, the fewer literals survive.
A group that cannot grow any larger is a prime implicant. Some 1s can only be covered by a single prime implicant, which makes that group essential, so the solver always takes the essential ones first, then searches the remaining choices for the cover with the fewest groups and, among those, the fewest literals. A don't-care can join a group when that helps, but it never has to be covered on its own, which is how a stray X can let a group double in size and shrink the final expression.
Getting the product of sums (POS)
Sum of products is not the only minimal form. The product of sums (POS)
is its mirror image: instead of grouping the 1s, you group the 0s
of the map, using the exact same power-of-two rectangles and the same don't-cares. Each
group of zeros becomes one bracketed OR term, and the brackets are ANDed together.
The one twist is that the literals flip. When you read a group of zeros, a variable that
stays 0 across the group appears uncomplemented and a variable
that stays 1 appears complemented, the opposite of the SOP rule.
That flip is just De Morgan's law: you are grouping the zeros to build the complement, then
complementing it back. For the majority function (output 1 when at least two of A, B, C are
1), the SOP is AB + AC + BC and the POS is
(A + B)(A + C)(B + C). Both describe the same circuit; pick whichever
is smaller, which is usually SOP when the function has few 1s and POS when it has few 0s.
The solver above prints both, minimized, for every map you enter.
Frequently asked
What is a Karnaugh map?
A Karnaugh map is a grid that arranges a truth table so that adjacent cells differ in exactly one input bit. Grouping adjacent 1s in powers of two lets you read off a minimized boolean expression without algebra.
How does this K-map solver minimize?
It finds every prime implicant of the ON-set and don't-cares, then picks the cover with the fewest terms and, among those, the fewest literals, taking the essential prime implicants first. The result is a minimized sum-of-products expression with each group written as a product term.
Can it solve 5 and 6 variable K-maps?
Yes. Choose 5 or 6 variables and the solver draws two or four 4-variable maps side by side, one for each value of A (or of A B). The same cell on neighbouring maps is adjacent, and the solver groups across the maps for you. The 5 and 6 variable K-map guide works through an example of each.
What is a don't-care in a Karnaugh map?
A don't-care, often written X, is an input combination whose output never matters. The solver is free to treat each one as 0 or 1, whichever makes the groups larger and the final expression simpler.
How do you find the product of sums (POS) from a Karnaugh map?
Group the zeros of the map instead of the ones, the same way (rectangles sized to a power of two, using don't-cares if they help), read each group as a product term, then complement it. By De Morgan's law a variable that is 0 across the group appears uncomplemented and one that is 1 appears complemented, the terms are ORed inside each bracket and ANDed together. This solver shows the minimized POS next to the SOP for every map.
What is the difference between SOP and POS from a K-map?
Sum of products (SOP) groups the 1s and gives an OR of AND terms, like A B + A' C. Product of sums (POS) groups the 0s and gives an AND of OR terms, like (A + B)(A' + C). Both describe the same function; SOP is usually simpler when the function has few 1s, POS when it has few 0s. The solver computes both so you can pick the smaller one.
How do I solve a 4 variable K-map?
Fill the 16 cells with the function's outputs, with rows and columns in Gray code order (00, 01, 11, 10). Circle the largest groups of 1s whose sizes are powers of two (16, 8, 4, 2, 1), wrapping around the edges, until every 1 is covered. Each group becomes one product term: keep the variables that do not change inside it. The solver does this for you and shows the minimal SOP and POS.
Can it solve K-maps with 7 or 8 variables?
No, it stops at 6, because maps with more variables are hard to read and are rarely drawn by hand. For up to 8 variables, the Boolean algebra calculator minimizes the expression directly with the Quine-McCluskey method.
Once you have the minimized expression, build it for real: open the lab and wire the gates from transistors, or read the theory on Karnaugh maps and boolean algebra.
Related tools: truth table generator boolean simplifier, logic circuit generator and truth table to expression converter (up to 6 variables).
Open the lab →