I'm trying to understand the structure of the service and network bytes for compact sizes.

what's specification for compressing the bytes for example in addrv2 message encoding?


1 Answer 1


The compactsize encoding is a variable-length encoding for integers between 0 and 264 - 1 inclusive.

  • Numbers in [0,253) are stored a a single byte, encoding the value directly.
  • Numbers in [253,216) are stored as 3 bytes: 0xFD + the number in 16-bit little-endian format.
  • Numbers in [216,232) are stored as 5 bytes: 0xFE + the number in 32-bit little-endian format.
  • Numbers in [232,264) are stored as 9 bytes: 0xFF + the number in 64-bit little-endian format.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.