Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk5 min

Bitcoin Transaction Format: How to Read Every Field in Raw Hex

A practical guide to Bitcoin transaction serialization, from the legacy field order and input/output records to SegWit witness data and TXID versus WTXID.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A Bitcoin transaction’s raw bytes encode its version, inputs, outputs and locktime; SegWit transactions also include a marker, flag and witness data. Read the fields in order to decode the transaction and understand why its TXID can differ from its witness-inclusive hash.

What is the field order in a Bitcoin transaction?

The Bitcoin Developer Reference describes raw format as the serialized byte format used to broadcast transactions between peers. The legacy layout is:

As an Amazon Associate I earn from qualifying purchases.

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

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

Every field is bytes, not a human-readable label. Counts and variable-length scripts use Bitcoin’s CompactSize integer encoding, so a count or length is not always represented by a single byte. A transaction can contain multiple inputs and outputs.

What does each input contain?

An ordinary input identifies one earlier transaction output to spend, then provides data to satisfy that output’s spending conditions. Its serialized structure is:

previous transaction hash (32 bytes) | output index (4 bytes) | scriptSig length | scriptSig | sequence (4 bytes)

  • Outpoint: The 32-byte transaction hash and four-byte output index together identify the earlier output. The hash is serialized in internal byte order, which differs from the conventional displayed TXID byte order.
  • Script length and scriptSig: A CompactSize length precedes the script bytes. The script provides spending data for the referenced output’s locking script. In witness-based spends, relevant spending data may instead be carried in the separate witness structure.
  • Sequence: A four-byte value associated with this input. It can affect locktime behavior; under BIP 68, sequence values can express relative-locktime constraints when the applicable version and limits are met.

These fields repeat once for each input. The count immediately before the input vector tells a decoder how many records to parse.

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

What does each output contain?

An output has an eight-byte value, denominated in satoshis, followed by the length and bytes of a scriptPubKey:

value (8 bytes) | scriptPubKey length | scriptPubKey

The script specifies the conditions that must be satisfied to spend that output later. Transactions can have several outputs, including a change output. There is no explicit fee field: for a valid ordinary transaction, the fee is the total input value minus the total output value. The Bitcoin Developer Reference notes the coinbase exception: coinbase output value is governed by block subsidy and collected fees.

How do version, sequence and locktime work together?

version is a four-byte field. The Bitcoin Developer Reference describes version 1 as the baseline and version 2 as indicating that BIP 68 rules apply. A version number alone does not make a transaction valid; the transaction must still meet the applicable consensus rules.

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

sequence is repeated within each input, while nLockTime appears once at the end of the transaction. Locktime is four bytes and is interpreted as either a block height or a Unix timestamp according to the documented threshold. Sequence can disable locktime in some cases and, under BIP 68’s conditions, can specify a relative locktime. These are distinct controls: one is transaction-wide and the other belongs to an individual input.

How does SegWit change the serialized layout?

When a transaction carries witness data, the extended serialization is arranged as follows:

version | marker | flag | input count | inputs | output count | outputs | witness data for each input | locktime

The marker is zero and the flag is nonzero. The input and output records retain their roles, while a witness stack is serialized for each input after the outputs. The number of witness stacks is implicit in the input count; each stack contains length-prefixed byte arrays. An empty stack is encoded with a zero byte. If every input’s witness is empty, the legacy serialization is used instead.

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

Witness data supplies spending information for applicable conditions; it is not another set of outputs. For example, BIP 141 describes version-zero witness programs including P2WPKH, whose witness contains a signature and public key, and P2WSH, whose witness can include stack data and a serialized script.

Feature Legacy serialization Witness serialization
Marker and flag Not present Zero marker and nonzero flag follow the version
Witness stacks Not carried Serialized for each input after the outputs
Traditional TXID input Legacy serialization Non-witness serialization
Witness-inclusive hash input Same serialization as the TXID when witness is empty Witness serialization
All witness stacks empty Legacy form applies Extended form is not used

Why can a transaction have a TXID and a different WTXID?

The traditional transaction identifier, or TXID, is calculated from the non-witness serialization. BIP 144 states: “Transaction hashes used in the transaction merkle tree and txin outpoints are always computed using the old non-witness serialization.” This is why witness bytes do not change the TXID used for transaction-tree references and input outpoints.

The witness-inclusive hash, or WTXID, is calculated from the witness serialization. If a transaction has no witness data, the legacy serialization is used and the TXID and WTXID are equal. If it has witness data, the two hashes can differ because only the WTXID commits to those witness bytes.

What is different about a coinbase transaction?

The first transaction in a block is the coinbase transaction. It has exactly one special input rather than an ordinary input spending an earlier output. That input’s outpoint contains a null 32-byte hash and the index 0xffffffff. Its script field carries the block height as required by BIP 34 and can include additional miner-selected data within the specified limit. Coinbase output value comes from the block subsidy and collected transaction fees, so ordinary input-minus-output fee accounting does not apply to it.

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.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Is raw transaction serialization the same as PSBT?

No. Raw serialization is the transaction byte format relayed between peers and used in transaction hashes. A PSBT, or Partially Signed Bitcoin Transaction, is a separate format for carrying transaction data and signing-related metadata through a signing workflow. It is not the network serialization format.

For version-zero witness programs, signature-hash construction is also distinct from simply hashing the full raw transaction. BIP 143 specifies a constructed digest that commits to the spent input amount and selected transaction components according to the sighash flags.

How can you inspect a serialized transaction?

Use a source that exposes the raw transaction hex, then parse it according to the format rather than treating the full string as one opaque value. A reliable decoder must account for the CompactSize counts and script lengths, distinguish legacy from witness serialization, and interpret the outpoint hash using serialized byte order. A wallet’s transaction display may show decoded details without exposing the serialized bytes; availability depends on the wallet.

For the protocol definitions, see the Bitcoin Developer Reference: Transactions, BIP 144: Segregated Witness (Peer Services), BIP 141: Segregated Witness (Consensus layer), and BIP 68: Relative lock-time using consensus-enforced sequence numbers.

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

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.