{
  "slug": "variable-length-integer",
  "term": "Variable-length integer",
  "aliases": [
    "Varint",
    "Variable-width integer"
  ],
  "definition": "A variable-length integer encoding represents integer values using different numbers of bytes according to the format's rules.",
  "note": "Formats: Varint is not one interoperable encoding. Protobuf uses least-significant seven-bit groups first, with a continuation bit and a one-to-ten-byte unsigned 64-bit representation. [varint-protobuf]\n\nSQLite: Its file-format varints use most-significant groups first and at most nine bytes; the ninth contributes eight payload bits. Rowids and record headers use varints, but integer column payloads use widths selected by serial types, including zero-byte encodings of 0 and 1. [varint-sqlite]\n\nInterpretation: The integer 150 gives hexadecimal 96 01 in Protobuf and 81 16 in SQLite. These are integer-field bytes, excluding tags and surrounding metadata. Select the encoding and field type before decoding.\n\nSize: Small magnitudes can use fewer bytes, but an unsigned 64-bit maximum needs ten Protobuf bytes rather than eight fixed-width bytes. Signed values require a specified mapping such as ZigZag. [varint-protobuf]",
  "related": [
    "zigzag-encoding",
    "data-serialization",
    "byte-order",
    "stream-vbyte",
    "protocol-buffers"
  ],
  "citations": [
    {
      "id": "varint-protobuf",
      "title": "Protocol Buffers encoding: Base 128 Varints and Signed Integers",
      "url": "https://protobuf.dev/programming-guides/encoding/",
      "accessed": "2026-11-17"
    },
    {
      "id": "varint-sqlite",
      "title": "SQLite database file format: B-tree varints and record serial types, sections 1.6 and 2.1",
      "url": "https://sqlite.org/fileformat.html",
      "accessed": "2026-11-17"
    }
  ],
  "status": "unknown",
  "advantages": [],
  "limitations": [],
  "supersedes": [],
  "supersededBy": [],
  "firstSeen": null,
  "lastSeen": null,
  "updated": "2026-11-21",
  "provenance": [
    "Source synthesis and exact integer examples, not a full serializer or a native decoder conformance test.",
    "Executable examples and controls: https://hesela.dev/research/varint-contracts.mjs and https://hesela.dev/research/varint-contracts.test.mjs."
  ]
}
