Karnaugh Map Calculator - K-Map Solver with Groupings

Minimise as

Click any cell to cycle it 0 → 1 → X

X marks a don’t-care: an input combination that can never happen, so the solver is free to read it as whichever value makes the groups bigger.

AB\CD
00
01
11
10
00
01
11
10

Commas, spaces or plain gaps all work.

Anything listed here overrides the box on the left.

Load a worked example

Minimal sum of products

B'D' + BD

F(A, B, C, D) = Σm(0, 2, 5, 7, 8, 10, 13, 15)

Groups

2

terms

Literals

4

down from 32

Literals saved

88%

vs canonical form

Gates

5

2 inverters

✓ Checked against all 16 rows of the truth table — the expression matches every fixed row.

The 2 groups on the map

Tap a row to light it up on the grid above. A star marks an essential prime implicant — a group that appears in every minimal answer, because at least one cell has nowhere else to go.

What the grouping bought you

Canonical SOP8 terms · 32 literals
Minimal SOP2 terms · 4 literals

Writing the function straight off the truth table needs 8 4-input AND gates. The grouped version needs 5 gates in total, inverters included.

Sum of products (AND-OR)

B'D' + BD

Product of sums (OR-AND)

(B + D')(B' + D)

How to Use This Calculator

  1. Pick Number of variables first. Changing it clears any cell outside the new range, so set it before you start filling the grid.
  2. Click cells on the map to cycle them 0 → 1 → X, or paste a minterm list into Minterms where F = 1. The grid and the two text boxes stay in sync either way, so you can start from whichever one your problem gives you.
  3. Put impossible input combinations in Don’t-care minterms — the six unused BCD codes 10 to 15, for instance. They cost nothing and usually shrink the answer.
  4. Read the coloured groups in The groups on the map, and tap any row to highlight just that group on the grid. Groups that wrap around an edge are drawn as matching colours on both sides rather than one rectangle, because that is what they actually are.
  5. Switch Minimise as to POS when the map has fewer 0s than 1s — the solver then groups the zeros instead, which is often the cheaper circuit.
  6. Open All prime implicants to see every legal group, including the ones a minimal answer skips. That table is what to compare against when your hand-drawn grouping has one term more than the calculator’s.

Share this calculator

Help others solve their calculations

Found this calculator helpful? Share it with your friends, students, or colleagues who might need it!

Karnaugh Map Calculator: Grouping Rules That Guarantee a Minimal Expression

About the Author

Marko Šinko - Co-Founder & Lead Developer

Marko Šinko

Co-Founder & Lead Developer, AI Math Calculator

Lepoglava, Croatia
Advanced Algorithm Expert

Croatian developer with a Computer Science degree from University of Zagreb and expertise in advanced algorithms. Co-founder of award-winning projects, ensuring precise mathematical computations and reliable calculator tools.

📅 Published:
Karnaugh Map Calculator showing a four-variable K-map grid with coloured groups wrapping around the edges to join opposite corner cells

Load the four-corners example into the Karnaugh map calculator above and the eight scattered ones of F = Σm(0, 2, 5, 7, 8, 10, 13, 15) collapse into B'D' + BD. Two terms, four literals, two AND gates and an OR. Written straight off the truth table the same function needs eight four-input AND gates and an eight-input OR — 32 literals for a circuit that is really just “B and D agree”.

That 88% cut comes entirely from how the cells are grouped, and grouping is where hand-drawn K-maps go wrong. Not the arithmetic — the arithmetic is trivial. The rules below are the ones that decide whether your answer is minimal or merely correct, including the one every tutorial gets backwards.

Why the Columns Run 00, 01, 11, 10

The odd column order is the whole trick. In Gray code each label differs from its neighbour in exactly one bit: 00 → 01 flips only the right bit, 01 → 11 flips only the left, 11 → 10 flips only the right again. Binary counting order would put 01 next to 10, which differ in two bits and share no algebraic factor at all.

