Karnaugh Map (K-map) Calculator

Simplify Boolean expressions using a K-map. Select the number of variables, then toggle cells to build your K-map.


How to use the k-map calculator

The K-map is used to simplify Boolean algebra expressions. You can toggle each cell (by clicking) to set it as 1, 0, or X (don't care condition). After setting the K-map, click "Simplify" to get the minimal Boolean expression.

In-depth Tutorial: How to Solve K-maps

Karnaugh Maps (K-maps) are graphical tools used to simplify Boolean algebra expressions. They provide a visual method for eliminating redundant variables and finding the most efficient logic expression for a given truth table. K-maps can handle two or more variables, but they are most often used for problems with 2, 3, 4, 5, or 6 variables. Below, we break down the steps for solving a K-map and provide the essential concepts.

1. Understanding K-map Structure

A K-map organizes the truth table into a grid format. Each cell in the K-map corresponds to a minterm of the Boolean function. The number of cells in a K-map depends on the number of variables:

  • 2 variables: 22 = 4 cells (2x2 grid)
  • 3 variables: 23 = 8 cells (2x4 grid)
  • 4 variables: 24 = 16 cells (4x4 grid)
  • 5 variables: 25 = 32 cells (4x8 grid)
  • 6 variables: 26 = 64 cells (8x8 grid)

Each cell represents a unique combination of variables, and its value (0, 1, or X for don't care) comes from the corresponding row of the truth table.

2. Gray Code and Variable Mapping

The K-map uses Gray code for labeling rows and columns. Gray code ensures that adjacent cells differ by only one variable. For example, in a 4-variable K-map, the row and column labels are arranged as:

                Row Labels: 00, 01, 11, 10
                Column Labels: 00, 01, 11, 10
            

Gray code minimizes the transitions between terms, making it easier to group adjacent terms for simplification.

3. Filling the K-map

To fill the K-map:

  1. From the truth table, place a "1" in each cell where the function's output is 1.
  2. Place a "0" where the output is 0.
  3. Use "X" for don't care conditions (optional).

Each cell's value corresponds to the minterm of the Boolean expression for that particular combination of variables.

4. Grouping Adjacent 1s

The next step in solving the K-map is grouping adjacent 1s together. The goal is to create groups of 1s in powers of 2 (1, 2, 4, 8, etc.). Larger groups result in more simplified expressions:

  • Group 1 cell: Represents a minterm with no simplification.
  • Group of 2 cells: Simplifies one variable (e.g., A or A').
  • Group of 4 cells: Simplifies two variables.
  • Group of 8 cells: Simplifies three variables.
  • Group of 16 cells: Simplifies four variables (and so on).

Groups should be as large as possible and can wrap around the edges of the K-map (considering the map as circular). Overlapping groups are also allowed if they simplify the expression.

5. Simplifying the Boolean Expression

After grouping, the next step is to write the simplified Boolean expression:

  1. For each group, determine which variables remain constant (i.e., do not change) across all cells in the group.
  2. Eliminate the variables that change within the group.
  3. Write the simplified product term for the group based on the constant variables.

For example, if grouping two adjacent cells for variables A, B, C, and D, and A is the only variable that stays the same, the product term for that group would be A (or A').

6. The Final Expression

After determining the simplified product term for each group, combine the terms with logical OR operators to form the final minimal Boolean expression. This expression represents the most efficient form of the original Boolean function.

7. Handling Don't Care Conditions (X)

Don't care conditions (X) can be used to further simplify the K-map. You can include Xs in groups of 1s if it helps create larger groups. However, Xs are optional and can be ignored if they don’t aid in simplification.

8. Examples

Example 1: Simplify a 3-variable K-map

                Truth Table:
                A | B | C | F
                ---------------
                0 | 0 | 0 | 1
                0 | 0 | 1 | 1
                0 | 1 | 0 | 0
                0 | 1 | 1 | 1
                1 | 0 | 0 | 1
                1 | 0 | 1 | 0
                1 | 1 | 0 | 1
                1 | 1 | 1 | 0
    
                K-map:
    
                  AB\C  |  0   |   1
                --------------------
                00     |   1   |   1
                01     |   0   |   1
                11     |   1   |   0
                10     |   1   |   0
    
                Grouping:
                - Group the two 1s in the first row (00) -> C'
                - Group the two 1s in the leftmost column -> A'B'
    
                Final Expression: F = C' + A'B'
            

Example 2: Simplify a 4-variable K-map with Don't Care Conditions

                K-map:
    
                  AB\CD  |  00  |  01  |  11  |  10
                -------------------------------
                00      |   1   |   X  |   1   |   1
                01      |   0   |   1  |   X  |   1
                11      |   X   |   0  |   1   |   0
                10      |   1   |   1  |   X   |   0
    
                Grouping:
                - Group the 1s in the bottom-left -> CD' (Row 10)
                - Group the 1s in the first row and last column -> B'D'
                - Group the four 1s in the middle of the map -> AC'
    
                Final Expression: F = CD' + B'D' + AC'
            

9. Tips for solving K-Maps

  • Always look for the largest possible groups of 1s to minimize the expression.
  • Don't forget that K-maps "wrap around," allowing you to group cells on opposite edges of the map.
  • Use don't care conditions strategically to simplify expressions further.
  • Ensure that you understand how to convert between truth tables and K-maps quickly.