BitcoinMachine
TERM_DEF // ADDRESSES_ENCODING / COMPACT_SIZE
COMPACT
SIZE
Compact Size. A variable-length integer encoding using 1, 3, 5, or 9 bytes depending on the value; flags by first byte.

This page sits in the Addresses & Encoding section — How raw bytes become human-shareable strings — and the encoding rules that catch typos. Read on for what it is, why it exists, how it works under the hood, and what to watch out for.
Compact Size — at a glance
ADDRESSES
Compact Size is part of the COMPACTSIZE family of encodings used throughout Bitcoin. Same encoding as VarInt — sometimes called CompactSize in Core sources. A variable-length integer encoding using 1, 3, 5, or 9 bytes depending on the value; flags by first byte.
Why it exists
DESIGN
A Bitcoin address is, under the hood, a commitment to a script — usually a 20-byte hash or a 32-byte point. Asking users to copy 32 raw bytes would guarantee constant typos and lost funds. Address encodings (Base58Check, Bech32, Bech32m) turn those bytes into compact strings that include a mathematical checksum: every typo of 1–4 characters is detected before broadcast.
Mechanism
HOW IT WORKS
Legacy P2PKH addresses ("1…") use Base58Check: a version-byte-base58check/">version byte + 20-byte hash + 4-byte double-SHA-256 checksum, then encoded with a 58-character alphabet (no 0/O/I/l). P2SH ("3…") is the same recipe with a different version byte. SegWit v0 ("bc1q…") uses Bech32: a human-readable prefix, separator "1", 5-bit data, and a BCH checksum that detects up to 4 character errors. Taproot ("bc1p…") uses Bech32m, a tiny variant that fixes a length-extension vulnerability discovered in the original Bech32.
1. The script is reduced to a canonical commitment — usually HASH160(pubkey) for legacy or witness program for SegWit. 2. A version byte (P2PKH 0x00, P2SH 0x05, testnet variants) or a witness version (0 for v0, 1 for Taproot) is prepended. 3. A checksum is computed: 4 bytes of double-SHA-256 for Base58Check, or a 30-bit BCH checksum for Bech32/Bech32m. 4. The combined bytes are encoded into the chosen alphabet (58-character Base58 or 32-character Bech32). 5. The result is the address. A wallet checks the checksum on every paste; mismatched checksum → user is warned, transaction is never built.
Compact Size — COMPACTSIZE
EXAMPLE
Identical to VarInt above; "CompactSize" is the Bitcoin Core C++ name for the same on-wire format.
CHECKSUM
A 1–4 character typo is caught client-side. No transaction is broadcast against a malformed address.
PREFIX
The first character(s) tell you the address type (legacy / P2SH / SegWit / Taproot) at a glance.
CASE-SAFE
Bech32/Bech32m are case-insensitive but always written lowercase. Base58Check is case-sensitive — copy carefully.
NETWORK-SCOPED
Mainnet, testnet, signet, and regtest each have distinct prefixes — coins sent across networks are unrecoverable.
Things that catch people out
PITFALLS
  • Sending mainnet coins to a testnet address (or vice versa) destroys them. Always verify the prefix before broadcasting.
  • Some exchanges still cannot send to Taproot ("bc1p…") addresses. Have a SegWit-v0 ("bc1q…") fallback ready.
  • Address reuse degrades privacy. Modern wallets generate a fresh address per receive — re-displaying the same one is an anti-pattern.
  • Vanity addresses ("1Bitcoin…") are fine but use scarce randomness; never accept one from a stranger as a "proof" of identity.

Pages on this site that cover Compact Size in more depth:
Other terms from Addresses & Encoding — click any to read its page:
TERMINOLOGY
Compact Size
A variable-length integer encoding using 1, 3, 5, or 9 bytes depending on the value; flags by first byte.
Address
A user-friendly string that encodes a locking script; you give it to a sender and they pay the script.
Base58
A 58-character alphabet excluding visually-confusable characters (0, O, I, l); used in legacy addresses.
Base58Check
Base58 with a 4-byte SHA256d checksum suffix; a single typo will fail the checksum.
Bech32
BIP173 address format for SegWit v0; uses a lowercase 32-character alphabet and BCH error-correcting checksum.
Bech32m
BIP350 variant fixing a Bech32 mutation issue; used for SegWit v1+ (Taproot).
Checksum
Extra bytes appended to data so a recipient can detect transmission errors with high probability.
WIF (Wallet Import Format)
Base58Check encoding of a private key with a version byte and optional flag-wif-0x01/">compression flag.