Why K-maps use Gray code and wrap around at the edges
By K-Map Solver · · 2 min read

In this article
The first thing people notice about a K-map is that the labels run 00, 01, 11, 10 rather than 00, 01, 10, 11. That odd order is the whole trick behind the method.
Why plain binary order does not work
Going from 01 to 10 in ordinary binary flips two bits at once. Two cells that look like neighbours on the page would then differ in two variables, and merging them would be wrong. A K-map only works if every pair of touching cells differs in exactly one variable, because that is when two product terms combine into one with a variable removed.
Gray code
A Gray code is a counting order in which each step changes a single bit. For two bits it is 00, 01, 11, 10. For three bits it is 000, 001, 011, 010, 110, 111, 101, 100. The labels along a K-map's rows and columns use exactly this order, so each step to the next cell flips one variable.
Why the edges wrap
Look at the end of the two-bit sequence: it finishes at 10 and would start again at 00, and those differ in one bit too. The sequence is a loop, so the last row is a neighbour of the first, and the last column is a neighbour of the first. A K-map is really a doughnut shape, a torus, drawn flat.
On a 4×4 map this has two practical consequences. A group may leave one edge and re-enter on the opposite one, and the four corners are all neighbours of each other. Textbooks and this solver draw such a group with open brackets at the map edge to show that it continues on the other side.
Worked example: sum of products
Cells 0, 2, 8 and 10 look unrelated, yet they share B = 0 and D = 0: one term, B'D'.
F = Σm(0, 2, 8, 10)
Simplified result
F = B'D'
- B'D' — minterms (0, 2, 8, 10)
Worked example: sum of products
Cells 0 and 1 in the top row pair with 8 and 9 in the bottom row, giving B'C'.
F = Σm(0, 1, 8, 9)
Simplified result
F = B'C'
- B'C' — minterms (0, 1, 8, 9)
A habit that prevents missed groups
After you have grouped everything you can see, deliberately look at each edge and corner and ask: does this cell have a neighbour on the other side? Most missed simplifications in exam answers are wrap-around groups.