Uni-Sine
Computer ScienceData and logic

Karnaugh map solver

A Karnaugh map solver simplifies a Boolean expression by laying its truth table out as a grid and grouping neighbouring 1s. Each group of 1, 2, 4 or 8 cells becomes one simple term, and together the groups give the minimal sum of products. Our Boolean Algebra Simplifier draws the Karnaugh map (K-map) for up to 4 variables, outlines the groups it uses, and gives the minimal sum of products or product of sums.

The K-map sits under the simplified answer, so there is no separate mode to switch to: type an expression and the map appears. It opens on A'B + AB + AB', whose map simplifies to A + B.

Try it

Boolean Algebra Simplifier

Simplify expressions with Boolean laws and Karnaugh maps

Go to its page

How to use the Karnaugh map solver

  1. Type the expression in the Expression box, such as A'B'C' + A'BC' + AB'C + ABC. Use ' or NOT for "not", letters side by side or AND for "and", and + or OR for "or".
  2. Choose Group the 1s for the minimal sum of products, or Group the 0s for the minimal product of sums.
  3. Read the K-map, with each group outlined, and the minimal form beside it.
  4. Tap a cell to mark it as a don't care (X). The minimal form uses it only if that makes the answer smaller.
  5. Follow the working, which also simplifies the expression one law at a time, naming each law.

Maps go up to 4 variables. For 5 to 8 variables the calculator still finds the minimal form, by the Quine-McCluskey method, but does not draw a map. You can change how answers are written, as AND OR, as ∧ ∨ ¬, or as · + ′.

From minterms to the solver

Many K-map questions give the minterms, such as F(A, B, C) = Σm(0, 2, 5, 7). The calculator takes an expression, not a minterm list, so write each minterm as a product: write the number in binary, then use a letter for each 1 and a NOT letter for each 0.

MintermBinary ABCProduct term
m0000A'B'C'
m2010A'BC'
m5101AB'C
m7111ABC

So Σm(0, 2, 5, 7) is A'B'C' + A'BC' + AB'C + ABC. Type that, and the calculator draws the map with those four 1s.

How to solve a Karnaugh map by hand

  1. Draw the grid with its rows and columns in Gray code order, 00, 01, 11, 10, so neighbouring cells differ by one variable.
  2. Put a 1 in each cell where the function is 1.
  3. Group the 1s in rectangles of 1, 2, 4, 8 or 16 cells. Make each group as big as possible, and use as few groups as you can. Groups may overlap and wrap round the edges.
  4. For each group, keep the variables that stay the same across it and drop the ones that change.
  5. Add up (OR) the terms from all the groups.

Worked examples you can check in the calculator

Example 1: three variables

Simplify F = Σm(0, 2, 5, 7). The 1s at m0 and m2 are neighbours, where A = 0 and C = 0, giving A'C'. The 1s at m5 and m7 are neighbours, where A = 1 and C = 1, giving AC:

F = \overline{A}\ \overline{C} + AC

Type A'B'C' + A'BC' + AB'C + ABC and the calculator gives A·C + A′·C′, down from 12 letters to 4. Choose Group the 0s and it gives the product of sums (A′ + C)(A + C′).

Example 2: four variables, with wrap-around

Simplify F(A, B, C, D) = Σm(0, 1, 2, 5, 8, 9, 10). The map, with AB down the side and CD across the top:

AB \ CD00011110
001101
010100
110000
101101
  • The four cells for C′D′ and C′D in rows 00 and 10 make a group of 4, where B = 0 and C = 0: B′C′.
  • The four corners are neighbours, because the map wraps round: B = 0 and D = 0, so B′D′.
  • m1 and m5 make a pair, where A = 0, C = 0 and D = 1: A′C′D.
F = \overline{B}\ \overline{C} + \overline{B}\ \overline{D} + \overline{A}\ \overline{C}D

Write the seven minterms as products and the calculator gives the same three terms, down from 28 letters to 6.

Example 3: don't cares

F = Σm(1, 3, 7, 11, 15), with don't cares at m0, m2 and m5. Without the don't cares, the best is A′B′D + CD. Tap cells 0, 2 and 5 on the map to mark them X, and the calculator can now make a group of four in the top row, giving A′B′ + CD, one letter shorter.

Check yourself:

practice
Pick an answer, then check it.
On a 4-variable K-map, a group of 4 cells covers the whole row where A = 0 and B = 1. What term does it give?

What the solver does not do

  • No minterm list input. Type the expression, or write each minterm as a product first, as above.
  • You cannot fill cells with 1s. Tapping a cell only marks a don't care. The 1s come from the expression.
  • Maps stop at 4 variables. It still simplifies up to 8 variables, but without drawing a map.

Common mistakes

  • Using binary order instead of Gray code. Columns must go 00, 01, 11, 10, or neighbouring cells will not differ by one variable.
  • Making groups of 3 or 6. Groups must be 1, 2, 4, 8 or 16 cells, in rectangles.
  • Missing the wrap-around. The left and right edges are neighbours, and so are the top and bottom. The four corners can form one group.
  • Groups that are too small. A bigger group gives a shorter term. Always look for the largest groups first.
  • Treating don't cares as 1s you must cover. Use them only if they make a group bigger.

Practise logic in a short timed paper

Boolean logic and logic gates come up in AP Computer Science Principles practice, and in GCSE Computer Science in the UK. Each daily paper is a short timed paper of 8 questions worth 25 to 35 marks, and the papers mix topics. Our Boolean algebra calculator guide covers simplifying with the laws, and the Circuits course covers truth tables and gates.

Common questions

What is a Karnaugh map?
A grid that lays out a truth table so that neighbouring cells differ in one variable. Grouping the 1s gives a simplified Boolean expression.
How do you solve a 4-variable K-map?
Draw a 4 by 4 grid in Gray code order, fill in the 1s, group them in rectangles of 1, 2, 4, 8 or 16 as large as possible, and write one term per group.
What are don't care conditions?
Input combinations that never happen or whose output does not matter. Mark them X and treat them as 1s only when that makes a group bigger.
What is the difference between sum of products and product of sums?
Sum of products groups the 1s and ORs AND terms. Product of sums groups the 0s and ANDs OR terms.
Why is Gray code used on a K-map?
So that each cell differs from its neighbours in one variable only, which is what lets a group drop that variable.
Can the solver handle 5 variables?
It finds the minimal form for up to 8 variables, but draws a map only up to 4.

Revision cards

Say the answer first, then flip the card to check it.

Where to go next

  • Solve it

    Boolean Algebra Simplifier

    Simplify expressions with Boolean laws and Karnaugh maps

    Open the tool
  • Learn it

    Circuits

    Resistors, capacitors and logic gates: build and understand real circuits

    Start the course
  • Test it

    AP Computer Science Principles

    A new exam-style paper every day, with instant marking and a mark scheme

    Start today's paper
Read next
Computer Science · Data and logicBoolean algebra calculator: simplify with laws and K-mapsFree Boolean algebra calculator: simplify any expression step by step, with each law named, a Karnaugh map, and the minimal sum of products.