Skip to content
MoneyDeck

Karnaugh Map Solver

Minimise Boolean functions of 2–6 variables to simplest SOP and POS

Updated · Free, no signup

Decimal indices separated by commas or spaces. A is the most significant bit.

Comma-separated, most significant first.

Minimal sum of products (SOP)

B'C' + CD' + A'BD

Minimal product of sums (POS)

(A' + B' + D')(B + C' + D')(B' + C + D)

SOP terms

3

SOP literals

7

POS terms

3

POS literals

9

Prime implicants (of the 1s)

6

Function

F(A,B,C,D) = Σm(0,1,2,5,6,7,8,9,10,14)
  • SOP uses 3 term(s) and 7 literals; POS uses 3 term(s) and 9 literals — build whichever needs fewer gates.

Karnaugh map (Gray-code order; X = don’t care)

AB \ CD00011110
001101
010111
110001
101101

About the Karnaugh Map Solver

This Karnaugh map solver simplifies a Boolean function of two to six variables. Enter the minterms (the input combinations where the output is 1) and any don’t-care terms, and it returns the minimal sum-of-products (SOP) and product-of-sums (POS) expressions, the number of terms and literals in each, all the prime implicants, and the filled-in K-map laid out in Gray-code order so you can check your own groupings.

It is aimed at digital-logic students working through homework and exam practice, and at engineers reducing gate count in a PLD, FPGA lookup table or discrete logic design. Don’t-care conditions — such as unused BCD codes 10 to 15 — are used only when they make a group larger, exactly as you would on a hand-drawn map.

Behind the scenes it uses the Quine–McCluskey method, which is what a K-map does visually, followed by an exact search for the smallest cover (fewest terms, then fewest literals). Variable A is the most significant bit, so minterm 5 of a 4-variable function is A′BC′D. When several equally small answers exist, the solver shows one of them.

How to use the karnaugh map solver

  1. 1Choose the number of input variables (2 to 6).
  2. 2Enter the minterms — the decimal row numbers where the output is 1.
  3. 3Add any don’t-care terms that can never occur.
  4. 4Optionally rename the variables (most significant first).
  5. 5Read the minimal SOP and POS, and compare your groupings with the K-map grid.

Formula and method

Combine terms that differ in one bit: X·Y + X·Y′ = X · F = Σ(prime implicants in a minimum cover)

A Karnaugh map arranges the truth table in Gray-code order so that neighbouring cells differ in exactly one variable; circling groups of 1, 2, 4, 8… adjacent 1s removes the variables that change inside the group. The solver does the same thing algebraically with the Quine–McCluskey method: it repeatedly merges pairs of terms that differ in a single bit (using don’t-cares as 1s) until no more merges are possible. The terms that cannot be merged further are the prime implicants — the largest possible groups.

It then chooses the smallest set of prime implicants that covers every 1 (essential primes are forced automatically), searching exactly for the fewest terms and then the fewest literals (the search is capped to stay instant, so an unusually tangled 6-variable function could return a near-minimal cover). The product-of-sums form is found the same way from the 0s and written with each variable complemented, by De Morgan’s law.

Σm
List of minterms where the function is 1
d
Don’t-care terms that may be treated as 0 or 1
X′
Complement (NOT) of variable X
SOP / POS
Sum of products (OR of ANDs) / product of sums (AND of ORs)

Worked examples

Four-variable function with ten minterms

Σm(0,1,2,5,6,7,8,9,10,14): minterms 0, 1, 8 and 9 form the quad B′C′, the column 2, 6, 14, 10 forms CD′, and 5 and 7 pair as A′BD — 3 terms and 7 literals. Six prime implicants exist, but B′D′ and the others are redundant. Grouping the six 0s gives a 3-term POS with 9 literals, so SOP is cheaper here.

BCD input greater than 4, using don’t-cares

Codes 10–15 never occur in BCD, so they are don’t-cares. Treating them as 1s lets 8–15 merge into A, and 5, 7, 13, 15 and 6, 7, 14, 15 into BD and BC — the classic “greater than 4” detector A + BC + BD. The POS form also needs 5 literals, for example (A + B)(A + C + D).

Three-variable majority function

The output is 1 when at least two inputs are 1. Each pair of adjacent 1s around minterm 7 forms a two-literal term, giving AB + AC + BC; the dual POS form is (A + B)(A + C)(B + C).

Frequently asked questions

How does a Karnaugh map simplify a Boolean expression?+

Cells are arranged in Gray-code order so adjacent cells differ by one variable. Grouping 1, 2, 4, 8 or 16 adjacent 1s (including wrap-around edges) removes the variables that change within the group, leaving a shorter product term for each group.

What are don’t-care conditions?+

Input combinations that never occur or whose output does not matter, such as BCD codes 10–15. They are marked X on the map and may be included in a group when that makes the group larger, but they never need to be covered.

Can a K-map handle 5 or 6 variables?+

Yes, but drawn maps get awkward: 5 variables need two 4×4 maps and 6 need four, with adjacency between the layers. This solver uses the Quine–McCluskey algorithm, which handles up to 6 variables exactly without having to spot cross-layer groups.

What is the difference between SOP and POS?+

Sum of products is an OR of AND terms built from the 1s, natural for AND-OR or NAND-NAND logic. Product of sums is an AND of OR terms built from the 0s, natural for OR-AND or NOR-NOR logic. Either can be smaller, so compare the literal counts.

Is the minimal expression unique?+

Not always. Some functions (with cyclic prime implicant charts) have several different covers with the same number of terms and literals. All are equally minimal; the solver returns one of them.

Which variable is the most significant bit?+

The first variable (A by default) is the most significant bit. For four variables minterm 9 is binary 1001, so it is AB′C′D. Rename variables in the names field if your truth table uses a different order.

Related tools