What is a Karnaugh map?
A Karnaugh map (K-map) is a truth table drawn so that neighbouring cells differ in exactly one variable. To achieve that, rows and columns follow Gray code order (00, 01, 11, 10) instead of binary order. When two 1s sit next to each other, the variable that changes between them can be eliminated: A·B·C + A·B·C' = A·B.
The map wraps around: the last column is adjacent to the first and the last row to the first. That is why the four corners of a 4-variable map can form a single group.
Rules for grouping
- Groups are rectangles of 1, 2, 4, 8 or 16 cells (powers of 2).
- Make groups as large as possible: a group of 2k cells eliminates k variables.
- Use the fewest groups that cover every 1. A cell can belong to several groups.
- Don't cares (X) can be treated as 1 if they help enlarge a group, but they never have to be covered.
- For each group, keep the variables that do not change: uncomplemented if they are 1 and complemented if they are 0.
Example · F = Σm(0, 2, 5, 7, 8, 10, 13, 15)
The four corners (0, 2, 8, 10) form a group where B = 0 and D = 0 throughout: B'D'. The four center cells (5, 7, 13, 15) have B = 1 and D = 1: BD. Result: F = B'D' + BD, which is B XNOR D. A and C disappear because they have no effect.
Sum of products vs product of sums
For the SOP form you group the 1s and each group gives a product term. For the POS form you group the 0s: each group gives a sum term in which variables appear inverted (complemented if they are 1 in the group). Both are correct; depending on the function one can be shorter than the other, and POS is often more convenient for NOR-gate implementations.
How the solver finds the minimal expression
Besides drawing the groups, the tool runs the Quine-McCluskey method: it generates every prime implicant (the largest possible groups), picks the essential ones first (those that are the only cover for some 1) and then tries every combination of the rest to find the cover with the fewest terms and, on a tie, the fewest literals. With 4 variables or fewer this guarantees a minimal expression. If several are equally short, one of them is shown, so yours may differ and still be correct.
Frequently asked questions
Why is the order 00, 01, 11, 10 and not 00, 01, 10, 11?
Because going from 01 to 10 changes two bits at once. In Gray code each step changes a single bit, which is what allows adjacent cells to be simplified.
What is an essential prime implicant?
A prime implicant is a group that cannot be made any larger. It is essential if it covers at least one 1 that no other group covers, so it must appear in the minimal expression.
What about 5 or more variables?
5- and 6-variable maps are drawn as two or four stacked 4-variable maps, but they are hard to read. In practice people use Quine-McCluskey or tools like Espresso. You can get the truth table of any expression with the truth table generator.
How do I enter my function?
Type the minterms (the rows where the output is 1) separated by commas, and optionally the don't cares, or click the cells of the map directly. The expression updates instantly.
More computer science tools
Two's Complement Calculator
Signed integers in two's complement, one's complement and sign-magnitude, plus overflow.
OpenIEEE 754 Floating-Point Converter
32 and 64-bit floating point with biased exponent and rounding error.
OpenIPv4 Subnet Calculator
Network, broadcast, hosts, wildcard and VLSM planning with the binary AND.
OpenTruth Table Generator
Truth table for any expression, with minterms and canonical forms.
OpenNumber Base Converter
Binary, octal, decimal, hex and bases 2–36 with repeated division.
OpenSorting Algorithm Visualizer
Animated sorting with comparison and write counters.
Open