Karnaugh map solver with groupings and step-by-step minimisation
This Karnaugh map solver simplifies a Boolean function of 2, 3, 4 or 5 variables to its minimal sum-of-products or product-of-sums form. Enter the minterms (the rows of the truth table where the output is 1) and any don’t-care conditions, or simply click cells on the map to toggle them between 0, 1 and X. The map is drawn in Gray-code order, each chosen group is outlined in its own colour — including groups that wrap around the edges — and the resulting expression appears above it.
Because K-maps are solved by eye, the tool uses the equivalent algorithm, Quine–McCluskey with Petrick’s method, to guarantee a minimal cover and to show the working: the grouping of minterms by their number of 1s, each combining round, the prime implicants, the essential ones, and the choice made among the remaining candidates.
How to use the Karnaugh Map Solver
- Choose the number of Variables (2–5). Variables are named A, B, C, D, E with A as the most significant bit of the minterm number.
- Type the Minterms as a comma-separated list, such as 0, 1, 2, 5, 6, 7, and any Don’t-cares. Alternatively paste a truth-table output column such as 11100111.
- Or click cells on the map: each click cycles 0 → 1 → X → 0, and the lists update to match.
- Read the minimal expression above the map. Switch between Minimal SOP and Minimal POS, and pick the notation (A'B, ĀB or ¬A∧B).
- Follow the numbered Solution steps to see the prime implicants, the essential ones and the Petrick selection if the chart is cyclic.
- Copy the expression as text or LaTeX, or download the map as SVG for a report.
Karnaugh Map Solver features
2 to 5 variables
2×2, 2×4 and 4×4 maps, and two 4×4 planes (A = 0 and A = 1) for five variables, all labelled in Gray code so adjacent cells differ in one bit.
Don’t-care handling
X cells are used when they enlarge a group and ignored otherwise, exactly as in the textbook method.
Guaranteed minimal cover
Quine–McCluskey finds every prime implicant; essential implicants are picked first and Petrick’s method resolves cyclic charts by the fewest terms, then the fewest literals.
Visual groupings
Each implicant is drawn as rounded rectangles over its cells, with wrap-around groups split at the edges and nested insets so overlapping groups stay readable.
SOP and POS
The product-of-sums form is derived by minimising the 0-cells and complementing the literals, with its own step list.
How a Karnaugh map works
A Karnaugh map is a truth table folded into a grid whose rows and columns are numbered in Gray code (00, 01, 11, 10), so that any two cells that touch — including cells at opposite edges — differ in exactly one variable. Wherever a block of 1-cells with 2, 4, 8 or 16 members forms a rectangle, the variables that change inside that block cancel out, leaving a product term with fewer literals. The minimal SOP is the smallest set of such blocks (prime implicants) that covers every 1-cell; don’t-cares may be included in a block whenever that makes it larger.
The product-of-sums form uses the same idea on the 0-cells: each block of zeros becomes a sum term in which every literal is complemented, so a block where A = 1 and B = 0 gives the factor (A' + B).
Worked example: F = Σm(0, 1, 2, 5, 6, 7)
With three variables the 1-cells are 000, 001, 010, 101, 110 and 111. Every pair of adjacent 1s forms a two-cell group, giving six prime implicants — A'B', A'C', B'C, AC, AB and BC' — and none of them is essential, because every minterm sits in two groups. This is a cyclic chart, where a quick glance can lead to four groups when three suffice. Petrick’s method shows that two different three-term covers exist: A'B' + BC' + AC and A'C' + B'C + AB; both use six literals, and the solver reports one of them. The POS form comes from the two 0-cells (011 and 100): F = (A + B' + C')(A' + B + C).
| Group size | Literals eliminated | Term literals (4 variables) |
|---|---|---|
| 1 cell | 0 | 4 |
| 2 cells | 1 | 3 |
| 4 cells | 2 | 2 |
| 8 cells | 3 | 1 |
| 16 cells | 4 | 0 (F = 1) |
Tips and common mistakes
- Groups must be rectangles whose side lengths are powers of two: 1, 2, 4 or 8 cells. An L-shape or a 3-cell strip is not a valid group.
- Always look for wrap-around groups — the four corner cells of a 4-variable map form a valid group (B'D' in the usual labelling).
- Use the largest possible groups, even if cells are covered twice; redundant small groups add literals without changing the function.
- If a cell is a don’t-care, you are free to treat it as 0 for SOP and 1 for POS; the two minimal forms may therefore assign it differently.
- To build the minterm list from an expression, run it through the truth table generator, which prints Σm(…) directly; the bitwise calculator helps when the function is given as a hex bit pattern.
Karnaugh Map Solver FAQ
How do I enter a Karnaugh map from a truth table?
List the row numbers whose output is 1 in the Minterms box, with any X rows in Don’t-cares. Or open “paste the output column” and type the output bits in row order, for example 11100111 for a 3-variable function.
Which variable is the most significant bit?
A. For four variables the minterm number is ABCD in binary, so minterm 10 = 1010 means A = 1, B = 0, C = 1, D = 0. Rows are labelled with AB and columns with CD.
Why does the solver give a different but equally short answer than my textbook?
Many functions have several minimal covers with the same number of terms and literals — the cyclic example above has two. Any of them is correct; the solver picks the first cheapest cover it finds.
Can it solve 5-variable maps?
Yes. Five variables are shown as two 4×4 maps, for A = 0 and A = 1. Cells in the same position on both maps are adjacent, so groups can span the two planes.
What does the Petrick step mean?
When no essential prime implicant covers some minterms, Petrick’s method writes down which implicants could cover each one, multiplies those choices out and keeps the cheapest combination. It is the systematic version of “try the groupings and pick the shortest”.