Because of that ordering, two side-by-side cells always represent minterms that agree on every variable but one — and two minterms like that combine by the distributive law: A'BC'D + A'BCD = A'BD(C' + C) = A'BD. The map does not simplify anything a Boolean algebra calculator could not. It just arranges the terms so the pairs that cancel end up touching, which turns an algebra search into a shape-spotting exercise.

The same logic runs off the edges. Column 00 and column 10 differ in one bit too, so the leftmost and rightmost columns are neighbours — the map is a torus, not a rectangle. That is why the four corner cells 0, 2, 8 and 10 form a legal quad in the default example: all four have B = 0 and D = 0.

A group is a rectangle of cells that all contain 1 (or X). It qualifies only if it satisfies all four of these:

  • Its size is a power of two. 1, 2, 4, 8, 16 cells. A group of six is not a group, however tidy it looks — you would have to draw it as a quad plus a pair.
  • Its shape is a rectangle that is itself a power of two on each side: 1×2, 2×2, 1×4, 2×4, 4×4. An L-shape or a diagonal is never legal.
  • It may wrap across either edge, or both at once. Corners count.
  • It may overlap other groups. Covering a cell twice costs nothing; leaving one uncovered breaks the function.

Group size is what pays. Each doubling removes exactly one variable from the term, so the payoff on a four-variable map is:

Cells groupedNameVariables removedLiterals left (4-var map)
1single04 — e.g. AB'CD'
2pair13 — e.g. AB'C
4quad22 — e.g. BD
8octet31 — e.g. D
16whole map40 — F = 1

So an octet is worth three separate pairs and then some. Which is exactly why the standard advice is “always circle the biggest group first” — and exactly why that advice sometimes costs you a term.

The Biggest Group Can Be the Wrong Group

Take F(A, B, C, D) = Σm(0, 1, 2, 3, 5, 6, 7, 8) — the Biggest-group trap preset above. The cells 0, 1, 2 and 3 sit in a clean 1×4 block along the top row: the quad A'B'. It is the largest group on the map, it is impossible to miss, and every “biggest first” rule tells you to circle it.

Do that and you are stuck at four terms:

A'B' + A'C + A'D + B'C'D'  — 4 terms, 9 literals

Leave it out entirely and three terms cover the same eight cells:

A'C + A'D + B'C'D'  — 3 terms, 7 literals

Check it: A'C covers 2, 3, 6, 7. A'D covers 1, 3, 5, 7. B'C'D' covers 0 and 8. That is all eight ones, with cells 3 and 7 covered twice, which is allowed. The quad A'B' turns out to be pure redundancy — every one of its cells is already picked up by a group that was forced onto the map by something else.

This is not a curiosity. There are dozens of four-variable functions with the same property, and the map above will flag them for you: open All prime implicants and the quad is listed as redundant rather than selected. Size decides how much a group is worth; it does not decide whether you need it.

Start With the Cells That Have Nowhere Else to Go

The rule that actually works is the opposite of the popular one. Instead of asking “what is the biggest group?”, ask cell by cell: how many different groups could cover this one?

Any cell with exactly one answer forces that group into the solution. There is no alternative, so it appears in every minimal expression. Those are the essential prime implicants, marked with a star in the group list above. The procedure is:

  1. Find every maximal group on the map — the ones that cannot be enlarged. These are the prime implicants.
  2. Find each 1 that only one of them covers. Take those groups; they are essential.
  3. Cross off every cell those essentials already cover.
  4. Cover whatever is left with as few of the remaining groups as possible.

In the trap example, cell 8 can only be reached by B'C'D', cell 5 only by A'D and cell 6 only by A'C. Three essentials, and between them they cover all eight ones — so step 4 is empty and A'B' never enters the picture. Applying step 2 before step 4 is the entire difference between the two answers above.

Step 4 is the part with no shortcut. Picking the group that mops up the most leftover cells is a heuristic, not an algorithm, and it returns non-minimal answers on maps with as few as four ones. The solver here runs a branch-and-bound search over the leftovers instead, which is why its term count is provably the smallest and not just a good try.

Don't-Cares Are the Cheapest Simplification You Will Ever Get

A don't-care is an input combination that physically cannot occur, so the output for it is irrelevant. Binary-coded decimal is the classic source: four bits can express 16 patterns but BCD only uses 0 through 9, leaving 1010 to 1111 permanently unused.

Suppose you need a circuit that detects an even BCD digit — F = Σm(0, 2, 4, 6, 8). Group only the ones and the best you can do is:

A'D' + B'C'D'  — 2 terms, 5 literals, 2 AND gates and an OR

Now mark 10 through 15 as X. The solver is free to read those six cells as 1s wherever that helps, and the entire bottom of the map fuses into a single octet:

D'  — 1 term, 1 literal, a single inverter

The circuit is one NOT gate. Six cells you were never going to use took an 80% bite out of the literal count — and the reason is obvious once you see it: for any valid BCD digit, “even” is already exactly “last bit is 0”. The don't-cares just let the map say so.

Two cautions. Every X you claim is a promise that the input really is impossible; if 1011 ever reaches that circuit, D' will happily call it even. And don't-cares are optional cover, not required cover — the solver will leave an X ungrouped if grouping it does not help, which is why some of them stay uncoloured on the map.

When Nothing on the Map Is Essential

Some maps have no essential prime implicants whatsoever. Every cell can be covered two different ways, so step 2 above finds nothing and there is no obvious place to begin. These are called cyclic maps, and the three-variable F = Σm(0, 1, 2, 5, 6, 7) is the standard example — the Cyclic map preset.

Its six prime implicants form a ring: A'B', B'C, AC, AB, BC', A'C'. Each one is a pair, each minterm sits in exactly two of them, and the minimum cover takes three. But there are two different sets of three that work:

SolutionExpressionCost
Alternate groupsA'B' + BC' + AC3 terms, 6 literals
The other threeA'C' + B'C + AB3 terms, 6 literals

Neither is better. This is the single most common reason a student thinks a solver is broken: the calculator shows one grouping, the answer key shows the other, and both are minimal. The tool above counts them and gives you a button to cycle through the alternatives, so you can find the one your textbook printed instead of arguing with it.

Group the Zeros When There Are Fewer of Them

Everything so far grouped the 1s, which produces a sum of products — an AND-OR circuit. Group the 0s with the identical rules and you get the complement, F'. Push a bar over both sides, apply De Morgan, and each product term of F' becomes a sum term of F: a product of sums, an OR-AND circuit.

The mechanical step is just flipping every literal. If F' = A'B + CD, then F = (A + B')(C' + D'). Complemented becomes plain, plain becomes complemented, AND becomes OR.

Which form to build is a counting question, and it is worth asking because the gap can be large:

  • Far more 0s than 1s? The 1s are sparse and isolated, so SOP will need many small groups. Group the 1s anyway — few ones means few terms.
  • Far more 1s than 0s? Flip to POS. A map with three 0s and thirteen 1s usually gives a much tighter product of sums, because you are grouping the three.
  • Roughly even? Try both. The toggle above recomputes instantly, and the two answers are rarely the same size.

There is a hardware angle too. Both forms are two-level, so both have the same propagation delay, but SOP maps directly onto NAND-NAND and POS onto NOR-NOR. If your logic family gives you cheaper NORs, POS wins even at equal term count. A logic gate simplifier is the quicker route when you want the gate-level version rather than the algebra.

Where a Karnaugh Map Calculator Runs Out of Dimensions

Five variables already needs two 16-cell planes side by side, with a group allowed to span both when the two half-maps have matching cells in the same position. Six needs four planes and adjacency relationships nobody can see reliably. Past that, the visual method is finished — not because the maths changes, but because human pattern recognition does.

What replaces it is the algorithm that was running underneath all along. Quine–McCluskey does the same combining step as a table rather than a picture, which is why the solver above handles two through five variables with one code path. It is exact and it scales past what you can draw, but the number of prime implicants can grow exponentially, so industrial tools use the Espresso heuristic instead and accept a near-minimal result for hundreds of inputs.

For coursework and for any circuit you would actually breadboard, four variables covers almost everything. Build the truth table first, transfer the 1s onto the map, group by the rules above, and check the result against a Boolean algebra simplifier if the expression came out differently from what you expected. If you would rather work from an expression than from a minterm list, the Boolean expression solver takes the written form directly, and our guide on how to simplify Boolean expressions walks through the algebraic route for comparison.

For the underlying theory and the history — Veitch published the chart in 1952, Karnaugh reworked it in 1953 — the Wikipedia entry on Karnaugh maps is thorough, and the Espresso minimiser page covers what industry uses when the map runs out of dimensions.

Frequently Asked Questions

Still Have Questions?

The detailed content on this page provides comprehensive explanations and examples to help you understand better.