BIP 337: Compressed Transactions
View on GitHub
  BIP: 337
  Layer: API/RPC
  Title: Compressed Transactions
  Author: Tom Briar <>
  Status: Draft
  Type: Standards Track
  Created: 2024-02-01
  License: BSD-3-Clause



This document proposes a serialization scheme for compressing Bitcoin transactions. The compressed Bitcoin transactions can reach a serialized size of less than 50% of the original serialized transaction. One method for compressing involves reducing the transaction outpoints in a potentially lossy way. Therefore, it is an optional path for compression. Compressing the outpoints is necessary for compressed transactions to reach less than 70% of the original size.


Typical Bitcoin transactions usually contain a large amount of white space and padding due to specific fields that are often one of a minimal number of possibilities. We can use this fact and a few similar methods to create an encoding for 90% of Bitcoin transactions that are roughly 25-50% smaller.

There exists a working-in-progress app that allows the use of steganography to encode data in images to be passed around via various social media groups. When used in conjunction with this compression scheme and an elligator squared encryption, this would allow for a very secure and private form of broadcasting bitcoin transactions.


The four main methods to achieve a lower transaction size are:

  1. Packing transaction metadata before it and each of its inputs and outputs to determine the following data structure.

  2. Replacing 32-bit numeric values with either variable-length integers (VarInts) or compact integers (CompactSizes).

  3. Using compressed signatures and public key recovery upon decompression.

  4. Replacing the 36-byte Outpoint txid/vout pair with a block height and index.

Backwards Compatibility

There are no concerns with backwards compatibility.



CompactSize1-5 BytesFor 0-253, encode the value directly in one byte. For 254-65535, encode 254 followed by two little-endian bytes. For 65536-(2^32-1), encode 255 followed by four little-endian bytes.
CompactSize Flag2 Bits1, 2, or 3 indicate literal values. 0 indicates that a CompactSize encoding of the value will follow.
VarInt1+ Bytes7-bit little-endian encoding, with each 7-bit word encoded in a byte. The highest bit of each byte is one if more bytes follow, and 0 for the last byte.
VLP-Bytestream2+ BytesA VarInt Length Prefixed Bytestream. It uses the prefixed VarInt to determine the length of the following byte stream.

General Schema

Transaction metadata1 BytesInformation on the structure of the transaction. See Transaction Metadata
Version0-5 BytesIf present according to the metadata field, a CompactSize encoding of the transaction version.
Input Count0-5 BytesIf present according to the metadata field, a CompactSize encoding of the transaction input count.
Output Count0-5 BytesIf present according to the metadata field, a CompactSize encoding of the transaction output count.
LockTime0-5 BytesIf present according to the metadata field, a CompactSize encoding of the transaction LockTime.
Minimum Blockheight1-5 BytesIf present according to the metadata field, a VarInt encoding of the minimum block height for transaction compressed inputs and LockTime.
Input Metadata+Output Metadata1+ BytesAn encoding containing the metadata for all the inputs followed by all the outputs of the transaction. For each input, see Input Metadata, and for each output, see Output Metadata.
Input Data66+ BytesSee Input Data.
Output Data3+ BytesSee Output Data.

Transaction Metadata

Version2 BitsA CompactSize flag for the transaction version.
Input Count2 BitsA CompactSize flag for the transaction input count.
Output Count2 BitsA CompactSize flag for the transaction output count.
LockTime1 BitA boolean to indicate if the transaction has a LockTime.
Minimum Blockheight1 BitA boolean to indicate if the transaction minimum block height is greater than zero.

Input Metadata

Compressed Signature1 BitA Boolean do determine if this input's signature is compressed. The signature is only compressed for P2TR on a key spend and for P2SH when it is a wrapped P2SH-WPKH.
Standard Hash1 BitA Boolean to determine if this input's signature hash type is standard (0x00 for Taproot, 0x01 for Legacy/Segwit).
Standard Sequence2 BitsA CompactSize flag for this input's sequence. Encode literal values as follows: 1 = 0x00000000, 2 = 0xFFFFFFFE, 3 = 0xFFFFFFFF.
Compressed OutPoint1 bitA Boolean to determine if the input's outpoint is compressed.

Output Metadata

Encoded Script Type3 BitsEncoded Script Type.

Script Type Encoding

Script TypeValue
Uncompressed Custom Script0b000
Uncompressed P2PK0b001
Compressed P2PK0b010

Input Data

Outpoint2-37 BytesThe Outpoint Txid/Vout are determined to be compressed or otherwise by the "Compressed Outpoint" Boolean in the input metadata. For each compressed outpoint see Compressed Outpoint. For each uncompressed signature see Uncompressed Outpoint.
Signature64+ BytesThe Signature is determined to be compressed or otherwise by the output script of the previous transaction. For each compressed signature see Compressed Signature. For each uncompressed signature see Uncompressed Signature.
Sequence0-5 BytesIf present due to a non-standard sequence, a VarInt encoding of the sequence.

Compressed Outpoint

Txid Block Height1-5 BytesA VarInt containing the offset from Minimum Blockheight for this Txid.
Txid Block Index1-5 BytesA VarInt containing the flattened index from the Txid block height for the Vout.

Uncompressed Outpoint

Txid32 BytesContains the 32 Byte Txid.
Vout1-5 BytesA CompactSize Containing the Vout of the Txid.

Compressed Signature

Signature64 BytesContains the 64 Byte signature.
Pubkey Hash0-20 BytesIf input is P2SH-P2WPKH contains the 20 byte hash of the public key.
Hash Type0-1 BytesAn Optional Byte containing the Hash Type if it was non-standard.

Uncompressed Signature

Signature2+ BytesA VLP-Bytestream containing the signature.

Output Data

Output Script2+ BytesA VLP-Bytestream containing the output script.
Amount1-9 BytesA VarInt containing the output amount.

Ideal Transaction

The compression scheme was designed to be optimal for a "typical" transaction, spending a few close-in-age inputs and having one or two outputs. Here are size values for such a transaction, which demonstrate the effectiveness of the compression.

FieldRequirementsSavings Up To
VersionLess than four30 Bits
Input CountLess than four30 Bits
Output CountLess than four30 Bits
LockTime030 Bits
Input Sequence0x00, 0xFFFFFFFE, or 0xFFFFFFFF62 Bits For Each Input
Input TxidCompressed Outpoint23 - 31 Bytes For Each Input
Input VoutCompressed Outpoint(-1) - 3 Bytes For Each Input
Input SignatureNon-custom Script Signing40 - 72 Bytes For Each Legacy Input
Input Hash Type0x00 for Taproot, 0x01 for Legacy7 Bits For Each Input
Output ScriptNon-custom Scripts2 - 5 Bytes For Each Output
Output AmountNo Restrictions(-1) - 7 Bytes For Each Output

Reference Implementation

This reference implementation adds two new RPC endpoints, compressrawtransaction and decompressrawtransaction. The first accepts a raw hex-encoded transaction and returns a compact hex-encoded transaction; also included in the output is a list of warnings to help ensure there are no unexpected uncompressed values. The second accepts a compact hex transaction and returns the uncompressed raw hex-encoded transaction.

Test Vectors






















Thank you to Andrew Poelstra, who helped invent and develop the ideas in the proposal and the code for reference implementation.



See an issue with rendering or formatting? Please submit an issue on GitHub is presented by nickmonad

Stay humble. Stack sats.

All content is owned and licensed by the respective author(s). This website makes no claim of ownership.