• About
  • FAQ
  • Earn Bitcoin while Surfing the net
  • Buy & Sell Crypto on Paxful
Newsletter
Approx Foundation
  • Home
    • Home – Layout 1
  • Bitcoin
  • Ethereum
  • Regulation
  • Market
  • Blockchain
  • Business
  • Guide
  • Contact Us
No Result
View All Result
  • Home
    • Home – Layout 1
  • Bitcoin
  • Ethereum
  • Regulation
  • Market
  • Blockchain
  • Business
  • Guide
  • Contact Us
No Result
View All Result
Approx Foundation
No Result
View All Result
Home Bitcoin

bitcoin core – What is the difference between the CompactSize and VarInt encodings?

Moussa by Moussa
June 25, 2026
in Bitcoin
0
How do Bitcoin mining pools typically handle payout frequency versus thresholds?
190
SHARES
1.5k
VIEWS
Share on FacebookShare on Twitter


There are two distinct variable-length integer encodings implemented in Bitcoin Core’s serialization framework:

  1. The encoding used in the P2P protocol for the lengths of vectors (number of transactions in blocks, number of inputs/outputs in transactions, number of entries in inv/addr messages, …) is known inside the Bitcoin Core codebase as the “CompactSize” encoding, though it has historically been referred to in external protocol documentation as “VarInt”.
  2. Another encoding which is only used internally in Bitcoin Core, in e.g. its UTXO database on disk, but isn’t used anywhere in the P2P protocol. This is referred to inside the Bitcoin Core codebase as “VarInt”.

For reference, the two encodings are:

  1. The “CompactSize” encoding (also known as “VarInt” outside Bitcoin Core):
  • 0..0xfc: 1 byte (the value itself)
  • 0xfd..0xffff: 3 bytes (0xfd + 2 byte little endian encoding)
  • 0x10000..0xffffffff: 5 bytes (0xfe + 4 byte little endian encoding)
  • 0x100000000..0xffffffffffffffff: 9 bytes (0xff + 8 byte little endian encoding)
  1. The “VarInt” encoding (not used outside Bitcoin Core) is described inside the codebase as follows:

Variable-length integers: bytes are a MSB base-128 encoding of the number.
The high bit in each byte signifies whether another digit follows. To make
sure the encoding is one-to-one, one is subtracted from all but the last digit.
Thus, the byte sequence a[] with length len, where all but the last byte
has bit 128 set, encodes the number:

(a[len-1] & 0x7F) + sum(i=1..len-1, 128^i*((a[len-i-1] & 0x7F)+1))

It results in the following sizes:

  • 0..0x7f: 1 byte
  • 0x80..0x407f: 2 bytes
  • 0x4080..0x20407f: 3 bytes
  • 0x204080..0x1020407f: 4 bytes
  • 0x10204080..0x81020407f: 5 bytes
  • …



Source link

Related articles

Bitcoin Covered Calls Could Generate 22% Yield in a Sideways Market, Grayscale Says

Grayscale’s Chainlink ETF Sinks to $72M After LINK’s 18% Slide

August 8, 2026
Musk’s SpaceX Stock Rallies 6% as Tokenized Volume Hits $700M

Musk’s SpaceX Stock Rallies 6% as Tokenized Volume Hits $700M

August 8, 2026
Share76Tweet48

Related Posts

Bitcoin Covered Calls Could Generate 22% Yield in a Sideways Market, Grayscale Says

Grayscale’s Chainlink ETF Sinks to $72M After LINK’s 18% Slide

by Moussa
August 8, 2026
0

Key TakeawaysGrayscale filed GLNK’s Q2 2026 10-Q with the SEC on August 7, reporting $72.2 million in net assets.LINK’s price...

Musk’s SpaceX Stock Rallies 6% as Tokenized Volume Hits $700M

Musk’s SpaceX Stock Rallies 6% as Tokenized Volume Hits $700M

by Moussa
August 8, 2026
0

Key TakeawaysGate’s tokenized SPCX token logged $332M and $360M in volume on August 4-5 ahead of the unlock.SpaceX stock closed...

Circle Renews Coinbase USDC Deal and Rules Out Dividends

Circle Renews Coinbase USDC Deal and Rules Out Dividends

by Moussa
August 8, 2026
0

Key TakeawaysCircle renewed Coinbase’s USDC deal as Q2 revenue reached $701M, preserving a key distribution channel.USDC ended Q2 at $73.3B...

Genius Sports Now Settles Contracts for Both Kalshi and Polymarket

Genius Sports Now Settles Contracts for Both Kalshi and Polymarket

by Moussa
August 8, 2026
0

Key TakeawaysGenius Sports signed Polymarket on Aug. 4 and Kalshi on Aug. 5.Genius booked prediction-market revenue in Q2, before either...

recover cryptocurrency

by Moussa
August 8, 2026
0

I had an unfortunate experience with a fraudulent investment company. After investing $185,000, I became increasingly concerned when I was...

