What Is a Karnaugh Map (K-Map)?
A Karnaugh map, or K-map, is a graphical method for simplifying Boolean expressions, invented by Maurice Karnaugh in 1953. It rearranges a truth table into a grid where physically adjacent cells differ by exactly one variable — achieved through Gray-code ordering of the rows and columns (00, 01, 11, 10). By grouping adjacent 1s into rectangles of size 1, 2, 4, 8 or 16, you can read off the minimal Sum of Products directly, without applying Boolean algebra by hand. This K-map solver builds the map, groups the 1s automatically, and returns the simplified expression with color-coded groups.
How to Use This K-Map Solver
1. Choose 2, 3 or 4 variables. 2. Enter the minterms — the cell numbers where the output is 1 — as a comma-separated list, and optionally any don't-care terms. 3. Or click cells directly on the map to cycle each between 0, 1 and X. The solver instantly plots the map in Gray-code order, groups the 1s into the largest possible blocks, and shows the minimal SOP with each group in its own color. Click a prime-implicant chip to highlight exactly which cells that term covers.
How to Solve a K-Map, Step by Step
The solver follows the same procedure you would by hand:
- Plot the map — place a 1 for each minterm, X for don't-cares, 0 elsewhere, using Gray-code row/column labels.
- Group the 1s into the largest power-of-two rectangles. Groups may overlap and may wrap around the edges — the first and last columns are adjacent, as are the first and last rows, and the four corners.
- Drop the changing variables — within each group, keep only the variables that stay constant. A variable held at 1 appears as itself; held at 0 it appears complemented.
- OR the product terms to form the minimal Sum of Products.
Grouping Rules
| Group size | Variables removed | Literals in term (4-var) |
|---|---|---|
| 1 cell | 0 | 4 |
| 2 cells (pair) | 1 | 3 |
| 4 cells (quad) | 2 | 2 |
| 8 cells (octet) | 3 | 1 |
| 16 cells | 4 | 0 (F = 1) |
Bigger groups mean fewer literals, so the goal is always to form the largest legal groups and the fewest of them.
Worked Example (4 Variables)
F(A,B,C,D) = Σm(0,1,2,3,5,7)
Minterms 0,1,2,3 form a quad where A=0 and B=0, giving A′B′. Minterms 1,3,5,7 form a quad where A=0 and D=1, giving A′D. Together they cover every 1, so the minimal result is F = A′B′ + A′D — down from six 4-literal minterms to two short terms.
Don't-Care Conditions
A don't-care term (marked X) is an input combination whose output never occurs or does not matter — a common example is a BCD decoder, where inputs 10–15 never appear. The solver may treat each X as 0 or 1, whichever makes the groups larger and the expression simpler. Used well, don't-cares often cut the literal count substantially. Enter them in the don't-care field or cycle a cell to X on the map.
2, 3 and 4 Variable K-Maps
The layout depends on the number of variables:
- 2-variable K-map — a 2×2 grid (rows A, columns B, 4 cells). Best for the simplest functions.
- 3-variable K-map — a 2×4 grid (rows A, columns BC in Gray code, 8 cells).
- 4-variable K-map — a 4×4 grid (rows AB, columns CD, 16 cells). This is the most widely used size in coursework and the largest that stays easy to read by eye.
The 4 variable Karnaugh map is the one most students need: remember that its edges wrap, so the top and bottom rows are adjacent, the left and right columns are adjacent, and all four corner cells are mutually adjacent. This solver handles the wrap-around grouping automatically for every size.
Getting the Product of Sums (POS)
Switch the output form to POS and the solver groups the 0-cells instead of the 1-cells. It minimises those, then applies De Morgan's law so each product term becomes a sum term — giving the minimal Product of Sums as ANDed groups of ORed literals, for example (A + B′)(C′ + D). POS is often more compact than SOP when a function has fewer 0s than 1s, and it maps directly onto an OR-AND (two-level) gate structure.
SOP vs POS, Prime Implicants, and Quine-McCluskey
Sum of Products (SOP) groups the 1-cells and ORs the product terms — the form this solver returns. Product of Sums (POS) instead groups the 0-cells. A prime implicant is a group that cannot be made any larger; an essential prime implicant is the only one covering some particular minterm and must appear in the answer. Under the hood the solver uses the Quine-McCluskey algorithm — the systematic equivalent of visual K-map grouping — to guarantee a minimal result. See the gates behind each term in the Logic Gate Calculator, or build the truth table first in the Truth Table Generator.
The map rows and columns are labelled in Gray code order. Convert between the two encodings in the Gray Code Converter, with the XOR steps shown.
Frequently Asked Questions
What is a Karnaugh map (K-map)?
A graphical tool for simplifying Boolean expressions. Adjacent cells differ by one variable (Gray-code order), so grouping adjacent 1s reveals the minimal Sum of Products without algebra.
How do you solve a K-map?
Place 1s for the minterms, group adjacent 1s into the largest power-of-two rectangles (wrapping around edges), keep the constant variables in each group, and OR the product terms. This solver does it automatically.
What is a minterm?
An input combination that makes the function output 1, numbered by reading the input bits as binary. For A,B,C,D the combination 0101 is minterm 5.
What are don't-care conditions in a K-map?
Inputs whose output is irrelevant, marked X. The solver treats each as 0 or 1, whichever yields larger groups and a simpler expression.
What is the difference between SOP and POS?
SOP groups the 1-cells and ORs product terms (AND-OR circuit); POS groups the 0-cells and ANDs sum terms (OR-AND circuit). Both describe the same function.
How many variables can a K-map handle?
Karnaugh maps are practical for up to 4 variables. Beyond that, algorithmic methods like Quine-McCluskey are used. This solver covers 2, 3 and 4 variables.
How does this solver find the Product of Sums (POS)?
It groups the 0-cells to minimise the complement of the function, then applies De Morgan's law so each product term becomes a sum term — giving the minimal Product of Sums.
How do you solve a 4-variable K-map?
Use a 4×4 grid with rows AB and columns CD in Gray-code order. Place 1s for the minterms, group adjacent 1s into blocks of 1, 2, 4, 8 or 16 (edges and corners wrap), and read one product term per group. The solver does this automatically.
What is a prime implicant?
A group of adjacent 1-cells that cannot be expanded further. An essential prime implicant is the only group covering some minterm, so it must appear in the final expression.