variable-length-integer · also Varint, Variable-width integer

Variable-length integer

A variable-length integer encoding represents integer values using different numbers of bytes according to the format's rules.

Related Observatory article: Read on hesela.com

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. [1]

SQLite: 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. [2]

Interpretation: 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.

Size: 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. [1]

Relations

related
ZigZag encoding, Data serialization, Byte order, Stream VByte, Protocol Buffers

Citations

  1. Protocol Buffers encoding: Base 128 Varints and Signed Integers (accessed 2026-11-17)
  2. SQLite database file format: B-tree varints and record serial types, sections 1.6 and 2.1 (accessed 2026-11-17)
Sources & caveats
  • 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.

JSON: /data/terms/variable-length-integer.json

Published by Hesela team · Updated

Report a correction · Editorial standards · Reuse guidance

Cite this page
Hesela team. Variable-length integer. Hesela. 2026-11-21. https://hesela.dev/terms/variable-length-integer/