Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

A Bitcoin transaction’s legacy byte layout is version | input count | inputs | output count | outputs | locktime. SegWit transactions add a marker and flag after the version and place per-input witness data before locktime. These serialized bytes encode what is spent, where value goes, and the conditions for spending outputs—not a separate fee field.

Legacy Bitcoin transaction format, field by field

The Bitcoin Developer Reference describes raw format as the serialized byte format broadcast between peers. In legacy serialization, fields appear in this order:

version | input count | inputs | output count | outputs | locktime

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Order Field What it contains
1 version Four bytes. Version 1 is the baseline; version 2 indicates that BIP 68 relative-locktime rules apply, subject to those rules and transaction validity.
2 Input count A CompactSize unsigned integer giving the number of inputs.
3 Inputs One input record per earlier output being spent.
4 Output count A CompactSize unsigned integer giving the number of outputs.
5 Outputs One output record per destination or other output condition.
6 lock_time Four bytes, interpreted as a block height or Unix timestamp according to the locktime threshold.

CompactSize is Bitcoin’s variable-length integer encoding. It is not a single-byte count in every case. Counts and script lengths use this encoding, so the number of bytes occupied by a count depends on its value.

#1 Best Overall
Bitkey Bitcoin Hardware Wallet, No Screen - Self-Custody, No Seed Phrase
  • BITCOIN EXCLUSIVE, PHONE VERIFICATION: Bitkey is designed from the ground up exclusively for bitcoin — a dedicated hardware wallet for secure bitcoin storage. Approve transactions with a tap using your phone and NFC. No device screen is required.
  • SELF-CUSTODY, NO EXCHANGE OR CUSTODIAN REQUIRED: You hold two of the three keys in the Bitkey system – one on your phone and one on your Bitkey device. The third is stored on Bitkey’s server and cannot move your bitcoin on its own.
  • NO SEED PHRASE: Set up and use Bitkey without creating or storing a seed phrase.
  • 2-of-3 MULTISIG: Three keys are stored separately across your phone, Bitkey device, and Bitkey’s server. Any two keys are required to move your bitcoin.
  • BUILT-IN RECOVERY: Encrypted backup and recovery tools can help you regain access if you lose your phone or Bitkey device. You can also designate a Recovery Contact.

What an input contains

An ordinary input references one earlier output, called an outpoint, then provides a length-prefixed scriptSig and a four-byte sequence value. The outpoint is 36 bytes: a 32-byte transaction hash and a four-byte output index. The hash is serialized in internal byte order, which can look reversed compared with the conventional displayed TXID.

The input’s unlocking data must satisfy the conditions set by the referenced output. For witness-based spends, some or all required spending data is carried in the separate witness structure instead of scriptSig.

Rank #2
Trezor Safe 3 Crypto Hardware Wallet with Secure Element
  • Unparalleled Security: Protect your assets NDA-free EAL 6+ Secure Element, offering robust defense and complete transparency
  • Simple & Secure Interface: Manage your digital assets easily with a clear OLED screen for secure on-device confirmations
  • Supports 1000s of Coins & Tokens: Securely handle thousands of assets, including Bitcoin, Ethereum, and more, all in one wallet
  • Effortless Asset Management: Monitor and transact seamlessly with Trezor Suite, our intuitive desktop and mobile app
  • Enhanced Backup Solution: Rest assured with Multi-share Backup, eliminating single points of failure for secure cold wallet recovery

What an output contains

An output consists of an eight-byte value in satoshis followed by a CompactSize script length and the scriptPubKey bytes. The script defines the conditions that must be met to spend that output later. Transactions can have multiple outputs, including a change output.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

There is no explicit fee field. For a valid ordinary transaction, the fee is the total value of its inputs minus the total value of its outputs. Output value cannot exceed input value, with coinbase issuance handled as a special case.

Rank #3
Trezor Safe 3 Crypto Hardware Wallet with Secure Element
  • Unparalleled Security: Protect your assets with EAL 6+ Secure Element, offering robust defense and complete transparency
  • Simple & Secure Interface: Manage your digital assets easily with a clear OLED screen for secure on-device confirmations
  • Supports 1000s of Coins & Tokens: Securely handle thousands of assets, including Bitcoin, Ethereum, and more, all in one wallet
  • Effortless Asset Management: Monitor and transact seamlessly with Trezor Suite, our intuitive desktop and mobile app
  • Enhanced Backup Solution: Multi-share Backup eliminates single points of failure for secure cold wallet recovery

Sequence and locktime are different fields

sequence is stored in each input; lock_time appears once for the whole transaction. Sequence values can disable locktime in some cases and, under BIP 68’s defined conditions, express a relative-locktime constraint. Locktime is instead a transaction-wide condition interpreted using the height-or-time threshold.

How SegWit changes the serialization

A transaction with witness data uses an extended serialization:

