Skip to content
K Knidox Search…
Computer Science · Logic

Karnaugh Map

Minimise a Boolean function of two to four variables, with the map and every prime implicant.

Variables
Where the function is 1. Indices from 0 to 15, comma separated.
Inputs that never occur, free to treat as 0 or 1.
Minimal expression
B̄C̄ + CD̄ + ĀBD

3 product terms

Literals
7

the usual measure of cost

Prime implicants
6

this cover is the only minimal one

The map

AB\CD00011110
00
10
11
03
12
01
04
15
17
16
11
012
013
015
114
10
18
19
011
110

Columns and rows run in Gray-code order, so any two neighbouring cells differ in exactly one variable — which is what makes a rectangular group legal.

Prime implicantPatternCoversStatus
ĀC̄D0-011, 5Not needed
ĀBD01-15, 7Chosen to finish the cover
ĀBC011-6, 7Not needed
B̄C̄-00-0, 1, 8, 9Essential — nothing else covers one of its minterms
B̄D̄-0-00, 2, 8, 10Not needed
CD̄--102, 6, 10, 14Essential — nothing else covers one of its minterms

The cover is found by exhaustive search over the prime implicants, so it is genuinely the cheapest — not merely a good one found by a greedy rule.

Examples — tap to load

A Karnaugh map rearranges a truth table so that neighbouring cells differ in exactly one variable. Groups of adjacent 1s then correspond to terms with that variable cancelled out, which is why circling the largest legal groups gives the simplest expression.

Why the map is laid out so strangely

The columns do not run 00, 01, 10, 11 but 00, 01, 11, 10. That is Gray code, and it is the whole point: consecutive entries differ in one bit, so any two cells sharing an edge differ in exactly one variable. Two adjacent 1s therefore represent a pair like AB̄C and ABC, whose sum simplifies to AC — the B has cancelled, because the function is 1 whether B is true or false.

Everything else follows. A group of two removes one variable, a group of four removes two, a group of eight removes three. The groups must be rectangles of size a power of two, and they wrap around the edges, because the leftmost and rightmost columns also differ in only one bit. That wrap-around is the part most often missed by eye.

Prime implicants, and choosing between them

A group that cannot be made any larger is a prime implicant. Finding them all is mechanical — the Quine–McCluskey procedure repeatedly combines terms differing in one bit until nothing more combines — but finding the cheapest set that still covers every 1 is a separate problem. Some prime implicants are essential, being the only one covering a particular minterm; the rest are a choice, and this page searches every combination rather than taking whichever looks biggest first.

group of 2 → 1 variable gone  ·  4 → 2 gone  ·  8 → 3 gone

groups must be rectangles whose side lengths are powers of two, and they wrap round the edges

  1. 1
    Fill the map from the truth table. Put a 1 in every cell whose index is a minterm, an x for a don’t-care, and 0 elsewhere.
  2. 2
    Find the largest legal groups. Rectangles of 1, 2, 4, 8 or 16 cells. Don’t-cares may be included when it helps, and ignored when it does not.
  3. 3
    Remember the edges wrap. The left and right columns are neighbours, and so are the top and bottom rows. The four corners of a four-variable map form a legal group of four.
  4. 4
    Keep the essential groups. If a 1 is covered by only one group, that group must be in the answer.
  5. 5
    Cover what is left as cheaply as possible. Choose among the remaining groups to cover the rest with the fewest literals — not simply the fewest groups.

What each group size buys

On a four-variable map. A larger group is always a simpler term.

Cells in the groupVariables eliminatedLiterals leftExample term
104AB̄CD
213AB̄C
422AB̄
831A
16401 — the function is always true

Don’t-cares, and what the method cannot do

A don’t-care marks an input combination that never occurs — a binary-coded decimal digit above 9, say, or a state the hardware cannot reach. Because the output for it is irrelevant, it can be treated as a 1 when that enlarges a group and as a 0 when it does not. Using them well often removes a whole term, which is why they are worth listing rather than leaving as zeros.

Two limits are worth naming. The map is a visual method and stops being usable past four variables — five needs two stacked maps and six is essentially unreadable, which is why real synthesis tools use Quine–McCluskey or Espresso rather than a drawing. And the result here is a minimal sum of products; a product of sums can sometimes be cheaper still, and is found by mapping the zeros instead.

One thing the page reports that a hand-drawn map hides: whether the minimal cover is unique. When several different sets of prime implicants share the lowest cost, any of them is equally correct, and a textbook answer key showing a different expression from yours may well be one of the alternatives rather than a mark against you.

Why are the columns in the order 00, 01, 11, 10?
That is Gray code, where consecutive entries differ in one bit. It makes adjacent cells differ in exactly one variable, which is what allows a group of two to cancel a variable out.
What is a prime implicant?
A group that cannot be enlarged any further. Every minimal expression is built from prime implicants, though not every prime implicant appears in the answer.
What makes a prime implicant essential?
Being the only group covering some particular 1. Such a group has to appear in the answer, since nothing else can account for that minterm.
Do groups wrap around the edges?
Yes. The left and right columns are adjacent, as are the top and bottom rows, so the four corners of a four-variable map form a legal group of four.
How do I use don’t-cares?
Treat each as a 1 when doing so makes a group larger, and as a 0 otherwise. They cost nothing because those input combinations never occur.
Can a function have more than one minimal answer?
Yes. When several covers share the lowest literal count they are all equally correct, which is why two textbooks can give different-looking answers to the same question.
Why do real tools not use Karnaugh maps?
Because the visual method collapses past four variables. Quine–McCluskey does the same job algorithmically at any size, and heuristics such as Espresso handle the hundreds of variables a real circuit has.