Load More

youssufi.com

sephina.com

[vc_row full_width="stretch_row" parallax="content-moving" vc_row_background="" background_repeat="no-repeat" background_position="center center" footer_scheme="dark" css=".vc_custom_1517813231908{padding-top: 60px !important;padding-bottom: 30px !important;background-color: #191818 !important;background-position: center;background-repeat: no-repeat !important;background-size: cover !important;}" footer_widget_title_color="#fcbf46" footer_button_bg="#fcb11e"][vc_column width="1/4"]

We bring you the latest in Crypto News

[/vc_column][vc_column width="1/4"][vc_wp_categories]
[/vc_column][vc_column width="1/4"][vc_wp_tagcloud taxonomy="post_tag"][/vc_column][vc_column width="1/4"]

Newsletter

[vc_raw_html]JTNDcCUzRSUzQ2RpdiUyMGNsYXNzJTNEJTIydG5wJTIwdG5wLXN1YnNjcmlwdGlvbiUyMiUzRSUwQSUzQ2Zvcm0lMjBtZXRob2QlM0QlMjJwb3N0JTIyJTIwYWN0aW9uJTNEJTIyaHR0cHMlM0ElMkYlMkZhcHByb3gub3JnJTJGJTNGbmElM0RzJTIyJTNFJTBBJTBBJTNDaW5wdXQlMjB0eXBlJTNEJTIyaGlkZGVuJTIyJTIwbmFtZSUzRCUyMm5sYW5nJTIyJTIwdmFsdWUlM0QlMjIlMjIlM0UlM0NkaXYlMjBjbGFzcyUzRCUyMnRucC1maWVsZCUyMHRucC1maWVsZC1maXJzdG5hbWUlMjIlM0UlM0NsYWJlbCUyMGZvciUzRCUyMnRucC0xJTIyJTNFRmlyc3QlMjBuYW1lJTIwb3IlMjBmdWxsJTIwbmFtZSUzQyUyRmxhYmVsJTNFJTBBJTNDaW5wdXQlMjBjbGFzcyUzRCUyMnRucC1uYW1lJTIyJTIwdHlwZSUzRCUyMnRleHQlMjIlMjBuYW1lJTNEJTIybm4lMjIlMjBpZCUzRCUyMnRucC0xJTIyJTIwdmFsdWUlM0QlMjIlMjIlM0UlM0MlMkZkaXYlM0UlMEElM0NkaXYlMjBjbGFzcyUzRCUyMnRucC1maWVsZCUyMHRucC1maWVsZC1lbWFpbCUyMiUzRSUzQ2xhYmVsJTIwZm9yJTNEJTIydG5wLTIlMjIlM0VFbWFpbCUzQyUyRmxhYmVsJTNFJTBBJTNDaW5wdXQlMjBjbGFzcyUzRCUyMnRucC1lbWFpbCUyMiUyMHR5cGUlM0QlMjJlbWFpbCUyMiUyMG5hbWUlM0QlMjJuZSUyMiUyMGlkJTNEJTIydG5wLTIlMjIlMjB2YWx1ZSUzRCUyMiUyMiUyMHJlcXVpcmVkJTNFJTNDJTJGZGl2JTNFJTBBJTNDZGl2JTIwY2xhc3MlM0QlMjJ0bnAtZmllbGQlMjB0bnAtcHJpdmFjeS1maWVsZCUyMiUzRSUzQ2xhYmVsJTNFJTNDaW5wdXQlMjB0eXBlJTNEJTIyY2hlY2tib3glMjIlMjBuYW1lJTNEJTIybnklMjIlMjByZXF1aXJlZCUyMGNsYXNzJTNEJTIydG5wLXByaXZhY3klMjIlM0UlQzIlQTBCeSUyMGNvbnRpbnVpbmclMkMlMjB5b3UlMjBhY2NlcHQlMjB0aGUlMjBwcml2YWN5JTIwcG9saWN5JTNDJTJGbGFiZWwlM0UlM0MlMkZkaXYlM0UlM0NkaXYlMjBjbGFzcyUzRCUyMnRucC1maWVsZCUyMHRucC1maWVsZC1idXR0b24lMjIlM0UlM0NpbnB1dCUyMGNsYXNzJTNEJTIydG5wLXN1Ym1pdCUyMiUyMHR5cGUlM0QlMjJzdWJtaXQlMjIlMjB2YWx1ZSUzRCUyMlN1YnNjcmliZSUyMiUyMCUzRSUwQSUzQyUyRmRpdiUzRSUwQSUzQyUyRmZvcm0lM0UlMEElM0MlMkZkaXYlM0UlM0NiciUyRiUzRSUzQyUyRnAlM0U=[/vc_raw_html][/vc_column][/vc_row]
No Result
View All Result
  • Contact Us
  • Homepages
  • Business
  • Guide

© 2024 APPROX FOUNDATION - The Crypto Currency News