Karnaugh Map Solver
Enter minterms and optional don't-care terms for 2 to 5 variables and get the Karnaugh map in Gray-code order, the groups, and the minimal sum-of-products and product-of-sums expressions.
How it works
Cells in Gray-code order (00, 01, 11, 10) so neighbours differ in one variable · group 1s (and Xs) in rectangles of 1, 2, 4, 8 or 16 cells, wrapping around the edges · each group → one product term keeping only the variables that are constant in it · minimal SOP = fewest, largest groups covering every 1 · POS: group the 0s and write sum terms
A Karnaugh map arranges a truth table so that physically adjacent cells differ in exactly one variable, which turns the algebraic rule XY + XY' = X into drawing rectangles. This solver lays out the map in Gray-code order (rows = first variables, columns = the rest; for five variables the eight columns use a reflected Gray code) and finds the groups exactly with the Quine–McCluskey method, so it never misses a wrap-around or overlapping group. Don't-care cells (X) are used only when they make a group bigger.
Worked example
Four variables with minterms 0, 2, 5, 7, 8, 10, 13, 15: the four corners (0, 2, 8, 10) form one group where B = 0 and D = 0 → B'D', and the centre square (5, 7, 13, 15) where B = 1 and D = 1 → BD. The minimal SOP is B'D' + BD (4 literals) — an XNOR of B and D — and grouping the zeros gives the POS (B + D')(B' + D).
Sources: Karnaugh map — Wikipedia · M. Karnaugh, “The map method for synthesis of combinational logic circuits”, AIEE 1953
Frequently asked questions
Why are the rows and columns ordered 00, 01, 11, 10?
That is Gray code: each step changes only one bit, so cells next to each other (including the left and right edges, and top and bottom) differ in a single variable. That adjacency is what lets a rectangle of 1s collapse into one simpler term.
What are don't-care terms?
Input combinations that never occur or whose output doesn't matter (for example the codes 10–15 in a BCD circuit). Mark them as X: the solver may treat each one as 1 if that enlarges a group, or as 0 otherwise, which often gives a simpler expression.
How are minterms numbered?
A is the most significant bit. For four variables minterm 13 is 1101: A = 1, B = 1, C = 0, D = 1. The map shows the row bits (AB) on the left and the column bits (CD) on top.
Can a cell be in more than one group?
Yes — overlapping is allowed and often needed to make groups as large as possible. What matters is that every 1 is covered by at least one group and that you use as few groups as possible.
Does it work for five variables?
Yes. A 5-variable map is shown as 4 rows (AB) × 8 columns (CDE) in reflected Gray code; groups that mirror across the middle are found automatically because the solver works on the minterm numbers, not on the picture.
Related calculators
This calculator is for educational purposes. Double-check important results before acting on them.