Rank #4
Trezor Safe 7 Crypto Hardware Wallet with Bluetooth for Android/iOS/Desktop
  • Dual-chip architecture for maximum protection: The next-gen, fully auditable TROPIC01 chip works alongside a certified EAL6+ Secure Element—completely NDA-free—to deliver radically transparent, industry-leading defense against physical attacks.
  • Quantum-ready security: Get protection against future threats with the first-ever hardware wallet designed with quantum-ready architecture.
  • See every detail with confidence: Our largest high-resolution color touchscreen makes it easy to navigate your assets, review transactions and manage your coins with clarity.
  • Wireless freedom with encrypted Bluetooth control: Manage, buy, swap and stake securely using Trezor Suite on desktop or mobile. Qi2-compatible wireless charging keeps your Trezor powered up. No cables required—security meets convenience.
  • Works seamlessly with Android, iOS and desktop: Connect wirelessly or via USB-C to your phone or computer. Manage your crypto anywhere with our companion Trezor Suite app.

version | marker | flag | input count | inputs | output count | outputs | witnesses | locktime

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The marker is zero and the flag is nonzero. After all outputs, the serialization includes one witness stack for each input; the number of stacks is implicit in the input count. A stack contains length-prefixed byte arrays, and an empty stack is encoded with a zero byte. When all witness data is empty, the legacy serialization is used.

Best Value
Sale
Ledger Nano X - Classic Crypto Wallet with Bluetooth
  • Effortlessly build your crypto portfolio via the all in one Ledger Wallet app: buy, sell, send, receive, swap, stake and more across popular blockchains. 15,000+ coins & tokens in a single dashboard. Keep a close eye on the market. Compare service providers. Track performance. Get timely alerts. Build your portfolio with confidence.
  • Effortlessly build your crypto portfolio via the all in one Ledger Wallet app: buy, sell, send, receive, swap, stake and more across popular blockchains. 15,000+ coins & tokens in a single dashboard. Keep a close eye on the market. Compare service providers. Track performance. Get timely alerts. Build your portfolio with confidence.
  • Enjoy Bluetooth connectivity, iOS access, and hours of battery use with this mobile-first, secure backup signer. Freedom you can depend on.
  • Genuine Check: confirm your signer is authentic during setup with the Ledger Wallet app.
  • Protect your signer: keep it in mint condition at all times with a bespoke Pod or Case to avoid scratches and everyday wear and tear.

Witness data is spending information, not another set of transaction outputs. For example, BIP 141 describes a version-zero P2WPKH spend whose witness contains a signature and public key, and a P2WSH spend whose witness can include stack data and a serialized script.

Property Legacy serialization Witness-extended serialization
Marker and flag Absent Inserted after the four-byte version
Witness stacks Not included Included after outputs, one stack per input
When used Used when witness data is empty Used when witness data is present
Hashing relationship Provides the serialization used for the traditional TXID Provides the bytes used for the witness-inclusive WTXID; the traditional TXID still uses non-witness serialization
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

TXID and WTXID: which bytes are hashed?

The traditional transaction identifier, or TXID, is computed from the non-witness serialization. BIP 144 states that transaction hashes used in the transaction Merkle tree and input outpoints are computed using the old, non-witness serialization. The witness-inclusive hash, or WTXID, is computed from the witness serialization.

For a transaction with no witness data, the two hashes are equal because legacy serialization is used. When witness data is present, it affects the WTXID but is excluded from the TXID used for transaction-tree and outpoint references.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Special case: the coinbase transaction

The first transaction in a block is the coinbase transaction. It has exactly one special input rather than an ordinary spend: its outpoint uses a null 32-byte hash and output index 0xffffffff. The input’s script field carries the block height as required by BIP 34 and may include additional miner-selected data within the specified limit. Coinbase output value can come from the block subsidy and collected transaction fees, so the ordinary input-minus-output explanation does not apply to it in the same way.

Raw transaction bytes are not PSBT

Raw transaction bytes are the network serialization used to relay transaction data and calculate transaction identifiers. PSBT, or Partially Signed Bitcoin Transaction, is a separate format that carries transaction data plus metadata for signing workflows; it is not the network serialization format. For version-zero witness programs, BIP 143 also defines a signature-hash construction that commits to the spent input amount and selected transaction components according to the sighash flags. That constructed signature message is not simply the complete raw transaction byte stream.

Quick Recap

Bestseller No. 1
Bitkey Bitcoin Hardware Wallet, No Screen - Self-Custody, No Seed Phrase
Bitkey Bitcoin Hardware Wallet, No Screen - Self-Custody, No Seed Phrase
NO SEED PHRASE: Set up and use Bitkey without creating or storing a seed phrase.
SaleBestseller No. 5
Ledger Nano X - Classic Crypto Wallet with Bluetooth
Ledger Nano X - Classic Crypto Wallet with Bluetooth
Genuine Check: confirm your signer is authentic during setup with the Ledger Wallet app.
$79.00

Official references

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.