Gray code: meaning and examples
Gray code is an ordering of binary numbers in which consecutive values differ in exactly one bit: 00, 01, 11, 10. Karnaugh maps label their rows and columns in this order so that neighbouring cells differ in one variable.
In ordinary binary counting, 01 is followed by 10, a change of two bits at once. Gray code, named after Frank Gray, reflects the sequence instead: 00, 01, 11, 10, and the sequence wraps, since 10 and 00 again differ in one bit. For four variables a map uses the two-bit Gray sequence on both axes, so each cell has four neighbours differing in one variable each, including across the edges. That is what makes the grouping rule work: adjacent cells can be merged because only one variable changes between them.
The artefact on this page is Σm(A, B, C, D; 0, 2, 8, 10), whose four true cells are the four corners of a four-variable map. In Gray-code order the corners are neighbours: cells 0 and 2 differ only in C, cells 0 and 8 only in A. The engine's map finds a single group of those four cells and derives NOT B AND NOT D, two literals for four minterms, 1 prime implicant, no don't-cares, equivalent on every assignment. The satisfiable witness A = FALSE, B = FALSE, C = FALSE, D = FALSE is cell 0.
Beyond maps, Gray code is used in rotary encoders and in error-tolerant counters, where a one-bit change per step avoids transient wrong readings. The term is confused with binary order, which is why a map drawn with columns 00, 01, 10, 11 produces wrong groups, and it is sometimes assumed to be a single sequence, whereas any ordering with the one-bit property is a Gray code.
Example
f := Σm(A, B, C, D; 0, 2, 8, 10) · output
Exact checks
Truth table (16 rows)
| # | A | B | C | D | f |
|---|---|---|---|---|---|
| 0 | FALSE | FALSE | FALSE | FALSE | TRUE |
| 1 | FALSE | FALSE | FALSE | TRUE | FALSE |
| 2 | FALSE | FALSE | TRUE | FALSE | TRUE |
| 3 | FALSE | FALSE | TRUE | TRUE | FALSE |
| 4 | FALSE | TRUE | FALSE | FALSE | FALSE |
| 5 | FALSE | TRUE | FALSE | TRUE | FALSE |
| 6 | FALSE | TRUE | TRUE | FALSE | FALSE |
| 7 | FALSE | TRUE | TRUE | TRUE | FALSE |
| 8 | TRUE | FALSE | FALSE | FALSE | TRUE |
| 9 | TRUE | FALSE | FALSE | TRUE | FALSE |
| 10 | TRUE | FALSE | TRUE | FALSE | TRUE |
| 11 | TRUE | FALSE | TRUE | TRUE | FALSE |
| 12 | TRUE | TRUE | FALSE | FALSE | FALSE |
| 13 | TRUE | TRUE | FALSE | TRUE | FALSE |
| 14 | TRUE | TRUE | TRUE | FALSE | FALSE |
| 15 | TRUE | TRUE | TRUE | TRUE | FALSE |
Plain-language reading
Beginnerf is true exactly when the truth-table row of (A, B, C, D) is one of the rows 0, 2, 8, and 10.
In every other case, f is false.
About the operators:
- Σm lists the truth-table rows (minterms) where the formula is true. Rows are numbered from 0 with the first listed input as the most significant bit.
Intermediatef is true exactly when the truth-table row of (A, B, C, D) is one of the rows 0, 2, 8, and 10.
In every other case, f is false.
Advancedf is true exactly when the truth-table row of (A, B, C, D) is one of the rows 0, 2, 8, and 10 [canonical sum of minterms (DNF)].
In every other case, f is false.
Formal notation: Σm(A, B, C, D; 0, 2, 8, 10)
Karnaugh map
- cells m0, m2, m8, m10
NOT B AND NOT D
The common slip
Labelling map columns in counting order, 00, 01, 10, 11. The middle two then differ in two bits, cells that look adjacent are not, and a group that spans them is not a single term. The Gray order 00, 01, 11, 10 is the whole point of the map.
Questions
Why are the corners of a map adjacent?
Because Gray code wraps: the first and last labels, 00 and 10, differ in one bit, so the leftmost and rightmost columns are neighbours, and so are the top and bottom rows. The four corners form a legal group of four, as this page shows.
Related
Guides
See also
- Karnaugh map (K-map): meaning and examples
- Karnaugh map grouping rule: adjacent cells drop the variable that changes
- Karnaugh map solver: 2 to 4 variables, groups, SOP and POS, don’t-cares from assumptions
- Lesson 11: Karnaugh maps (advanced, 15 min)
- Karnaugh map exercises with answers: 4 variables
- Four-variable K-map: Σm(0, 2, 5, 7, 8, 10, 13, 15) simplified
Glossary
Generated from the Tangibool engine, semantics tangibool-semantics/1, engine 1.0.0, build . Every table, map, simplification and verdict on these pages was computed by the Tangibool engine when the site was built, and every claim was re-checked by the same exact checker the app uses. Limits are stated where they apply. © 2026 Foreranger LTD.