Protobuf Varint Encoder/Decoder

Encode integers as Protocol Buffers variable-length integers

Ad placeholder (leaderboard)

The Protocol Buffers wire format stores integers as varints — variable-length sequences where small numbers cost a single byte and larger numbers grow gradually. This tool turns any non-negative integer into its exact varint bytes and decodes byte sequences back into numbers, so you can inspect or hand-build a protobuf payload.

How it works

A varint splits the integer into 7-bit groups, least significant group first. Each group is written into one byte’s low 7 bits, and the top bit (0x80) is set as a continuation flag on every byte except the final one:

300 (binary 100101100)
  low 7 bits  0101100 -> 0xAC (continuation set)
  next bits        10 -> 0x02 (last byte)
  varint = AC 02

Decoding reverses this: read bytes until one has its continuation bit cleared, shift each group left by 7 times its position, and OR them together. The tool uses BigInt throughout so 64-bit values stay exact.

Tips and notes

Varint is defined only for unsigned (non-negative) integers; signed protobuf fields are normally pre-processed with ZigZag encoding first, so use the ZigZag tool before this one for negative numbers. When decoding, separate bytes with spaces or commas and write them in hex (AC, 0xAC) or decimal (172). The final byte must clear its continuation bit or the input is reported as an incomplete varint.

Ad placeholder (rectangle)