<p>The compactsize encoding is a variable-length encoding for integers between 0 and 2<sup>64</sup> - 1 inclusive.</p>
<ul>
<li>Numbers in [0,253) are stored a a single byte, encoding the value directly.</li>
<li>Numbers in [253,2<sup>16</sup>) are stored as 3 bytes: 0xFD + the number in 16-bit little-endian format.</li>
<li>Numbers in [2<sup>16</sup>,2<sup>32</sup>) are stored as 5 bytes: 0xFE + the number in 32-bit little-endian format.</li>
<li>Numbers in [2<sup>32</sup>,2<sup>64</sup>) are stored as 9 bytes: 0xFF + the number in 64-bit little-endian format.</li>
</ul>

CC BY-SA 4.0
2021-11-28T02:39:57.883Z
2021-11-28T02:39:57.883Z
Pieter Wuille
<p>I'm trying to understand the structure of the service and network bytes for compact sizes.</p>
<p>what's specification for compressing the bytes for example in addrv2 message encoding?</p>
<p>thanks.</p>

<p2p><services>
What's the specification for Compact Size service messages?
Chiru
# What's the specification for Compact Size service messages?

(Asked by: username_0 on 2021-11-27)

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?

thanks.

**Tags:** p2p, services


---

## 1 answers

### Answer by username_1 on 2021-11-28. Score: 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.


---

