These docs are for v0.17.0. Click to read the latest docs for v19.0.0-redirect.

CompactSize Unsigned Integers

The raw transaction format and several peer-to-peer network messages use a type of variable-length integer to indicate the number of bytes in a following piece of data.

Dash Core code and this document refers to these variable length integers as compactSize. Many other documents refer to them as var_int or varInt, but this risks conflation with other variable-length integer encodings---such as the CVarInt class used in Dash Core for serializing data to disk. Because it's used in the transaction format, the format of compactSize unsigned integers is part of the consensus rules.

For numbers from 0 to 252 (0xfc), compactSize unsigned integers look like regular unsigned integers. For other numbers up to 0xffffffffffffffff, a byte is prefixed to the number to indicate its length---but otherwise the numbers look like regular unsigned integers in little-endian order.

ValueBytes UsedFormat
>= 0 && <= 0xfc (252)1uint8_t
>= 0xfd (253) && <= 0xffff30xfd followed by the number as uint16_t
>= 0x10000 && <= 0xffffffff50xfe followed by the number as uint32_t
>= 0x100000000 && <= 0xffffffffffffffff90xff followed by the number as uint64_t

For example, the number 515 is encoded as 0xfd0302.

What’s Next