Home › Developer Tools › Karnaugh Map Solver

Karnaugh Map Solver

Build a Karnaugh map by clicking cells or typing minterms and don't-cares, and get the minimal sum-of-products or product-of-sums expression instantly. Every group is outlined on the map in its own color, including groups that wrap around the edges.

Last updated:

Variables

Click a cell to cycle 0 → 1 → X (don't care). With a cell focused, type 1, 0 or X, and use the arrow keys to move.

    Truth table and canonical forms
    Advertisement
    Advertisement

    How to use the Karnaugh Map Solver

    1. Choose the number of variables (2 to 6) and, if you like, rename them (for example X Y Z or S1 S0 EN).
    2. Fill the map: click cells to cycle 0 → 1 → X, or type the minterms and don't-cares (ranges like 10-15 work) and press Solve.
    3. Read the answer: the minimal expression appears on the right and every group is outlined on the map in the matching color.
    4. Switch to POS to group the zeros and get the minimal product of sums instead.
    5. Copy the expression in the notation you need, or open the truth table to check each row.

    Karnaugh map layouts and minterm numbering

    Minterm numbers come from reading the variables as a binary number with the first variable as the most significant bit, so with A, B, C, D the cell A=1, B=0, C=1, D=1 is minterm 1011₂ = 11. Rows and columns follow the Gray code 00, 01, 11, 10, which is why minterms 2 and 3 appear in swapped order on the map.

    VariablesMap layoutRows × columnsCellsLargest group
    2A down, B across2 × 244 (F = 1)
    3A down, BC across2 × 488
    4AB down, CD across4 × 41616
    5two 4 × 4 maps (A = 0, 1); BC down, DE across2 × (4 × 4)3232
    6four 4 × 4 maps (AB = 00, 01, 11, 10); CD down, EF across4 × (4 × 4)6464

    Grouping rules

    • Groups must be rectangles whose size is a power of two: 1, 2, 4, 8, 16 or 32 cells.
    • The map wraps around: the left edge touches the right edge and the top touches the bottom, so the four corners of a 4×4 map form one group.
    • Make every group as large as possible (these are the prime implicants) and use as few groups as possible to cover every 1.
    • Groups may overlap, and they may include don't-care cells, but no group may contain a 0 (or a 1 when grouping zeros for POS).
    • A group of 2k cells removes k variables: in a 4-variable map, a pair gives a 3-literal term, a quad 2 literals and an octet 1 literal.

    Worked example: for the default map m(0, 1, 2, 5, 6, 7, 8, 9, 10, 14) the solver finds F = B'C' + CD' + A'BD: three terms and seven literals. B'C' is a quad that wraps from the top row to the bottom row (cells 0, 1, 8, 9), CD' is the whole right-hand column (cells 2, 6, 10, 14), and A'BD picks up the remaining pair 5 and 7.

    Frequently asked questions

    What is a Karnaugh map?

    A Karnaugh map (K-map) is a grid of a Boolean function's truth table arranged in Gray-code order, so that neighboring cells differ in exactly one variable. Groups of 1, 2, 4, 8, 16 or 32 adjacent 1-cells correspond to product terms where the variables that change are eliminated, which makes it easy to find a simplified expression by eye. Maurice Karnaugh introduced it in 1953.

    How does the solver find the minimal expression?

    It runs the Quine–McCluskey method to list every prime implicant (the largest possible groups), picks the essential prime implicants that are the only cover for some 1-cell, and then searches all remaining combinations to find the cover with the fewest terms and, among those, the fewest literals. That is the same answer you aim for with careful grouping on the map, without the risk of missing a wrap-around group.

    What are don't-care conditions?

    Don't-cares (X) are input combinations whose output does not matter, usually because they can never occur, such as the BCD codes 10 to 15. The solver may include them in a group when that makes the group bigger, but it never needs to cover them, which often gives a simpler circuit.

    How do 5 and 6 variable K-maps work?

    A 5-variable map is drawn as two 4×4 maps for A = 0 and A = 1, and a 6-variable map as four 4×4 maps for AB = 00, 01, 11 and 10. Cells in the same position on neighboring maps are adjacent, so a group can span maps. The solver handles this automatically and outlines each group on every map it touches.

    What is the difference between SOP and POS?

    Sum of products (SOP) ORs together AND terms and is found by grouping the 1s, for example F = AB' + C. Product of sums (POS) ANDs together OR terms and is found by grouping the 0s, for example F = (A + C)(B' + C). Both describe the same function; which is smaller depends on the function, and POS maps naturally to NOR-NOR logic while SOP maps to NAND-NAND.

    Why are there several minimal answers?

    Some functions have more than one cover with the same number of terms and literals, typically when a 1-cell can be covered by two different prime implicants of the same size. All of them are equally minimal; use Show another solution to step through them.

    Are all the tools on FreeToolCabin tested for quality and accuracy?

    Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.

    Related tools

    Binary CalculatorAdd, subtract, multiply, divide, AND, OR, XOR and shift binary numbers with decimal values.Bitwise CalculatorCalculate AND, OR, XOR, NOT and bit shifts at 8–64 bits with a bit grid and all bases.Binary to DecimalConvert binary to decimal instantly with steps and signed mode.Sorting Algorithm VisualizerWatch bubble, insertion, merge, quick, heap and radix sort step by step with live counters.JSON to Excel ConverterTurn JSON into a styled .xlsx spreadsheet; nested arrays become their own linked sheets.JSON to CSVConvert JSON data to CSV for spreadsheets.CSV to JSONConvert CSV data to JSON with live preview.Excel to CSVConvert XLSX spreadsheets to CSV.CSV ViewerOpen a CSV or TSV file as a sortable, filterable table.Excel Viewer (XLSX / XLS)Open XLSX, XLS and ODS spreadsheets in your browser without Excel.Line Ending ConverterConvert text and files between CRLF, LF and CR line endings.Markdown to HTMLConvert Markdown to clean HTML with a live editor.XML to JSONConvert XML to JSON with validation.Text Encoding ConverterDetect and convert text file encodings like UTF-8, UTF-16 and Latin-1.JSON ViewerExplore JSON as a collapsible tree, search keys and values and copy any node's path.TTF to WOFF2 ConverterConvert TTF and OTF fonts to WOFF2 or WOFF and get a ready @font-face CSS snippet.Chmod CalculatorConvert Linux file permissions between checkboxes, octal (755) and symbolic (rwxr-xr-x) notation.JSON to TypeScriptGenerate TypeScript interfaces or types from JSON, with nested types and optional fields.Morse Code TranslatorTranslate text to Morse code and back, then play it as sound or a blinking light, or save a WAV.HTML Table GeneratorBuild HTML tables in an editable grid with styles, header rows, CSV import and live preview.Hex to Text ConverterConvert hex to text and text to hex with UTF-8 support and space, 0x, \x or comma formats.JSON to XML ConverterConvert JSON to well-formed XML with attributes, arrays and pretty print.JSON to YAML ConverterConvert JSON to clean YAML as you type, with indent, quoting and sort options.YAML to JSON ConverterConvert YAML to pretty or minified JSON, with errors pinned to the exact line.HTML to Markdown ConverterTurn HTML or pasted rich text into clean Markdown with tables and live preview.Markdown Table GeneratorBuild Markdown tables in a grid or paste from Excel/CSV, with alignment and preview.JSON ValidatorCheck JSON with the exact line and column of each error, fix tips and one-click auto-fix.Image to Base64Convert images to Base64 data URIs, CSS backgrounds and HTML img tags in your browser.Base64 to ImagePaste a Base64 string or data URI to preview, identify and download the image.JSON CompareCompare two JSON documents and see every added, removed and changed path.Hex to DecimalConvert hex to decimal instantly with steps and signed mode.Decimal to HexConvert decimal to hex instantly with steps and signed mode.Decimal to BinaryConvert decimal to binary instantly with steps and signed mode.Two's Complement CalculatorDecimal to two's complement binary and back for 4-64 bits, with invert-and-add-1 steps.XML to CSV ConverterConvert XML to CSV: detects repeating records, flattens nested data, pick your columns.CSV to XML ConverterConvert CSV to well-formed XML with custom root and row names, escaping and pretty print.TOML to JSON ConverterConvert TOML to JSON and JSON to TOML with a full v1.0 parser and clear error lines.JSON to Go StructTurn JSON into Go structs with inferred types, nested structs and json tags.JSON Merge ToolDeep-merge two or more JSON objects with array concat, replace or union and a conflict rule.JSONL to CSV ConverterConvert JSON Lines / NDJSON to CSV with flattened columns; streams large files locally.PHP Unserialize OnlineDecode PHP serialize() strings to JSON, a tree or print_r, and serialize JSON back to PHP.SQL Dialect ConverterTranslate SQL between MySQL, PostgreSQL, SQLite, SQL Server, Oracle, BigQuery and more.TSV to JSON ConverterTurn tab-separated data pasted from Excel or Sheets into a JSON array or keyed object.XLS to XLSX ConverterConvert old Excel 97-2003 .xls workbooks to modern .xlsx files in your browser, several at once.XML to Excel ConverterTurn repeating XML elements into an .xlsx spreadsheet with attributes and nested data as columns.XSD to XML Sample GeneratorGenerate a sample XML document from an XSD schema, with types, attributes and namespaces.YAML to CSV ConverterTurn a YAML list of objects into CSV with dot-notation columns, custom column order and download.DOCX to Markdown ConverterConvert Word .docx to clean Markdown with headings, lists, tables, links and images in a ZIP.ES6 to ES5 ConverterTranspile modern JavaScript (ES2015+) to ES5 with Babel: targets, module format and loose mode.JavaScript Object to JSONTurn JS object literals and Python dicts into valid JSON: quotes keys, fixes commas and values.JSON Graph VisualizerSee JSON as an interactive node graph with zoom, collapse and search; export PNG or SVG.KML ViewerOpen KML and KMZ files on an interactive map: placemarks, paths, polygons, folders, export.MySQL to PostgreSQL ConverterConvert MySQL dumps and CREATE TABLE statements to PostgreSQL: types, AUTO_INCREMENT, ENUMs, quotes.Text to CSV ConverterTurn space-aligned, fixed-width, pipe or tab separated text into clean CSV with a live preview.VCF File ViewerOpen vCard .vcf files as contact cards with photos, search and duplicate check, export CSV.XML ViewerBrowse XML as a collapsible tree with search, XPath of any node, attributes and big-file support.JSON to Python ClassGenerate Python dataclasses, Pydantic models or TypedDicts with type hints from JSON.JSON to C# ClassConvert JSON to C# classes or records with System.Text.Json or Newtonsoft attributes.JSON SorterSort JSON keys A-Z recursively, sort arrays by value or by a key, then pretty-print or minify.JSON to HTML TableConvert a JSON array of objects into clean HTML table code with CSS styles and a live preview.CSV to SQL ConverterConvert CSV to SQL CREATE TABLE and INSERT statements for MySQL, PostgreSQL, SQLite or SQL Server.IPv4 to IPv6 ConverterConvert IPv4 to IPv4-mapped, 6to4 and NAT64 IPv6, extract IPv4 from IPv6, and get int/hex/binary.cURL to Code ConverterConvert curl commands to JavaScript fetch, Axios, Python requests, Node.js, PHP and Go code.Code to ImageTurn code into a beautiful syntax-highlighted PNG with themes, window frame and background.Excel to JSON ConverterConvert Excel sheets (XLSX, XLS, ODS) to JSON with header row, type and shape options.CSV to Excel ConverterConvert CSV files to a real .xlsx workbook with typed numbers and dates, one sheet per file.CSV SplitterSplit a large CSV into smaller files by row count, file count or column value, header kept.CSV MergerCombine many CSV files into one, matching columns by name, with dedupe and a source column.
    See all 129 Data & File Format Converters →