Skip to content
DenseChip
Learn
PracticeCode labInterview

DenseChip

Navigate

Menu

LearnPracticeCode labInterview

Tools

All toolsSV editorCode repoResume
DenseChip

Practice, courses, and chip-design tools in one focused workspace.

LearnPracticeCode labInterviewToolsLearning paths

© 2026 DenseChip

AboutRoadmapCareersInternshipsFAQContactPrivacyTerms
Skip to lesson

Course contents

  • RTL Foundations36
    • Digital Logic for RTL Engineers
      • Algebra Before Gates
      • The Identity Toolkit
      • De Morgan Rules
      • Truth Tables as a Debug Anchor
      • K-Map Intuition
      • Implementation Trade-offs
    • Number Systems for RTL Engineers
    • Verilog Fundamentals
    • Verilog Operators and Types
    • SystemVerilog for RTL
    • Simulation and Testbenches
  • Combinational Design25
  • Sequential Design27
  • FSM & Control27
  • Timing & Clocking39
  • Reset & CDC34
  • Memory & Buses57
  • Advanced RTL28
  • Senior & Interview76
  • Glossary and Notation
Loading lesson

←Digital Logic for RTL Engineers
  1. Topics
  2. RTL Design
  3. RTL Foundations
  4. Digital Logic for RTL Engineers
  5. K-Map Intuition
