• 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

Saylor Drops ‘Doing Business’ Message, Sparks Strategy Bitcoin Mystery

Saylor Drops ‘Doing Business’ Message, Sparks Strategy Bitcoin Mystery

August 9, 2026
Bitcoin’s Price Barely Blinks Amid Coldcard Sweeps and BIP-110’s Collapse

Bitcoin’s Price Barely Blinks Amid Coldcard Sweeps and BIP-110’s Collapse

August 9, 2026
Share76Tweet48

Related Posts

Saylor Drops ‘Doing Business’ Message, Sparks Strategy Bitcoin Mystery

Saylor Drops ‘Doing Business’ Message, Sparks Strategy Bitcoin Mystery

by Moussa
August 9, 2026
0

Key TakeawaysSaylor posted Strategy’s bitcoin chart on X on Aug. 9 with two words.Strategy’s bitcoin was worth about $55 billion...

Bitcoin’s Price Barely Blinks Amid Coldcard Sweeps and BIP-110’s Collapse

Bitcoin’s Price Barely Blinks Amid Coldcard Sweeps and BIP-110’s Collapse

by Moussa
August 9, 2026
0

Key TakeawaysBitcoin held near $65,000 as Coldcard losses potentially approached $130 million.BIP-110 stalled after 2 blocks as roughly 99.85% of...

Inside the 45-Day Laundering Machine

Inside the 45-Day Laundering Machine

by Moussa
August 9, 2026
0

Key TakeawaysChainalysis logged $3.4B stolen in 2025, with Bybit’s $1.5B hack alone accounting for 44% of that total.H1 2026 set...

Stolen Bitcoin at Center of Kidnapping Plot, 3 Face 20 Years

Stolen Bitcoin at Center of Kidnapping Plot, 3 Face 20 Years

by Moussa
August 9, 2026
0

Key TakeawaysThree St. Louis men face up to 20 years over a bitcoin robbery plot.The trio stalked a family for...

VALR’s Ehsani Warns Crypto Curbs Could Reduce Regulatory Oversight

VALR’s Ehsani Warns Crypto Curbs Could Reduce Regulatory Oversight

by Moussa
August 9, 2026
0

Key TakeawaysNational Treasury and SARB release draft rules governing cross-border crypto transfers.VALR CEO Farzam Ehsani warned that banning corporate crypto...

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