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
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.
#1 Best Overall
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.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →What does each output contain?
An output has an eight-byte value, denominated in satoshis, followed by the length and bytes of a scriptPubKey:
Rank #2
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.
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.
Rank #3
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.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errorsWitness 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.
Rank #4
| 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.
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.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallQuick Recap
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.