On this page

    Part 1 of 9, lesson 5 of 36Part 1 of 9/Foundations/Lesson 5 of 36Beginner

    K-Map Intuition

    Group neighboring 1s in powers of two to cancel variables, use don't-cares safely, and know where maps stop scaling.

    A Karnaugh map shows at a glance which inputs a function really depends on. In the worked example, eight minterms of a four-input function collapse to two terms, and two of the inputs turn out not to matter at all.

    After this lesson you can: group adjacent cells on a four-variable map, read off the terms, and use don't-cares without breaking inputs that can occur.

    What a K-map shows

    A Karnaugh map redraws a truth table so cells differing in exactly one variable sit next to each other.

    That adjacency is the visual form of x·a + x·a′ = x. Two neighbouring 1s let one variable cancel, so grouping neighbours is simplification.

    Row and column labels use Gray code (00, 01, 11, 10). Consecutive labels differ by one bit.

    Edges wrap around. The left and right columns are neighbours, and so are the top and bottom rows.

    A four-variable example

    Let f(a,b,c,d) be 1 for minterms 0, 2, 5, 7, 8, 10, 13 and 15.

    Here is the map, with rows labelled by ab and columns by cd:

    ab \ cd

    00

    01

    11

    10

    00

    1

    0

    0

    1

    01

    0

    1

    1

    0

    11

    0

    1

    1

    0

    10

    1

    0

    0

    1

    A is one wrapping group, not four separate groups. The arrows join opposite edges: first and last columns are neighbours, as are first and last rows. B is an ordinary rectangle.

    Follow the outlines rather than the visual distance between cells. The corner group wraps in both directions; neither arrow makes diagonal cells adjacent. It is a two-by-two rectangle across the map's edges.

    • The four corners (minterms 0, 2, 8, 10) are all adjacent because the map wraps. Inside the group b = 0 and d = 0 stay fixed while a and c change, so the group is b′d′.

    • The centre block (5, 7, 13, 15) has b = 1 and d = 1 fixed: bd.

    Keep fixed variables; cancel changing variables

    Group

    abcd patterns

    a

    b

    c

    d

    Term

    A: corners

    0000, 0010, 1000, 1010

    0 and 1: drop

    Always 0: keep b′

    0 and 1: drop

    Always 0: keep d′

    b′d′

    B: centre

    0101, 0111, 1101, 1111

    0 and 1: drop

    Always 1: keep b

    0 and 1: drop

    Always 1: keep d

    bd

    Drop: a​,c​A keeps: b′,d′B keeps: b,d

    This is not arbitrary deletion. Each rectangle contains every combination of the changing variables. For A, factor the four minterms:

    a′b′c′d′+a′b′cd′+ab′c′d′+ab′cd′=b′d′(a′+a)(c′+c)=b′d′

    For B the same cancellation leaves the uncomplemented fixed variables:

    a′bc′d+a′bcd+abc′d+abcd=bd(a′+a)(c′+c)=bd

    So f = b′d′ + bd, which is simply XNOR of b and d. Eight 4-input minterms became two 2-literal terms, and a and c turned out not to matter at all.

    kmap_check.sv
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    module kmap_check;
      logic a, b, c, d;
      logic f_minterms, f_min;
    
      always_comb begin
        case ({a, b, c, d})
          4'd0, 4'd2, 4'd5, 4'd7, 4'd8, 4'd10, 4'd13, 4'd15: f_minterms = 1'b1;
          default:                                           f_minterms = 1'b0;
        endcase
        f_min = (~b & ~d) | (b & d);        // the K-map result
      end
    
      int errors = 0;
      initial begin
        for (int i = 0; i < 16; i++) begin
          {a, b, c, d} = i[3:0];
          #1;
          if (f_minterms !== f_min) begin
            $display("FAIL: mismatch at %0d", i);
            errors++;
          end
        end
        if (errors == 0) $display("PASS: K-map result verified for all 16 inputs");
        $finish;
      end
    endmodule

    Grouping rules

    1. Groups contain only 1s (or don't-cares) and have size 1, 2, 4, 8 or 16: always a power of two.

    2. Each group must be a rectangle, allowing edge wrapping, with power-of-two height and width. Its cells form a Boolean subcube: every combination of the changing variables is included. An L shape or diagonal is not a group, even if its cell count is a power of two.

    3. Make groups as large as possible: a bigger group cancels more variables.

    4. Cover every 1 at least once, using as few groups as possible. Overlap is allowed.

    5. Edges wrap: treat the map as the surface of a torus.

    A group of 2ᵏ cells removes k variables. The corner and centre groups above each have 4 = 2² cells, so each removed two variables.

    Four cells are not necessarily a group

    The next two maps show a different function, with ones only at minterms 0, 1, 4 and 12. First try enclosing all four ones. Then replace that invalid outline with legal, overlapping pairs.

    The dashed L is invalid. Keeping only c′ would also include minterms 5, 8, 9 and 13, which are zeros in this function.
    Each outline contains two adjacent ones and no zeros. Overlap is allowed: minterm 0 belongs to the solid and dashed pairs; minterm 4 belongs to the dashed and dotted pairs.

    Pair

    Patterns

    Changing variable

    Remaining term

    0, 1

    0000, 0001

    d

    a′b′c′

    0, 4

    0000, 0100

    b

    a′c′d′

    4, 12

    0100, 1100

    a

    bc′d′

    OR the three terms to obtain a correct cover: f = a′b′c′ + a′c′d′ + bc′d′. Now minimize the cover: the solid pair already covers 0 and 1, and the dotted pair covers 4 and 12. The dashed pair adds no uncovered one, so its term is redundant. The minimal cover is f = a′b′c′ + bc′d′. A valid group need not be necessary; retain enough groups to cover every one, without covering any zero.

    Check yourself Can minterms 0, 1, 4 and 12 form one four-cell group on a four-variable map?

    No. They form a connected L shape, not a wrapping rectangle. Only c = 0 is common to all four; cancelling three variables would cover eight minterms, including zeros. Use the valid pairs (0,1), (0,4) and (4,12) instead. A power-of-two cell count alone does not justify cancelling variables.

    Check yourself The pair (4,12) contains 0100 and 1100. Which variable cancels, and what term remains?

    a changes while b=1, c=0 and d=0 stay fixed. Therefore a cancels and the pair contributes bc′d′. Keeping a would cover only one cell; dropping another variable would include an unwanted zero.

    Don't-cares

    Cells marked X are inputs that never occur. Treat each X as a 1 if that makes a bigger group, and as a 0 otherwise.

    In the BCD “is even” example, inputs 10 to 15 are don't-cares. Including them lets the whole function collapse to ~d (the least significant bit is 0).

    The two outlined strips wrap into one eight-cell group. They contain the required ones 0,2,4,6,8 and the optional X cells 10,12,14; no required zero is included. The other X cells need not be used.

    Variable

    Values inside the group

    Keep it?

    a, b, c

    Each takes both 0 and 1

    No: all three cancel

    d

    Always 0

    Yes: the term is ~d

    Check yourself Why may X cells 10,12,14 join this group, but valid BCD code 9 may not?

    10,12,14 are outside the promised BCD input range, so their outputs can be chosen to enlarge the group. Code 9 is valid and odd, requiring output 0. Including it would change the specified function.

    Only mark a cell as don't-care if the system truly can never present that input, and ideally check it with an assertion. Using don't-cares to “make the logic smaller” for inputs that can actually happen is a bug that simulation, which sees x, may not reveal.

    Try it: group the cells

    The map starts on the four-variable example above (1s at minterms 0, 2, 5, 7, 8, 10, 13 and 15), so it shows the corner group b′d′ and the centre group bd. Click a cell to cycle it 0, 1, x; the tool keeps the fewest terms, then the fewest literals.

    K-map and truth table

    Loading k-map…

    Rows are ab and columns cd in Gray order; each cell shows its minterm number. Each outline is one product term, and a group that wraps an edge is drawn as separate pieces.
    • Set cell 15 (ab = 11, cd = 11) to 0: the centre square breaks and f = a′bd + b′d′ + bc′d, three terms instead of two.

    • Back on the starting map (press Reset), set cells 3, 9 and 11 to 1: f needs four terms. Now click cell 1 twice to make it x: it completes an eight-cell group and f = b′ + d.

    • Set Inputs to 3 and make cells 3, 5, 6 and 7 equal to 1: the majority function, f = ab + ac + bc.

    Where K-maps stop

    • Practical up to 4 variables, awkward at 5, hopeless beyond 6. Real blocks have dozens of inputs.

    • Synthesis tools use algorithms (Espresso-style two-level minimization and multi-level restructuring) that do the same job at scale and also consider shared logic and delay.

    • The value of the K-map is intuition: you learn to see which inputs a function really depends on, which is what you need when reviewing or reducing RTL.

    Check yourself Why are the K-map labels in Gray code (00, 01, 11, 10) and not in binary order?

    Gray code guarantees that neighbouring labels differ in exactly one bit. Adjacent cells then differ in one variable, which is exactly the condition for a variable to cancel when you merge them. With binary order (00, 01, 10, 11), cells 01 and 10 would sit side by side but differ in two bits.

    Check yourself A 3-variable map has a group of 4 cells. How many literals does its product term have?

    Three variables minus the 2 that cancel (a 4-cell group is 2²) leaves 1 literal. For example, the four cells with a = 1 reduce to just a.

    • Gray-code labels make neighbours differ by one variable, so a group of 2^k cells cancels k variables.

    • Groups are rectangles of 1s (or don't-cares) in powers of two, and they wrap at the edges.

    • Mark a cell don't-care only if the system can never present that input, and check it with an assertion.

    Rule of thumb: keep the variables that stay fixed in the group and drop the ones that change.

    • Interview: run a mock interview on this topic

    Related topics

    • The identity toolkit — the algebra behind grouping

    • Implementation trade-offs

    Previous

    5 / 350

    Next: Implementation Trade-offs

    Up next

    Up nextImplementation Trade-offs

    Sign in to save progress

    Practice this lessonPrevious lessonReport an error

    See also

    • Algebra Before Gates
    • The Identity Toolkit
    • De Morgan Rules