Transactions: inputs & outputs

No balances, just coins being spent and created.

Your wallet shows a balance, but Bitcoin itself has no accounts. It has coins, called UTXOs, and transactions that destroy some coins and create new ones.

The structure

  • Version (4 bytes).
  • Inputs: each one names a coin to spend with an outpoint (txid + output index), a scriptSig and a 4-byte nSequence field.
  • Outputs: each one has an amount in satoshis (8 bytes) and a locking script, the scriptPubKey, which says what is needed to spend it.
  • nLockTime (4 bytes): the earliest block or time the transaction may be mined.
  • Witness (SegWit only): signatures and scripts, kept outside the txid.

Coins are spent whole

A UTXO cannot be split while it sits there. If you hold a 0.5 BTC coin and want to pay 0.2 BTC, you spend the whole coin and create two outputs: 0.2 BTC to the receiver and about 0.3 BTC back to yourself as "change", usually to a fresh address in your own wallet.

The fee is invisible

No field says "fee". The fee is simply the inputs minus the outputs. In the example above, if the outputs add up to 0.4999 BTC, the miner can claim the remaining 0.0001 BTC. Forget the change output and the whole difference goes to the miner.

What a node checks

  • Every input spends a coin that exists and is still unspent.
  • Every input's script, together with the coin's locking script (and witness), runs successfully.
  • Outputs do not add up to more than inputs.
  • Timelocks are satisfied.

Minting new coins

The one exception to "inputs pay for outputs" is the coinbase transaction, the first in each block, which creates the block reward from nothing. Its outputs can only be spent after 100 further blocks.

Policy limits

Bitcoin Core also applies relay rules on top of consensus. A standard transaction may be at most 400,000 weight units. Outputs that cost more to spend than they are worth are called dust and are not relayed. At the default dust feerate, that is below 546 satoshis for a legacy P2PKH output and below 294 satoshis for a native SegWit P2WPKH output.

Takeaway

Every bitcoin you own is a specific output from a past transaction, locked by a script that only your key can satisfy.