Bitcoin Transaction Structure Explained: Inputs, Outputs, and Witness
A Bitcoin transaction is a serialized record that consumes existing unspent transaction outputs (UTXOs) and creates new outputs. Nodes validate the transaction against consensus rules; miners may later include it in a block. A transaction is not a transfer between account balances maintained by the network.
The essential components
A transaction includes a version, a list of inputs, a list of outputs, and a locktime. Each input refers to a previous output by transaction identifier and output index (the outpoint), and supplies the data needed to satisfy that output's spending conditions. Each new output specifies an amount in satoshis and a locking script (scriptPubKey).
A typical payment consumes one or more UTXOs and creates an output for the recipient and, when necessary, a change output back to the sender. Neither the recipient output nor the change output is inherently labeled as such by consensus rules.
An illustrative UTXO flow
Suppose a wallet controls a 100,000-satoshi UTXO and creates two outputs: 70,000 sats to the recipient and 28,500 sats as change. The 1,500-sat difference is the transaction fee. This example ignores the policy details that would determine whether these outputs are standard or economical to spend.
````
Inputs: 100000 sat
Outputs: 70000 sat + 28500 sat
Fee: 1500 sat
The miner fee is the sum of input values minus the sum of output values. The fee is not a separate transaction output.
What SegWit changed
Segregated Witness separates witness data from the traditional transaction serialization. For SegWit transactions, txid is computed without witness data, while wtxid commits to the witness serialization. This distinction matters when building block explorers, signing systems, and transaction tracking tools. Legacy transactions do not gain an independent witness payload merely by being processed by a SegWit-capable node.
Locktime and sequence
nLockTime and input sequence values affect when a transaction can be included and can participate in relative-locktime and replacement behavior under applicable rules. Do not treat every sequence value as a universal opt-in RBF flag; replacement relay policy and consensus validity are different concepts.
Developer checklist
When decoding a raw transaction, inspect version, input outpoints, input sequence, output amounts, output scripts, witness stacks when present, and locktime. Resolve the previous outputs to determine input values and the actual fee. Validate against the correct network and avoid interpreting an unconfirmed transaction as final settlement.
Primary references
- Bitcoin developer reference: https://developer.bitcoin.org/reference/transactions.html
- BIP141 (Segregated Witness): https://github.com/bitcoin/bips/blob/master/bip-0141.mediawiki
- BIP143 (SegWit v0 signature digest): https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki
