Karnaugh Map Solver Calculator (2-5 Variables)

Enter the minterms where your Boolean function is 1, add any don't-care conditions, and this calculator returns the minimal sum-of-products or product-of-sums expression for it. The result comes from the Quine-McCluskey algorithm with an exact cover search, so it is a true minimum rather than a good-looking grouping - and the Karnaugh map itself is drawn in Gray code alongside, with every prime implicant listed and the essential ones marked, so you can check your own circles against it.

Calculator

This calculator runs in your browser. Enable JavaScript for live results — the inputs, formula and worked example below remain fully readable without it.

Inputs this calculator takes, with typical values
InputWhat to enterExample
Number of variablesDetermines the map size: 2 variables give 4 cells, 5 give 32.4
Output formPOS is obtained by minimising the complement of the function and applying De Morgan.Minimal sum of products (OR of ANDs)
Minterms (where F = 1)Row numbers of the truth table where the output is 1, with the first variable as the most significant bit.0, 2, 5, 7, 8, 10, 13, 15
Don't-care indicesInput combinations that cannot occur or whose output is irrelevant. Leave blank if there are none.
Variable namesListed from the most significant bit first. Leave as A, B, C, D, E if you have no preference.A, B, C, D, E

It returns

  • Minimal expression — An apostrophe means complement. A constant function shows as 0 or 1.
  • Terms
  • Literals — Total variable appearances - the usual proxy for gate input count.
  • Prime implicants found
  • Essential prime implicants
  • Gates needed (estimate) — ANDs plus one OR plus one inverter per distinct complemented variable, with unlimited fan-in.

The formula

F=pcovervfixed(p)v±
(A+B)=AB

In plain text: F = Σ over the chosen prime implicants of Π (literals held constant in that group)

  • mintermA truth-table row where the output is 1, numbered with the first variable as the MSB
  • implicantA group of 2ᵏ adjacent cells, written as one product term
  • prime implicantAn implicant that cannot be enlarged
  • essentialA prime implicant that is the only cover of some minterm
  • literalOne appearance of a variable, complemented or not

A group of 2ᵏ cells eliminates exactly k variables. Cells wrap around both edges of the map, so the four corners of a four-variable map are mutually adjacent.

Updated Category Discrete Math, Logic & Graph Theory Verified against published test cases Reading time 11 min

What a Karnaugh map does

A Karnaugh map is a truth table redrawn so that adjacency means something. The rows and columns are labelled in Gray code - each label differs from its neighbour in exactly one bit - so any two cells that touch differ in exactly one variable. Two adjacent 1s can therefore be merged, and the variable that changes between them drops out of the expression entirely.

That is the whole method. Circle groups of 1s whose size is a power of two, read each group as a product term containing only the variables that stay constant across it, and OR the terms together. A group of 2 removes one variable, a group of 4 removes two, a group of 8 removes three.

The map also wraps around: the leftmost column is adjacent to the rightmost, and the top row to the bottom, because their Gray code labels also differ in one bit. The four corners of a four-variable map form a legitimate group of four, which is the fact beginners miss most often.

This calculator does not guess at circles. It runs the Quine-McCluskey algorithm, which finds every prime implicant systematically and then selects a minimum-cost cover exactly, so the answer it gives is a genuine minimum rather than a good-looking grouping. The map is still drawn, because seeing the groups is how the method is taught and checked.

Implicants, prime implicants and the cover

Three terms carry the whole theory.

