{
  "slug": "hamming-distance",
  "term": "Hamming distance",
  "aliases": [
    "Hamming metric"
  ],
  "definition": "Hamming distance counts the symbol positions in which two equal-length sequences differ.",
  "note": "For a binary code, minimum distance is the smallest number of bit inversions separating any two distinct codewords; it defines a guaranteed detection bound, not an observed error rate. A code with distance HD detects every pattern of up to HD-1 inverted bits, so HD=6 rules out undetected 1- to 5-bit errors. [koopman04]\n\nFor a fixed CRC polynomial, minimum distance can decrease as the data word grows. The IEEE 802.3 CRC-32 polynomial gives HD of at least 8 up to 91 data bits, HD=7 to 171 bits, HD=6 to 268 bits, HD=5 to 2974 bits, HD=4 to 91,607 bits and HD=3 to at least 128K bits. [koopman02]\n\nAt a 12,112-bit data word, the size used for a maximum-length Ethernet frame, the same polynomial detects all 2- and 3-bit errors but misses 223,059 of about 906 x 10^12 possible 4-bit errors across the 12,144-bit codeword. [koopman02]\n\nLet n count codeword bits including the CRC, and A_w count undetectable masks with exactly w flipped positions. For 1 <= w <= n, the fraction A_w / C(n,w) applies to uniformly selected weight-w masks; it does not depend on the bit-flip probability. Overall undetected-corruption probability additionally requires an error model. [rfc3385] [koopman02]",
  "status": "shipping",
  "advantages": [
    {
      "text": "Gives a worst-case guarantee that holds for every error pattern below the distance, wherever the inverted bits fall.",
      "citationIds": [
        "koopman04"
      ]
    }
  ],
  "limitations": [
    {
      "text": "A distance holds only for a stated data word length, so one polynomial has different distances at different message sizes.",
      "citationIds": [
        "koopman02"
      ]
    },
    {
      "text": "Full-codeword pattern counts include changes to CRC bits; a model restricted to data positions must restrict both its undetectable-mask count and its denominator.",
      "citationIds": [
        "koopman02"
      ]
    }
  ],
  "related": [
    "flip-n-write",
    "cyclic-redundancy-check",
    "crc32c",
    "crc-burst-error",
    "error-and-erasure-decoding",
    "interleaved-parity",
    "stopping-distance"
  ],
  "supersedes": [],
  "supersededBy": [],
  "firstSeen": null,
  "lastSeen": null,
  "citations": [
    {
      "id": "koopman04",
      "title": "Koopman and Chakravarty. CRC Polynomial Selection For Embedded Networks. DSN 2004, sections 2-4",
      "url": "https://users.ece.cmu.edu/~koopman/roses/dsn04/koopman04_crc_poly_embedded.pdf",
      "accessed": "2026-10-22"
    },
    {
      "id": "hesela-crc",
      "title": "Hesela: CRC polynomials, constructed error patterns and exact small-code enumeration",
      "url": "https://hesela.com/analyses/crc-polynomials-error-patterns/",
      "accessed": "2026-10-18"
    },
    {
      "id": "koopman02",
      "title": "Koopman. 32-Bit Cyclic Redundancy Codes for Internet Applications. DSN 2002, sections 1-3",
      "url": "https://users.ece.cmu.edu/~koopman/networks/dsn02/dsn02_koopman.pdf",
      "accessed": "2026-10-22"
    },
    {
      "id": "rfc3385",
      "title": "Sheinwald et al. RFC 3385: iSCSI CRC/Checksum Considerations, sections 2-3 (2002)",
      "url": "https://www.rfc-editor.org/rfc/rfc3385.html",
      "accessed": "2026-10-27"
    }
  ],
  "updated": "2026-11-29",
  "provenance": [
    "koopman04 is Koopman and Chakravarty, DSN 2004, read in sections 2 to 4.",
    "koopman02 is Koopman, DSN 2002, read in sections 1 to 3 and Table 1.",
    "The 802.3 lengths 91, 268, 2974 and 91,607 bits, 12,112 and 12,144 bits, 223,059 and 906 x 10^12 come from koopman02.",
    "The fixed-weight fraction follows by conditioning RFC 3385 section 3 on exactly w flips. The DSN 2002 count includes CRC bits and is not a measured storage error rate."
  ]
}