An implicant is any product term that is 1 only where the function is 1 (or don't-care). On the map it is any legal group. A prime implicant is an implicant that cannot be enlarged - no bigger legal group contains it. Only prime implicants can appear in a minimal expression, because a non-prime group could always be replaced by a larger one with fewer literals.

An essential prime implicant is one that is the sole cover of some minterm. If a cell is covered by exactly one prime implicant, that implicant has to be in every minimal solution - there is no alternative. Finding the essential ones first, then covering whatever is left as cheaply as possible, is the standard procedure and the one this page follows.

The last step is where hand methods and algorithms diverge. Selecting the cheapest subset of the remaining prime implicants that covers the remaining minterms is a set-cover problem, and the textbook technique for it is Petrick's method - writing the cover condition as a product of sums, multiplying it out, and reading off the cheapest product. This calculator instead searches the choices directly with branch and bound, which finds the same minimum without the algebraic expansion.

Cost is judged first by the number of terms and then by the number of literals, which is the conventional criterion: fewer terms means fewer gates feeding the output, and fewer literals means fewer gate inputs. Two different expressions can tie on both counts, in which case several equally minimal answers exist and the calculator reports one of them.

Don't-care conditions - input combinations that cannot occur, or whose output nobody cares about - are the cheapest simplification available. Each one may be treated as a 1 when that enlarges a group and as a 0 when it does not, and a single well-placed don't-care often removes a whole term. They are written X on the map and entered separately here.

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

Write out what those indices mean in binary, with A as the most significant bit:

0 = 0000, 2 = 0010, 5 = 0101, 7 = 0111, 8 = 1000, 10 = 1010, 13 = 1101, 15 = 1111

  1. Look for a pattern. In every one of those, the B bit and the D bit are equal: 0000 has B = 0 and D = 0; 0101 has B = 1 and D = 1; 1010 has B = 0 and D = 0; 1111 has both 1. The function is the XNOR of B and D.
  2. Group the cells where B = 0 and D = 0. Those are minterms 0, 2, 8 and 10 - a group of four in which A and C both vary and both drop out. The term is B′D′.
  3. Group the cells where B = 1 and D = 1. Those are 5, 7, 13 and 15 - another group of four giving BD.
  4. Combine. Every minterm is covered, so F = B′D′ + BD: two terms, four literals.

On the map these two groups look scattered rather than rectangular, which is the point of the wrap-around rule - minterms 0, 2, 8 and 10 sit at the four corners of the four-variable map, and they are adjacent through both edges. A student circling only visually contiguous blocks would find four groups of two and produce an expression with four terms and eight literals, twice the gate cost for the same function.

Both groups here are essential: minterm 0 is covered only by B′D′ and minterm 5 only by BD, so no choice arises and the minimum is unique. Building it takes two AND gates, one OR gate and two inverters - or, if you recognise the pattern, a single XNOR gate.

Reading the output

The prime implicant table is where the reasoning is visible. Rows marked essential are forced - they are the only cover for at least one minterm, and they appear in every minimal answer. Rows marked chosen were selected to finish the cover, and a different but equally cheap choice may have been available. Rows marked not needed are perfectly valid groups that the minimal solution happens not to use.

The pattern column uses a dash for each eliminated variable, so -0-0 in a four-variable problem means B = 0 and D = 0 with A and C free - a group of four, since two free variables give 2² cells. Count the dashes and you know the group size without looking at the map.

Literal count is the better guide to cost than term count alone. Two terms of four literals each need more gate inputs than three terms of two, even though the term count is smaller. The gate estimate on this page counts one AND gate per multi-literal product, one OR gate to combine them, and one inverter per distinct complemented variable - assuming gates with unlimited fan-in and no complemented inputs available. Real technology mappings differ, and a NAND-only implementation converts a sum of products directly by De Morgan at no extra cost.

If you asked for a product of sums, the prime implicant table describes the complement of your function. That is how POS minimisation works: minimise where the function is 0, then apply De Morgan to the result, which turns each product into a sum and complements every literal. Compare the SOP and POS forms of the same function and take whichever is cheaper - there is no rule that says one always wins.

How much a group removes

Group sizes on a Karnaugh map and their effect on the product term.
Cells in the groupVariables eliminatedLiterals in the term (4 variables)Literals (5 variables)Example term
1045A′BC′D
2134A′BC′
4223B′D′
8312B
1640 (constant 1)11
325n/a0 (constant 1)1

Every legal group has a size that is a power of two, and doubling the group removes exactly one more variable. A group of six is not legal, however neatly it fits on the page.

Mistakes that cost gates

  • Forgetting that the map wraps. The four corners of a four-variable map form a group of four, and the leftmost and rightmost columns are adjacent. Missing this is the single most common source of a non-minimal answer.
  • Making groups that are not powers of two. A block of six cells is not a legal group. Cover it as a four and a two, which may overlap.
  • Refusing to overlap groups. Overlapping is not only allowed but usually required - a minterm may be covered any number of times, and larger overlapping groups beat smaller disjoint ones.
  • Using a non-maximal group. If a group can be doubled, double it. Only prime implicants belong in a minimal expression, and a group of two inside a legal group of four carries one unnecessary literal.
  • Labelling the map in binary counting order. The columns run 00, 01, 11, 10 - Gray code - not 00, 01, 10, 11. Getting this wrong destroys the adjacency property the whole method rests on.
  • Wasting don't-cares. They are free simplification, but only where they enlarge a group. A don't-care that sits alone should be left as a 0; covering it adds a term for nothing.

Where this fits in digital design

Maurice Karnaugh published the map in 1953, refining a chart Edward Veitch had introduced the year before; the Gray code labelling is what makes the Karnaugh version work visually, and it is why the map survived while the Veitch diagram did not. Quine and McCluskey gave the tabular algorithm later in the 1950s, and it is that algorithm - not the drawing - that scales.

The practical limit of the drawing is about six variables. Beyond four the map splits into multiple planes and adjacency stops being visible; beyond six, nobody can see the groups at all. Real synthesis tools use heuristic minimisers in the Espresso family, which give up the guarantee of an exact minimum in exchange for handling functions with dozens of inputs and many outputs at once.

Minimisation still matters even when a tool does it for you, because it fixes gate count, propagation delay and power. It also has a subtlety the map does not show: a minimal cover can contain a static hazard, a momentary wrong output when two input variables change so that coverage passes from one group to another. The fix is to add a redundant prime implicant bridging the two groups - deliberately non-minimal logic, added for timing rather than area.

For the algebraic route to the same answer, the Boolean algebra simplifier works from an expression rather than from minterm indices, and the truth table calculator converts between the two - the minterm list is exactly the set of rows where the output is 1. The underlying algebra is the same structure as set operations, with AND for intersection, OR for union and complement for complement, so De Morgan's laws read identically in both notations.

Frequently asked questions

How do I get the minterm list from a truth table?

Number the rows from 0 with the first variable as the most significant bit, then list the row numbers where the output is 1. For three variables ABC, the row A=1, B=0, C=1 is binary 101, which is index 5. Rows whose output is marked X or 'don't care' go in the don't-care field instead. Getting the bit order backwards produces a valid but different function, so check one row before trusting the whole list.

Why must groups be a power of two in size?

Because each doubling eliminates exactly one variable, and only a group whose cells cover every combination of the eliminated variables can be written as a single product term. A group of six cells cannot be described by holding some variables constant and letting the rest vary freely, so it has no single-term expression. Cover it as a four and a two instead, overlapping if that helps.

Can groups overlap?

Yes, and they usually should. A minterm may be covered by several groups with no penalty, because OR-ing a term more than once changes nothing. Insisting on disjoint groups almost always produces a larger expression - the whole point of overlapping is to let every group grow to its maximum size.

What are don't-care conditions and how do I use them?

They are input combinations that never occur or whose output is irrelevant - the six unused codes in a BCD digit, for instance. Each may be treated as a 1 or a 0, whichever is convenient, so use one as a 1 when it enlarges a group and leave it as a 0 otherwise. Never add a term purely to cover a don't-care: it is not required to be 1, so covering it alone costs gates for nothing.

Is the minimal expression unique?

Not always. When some minterm can be covered by several prime implicants of equal cost, there are multiple minimal solutions with the same term and literal counts. The essential prime implicants are always the same, but the rest of the cover can differ. This calculator returns one minimum; a different textbook answer with the same counts is equally correct.

What is the difference between SOP and POS minimisation?

Sum of products groups the 1s and gives an OR of ANDs. Product of sums groups the 0s, minimises the complement of the function, and applies De Morgan to give an AND of ORs. Neither is always cheaper: a function with few 1s usually minimises better as SOP, and one with few 0s as POS. Compute both and compare the literal counts.

Why does the calculator use Quine-McCluskey instead of drawing circles?

Because circling is a visual heuristic and it misses groups, especially wrap-around ones. Quine-McCluskey enumerates every prime implicant by repeatedly combining terms that differ in one bit, then selects a minimum-cost cover exactly. The answer is provably minimal, which a hand grouping is not. The map is still drawn on this page so you can check your own grouping against it.

How many variables can a K-map handle?

Two to five here, shown as one map up to four variables and as two four-variable maps for five. Six is possible on paper with four maps but the adjacencies become very hard to see, and beyond that the drawing is useless. The tabular algorithm keeps working, though its cost grows quickly, which is why production tools use heuristic minimisers such as Espresso for large functions.

References

  • The Map Method for Synthesis of Combinational Logic Circuits, Transactions of the AIEE 72(9), 593-599 (1953) — Maurice Karnaugh
  • Digital Design: With an Introduction to the Verilog HDL, VHDL and SystemVerilog, 6th ed. (Chapter 3, Gate-Level Minimization) — M. Morris Mano and Michael D. Ciletti, Pearson
  • Minimization of Boolean Functions, Bell System Technical Journal 35(6), 1417-1444 (1956) — E. J. McCluskey