21Relay
Advanced curriculum
Lesson 1722 minReviewed July 2026

Reading a Raw Bitcoin Transaction

A raw transaction is the serialized byte sequence nodes parse, identify and validate - not merely the summary shown by a wallet or block explorer.

Learning outcomes

By the end of this lesson, you should be able to

  • Raw transactions are ordered serialized fields, not explorer account entries.
  • An input identifies a previous output using a txid and output index.
  • An output contains satoshis and a locking script, not an address string.
  • Fees equal input value minus output value.
1

Serialization turns fields into bytes

A legacy transaction is serialized as a version, input count, inputs, output count, outputs and locktime. Counts and script lengths use CompactSize encodings. Multi-byte integers are commonly serialized little-endian, which can make raw hex look reversed when compared with familiar explorer displays.

SegWit serialization adds a marker and flag after the version, then places witness stacks after the outputs and before locktime. Parsers must follow the exact format; one missing byte can shift every field that follows.

2

Inputs point to earlier outputs

Each input contains an outpoint: a previous transaction identifier and output index, often called vout. It also includes an unlocking script or empty script field, plus nSequence. SegWit authorization data is carried in the input's witness stack.

The input does not store a balance. A node uses the outpoint to find the previous output in its UTXO set, read that output's value and spending condition, and then evaluate the new transaction against it.

3

Outputs define new spendable value

Each output contains an amount in satoshis and a locking script, or scriptPubKey. The locking script defines the evidence a future input must provide. Wallets encode common script templates as addresses for safer human exchange, but addresses are not stored inside the transaction.

The transaction fee is not a dedicated output. It is the difference between the total value of valid inputs and the total value assigned to outputs.

4

txid and wtxid commit to different views

The txid is derived from the non-witness serialization. For a SegWit transaction, the wtxid is derived from the serialization that includes witness data. A non-SegWit transaction has the same txid and wtxid.

Human-readable transaction identifiers are conventionally displayed with the hash bytes reversed relative to their internal serialized order. This display convention does not change the underlying hash or security property.

5

Decode before you trust a summary

A decoder can reveal version, outpoints, output values, scripts, witness stacks, virtual size and locktime. That is valuable for learning and troubleshooting, but a decoded transaction is not automatically valid, standard, signed or broadcast.

Do not hand-edit raw transactions that control meaningful funds unless you fully understand signing digests, change handling, fee calculation and policy rules. Use maintained wallet software and test on regtest or signet when learning.

Visual recap

The serialized transaction

Nodes parse one ordered byte stream into references, new outputs, authorization data and timing rules.

01

Version

02

Input outpoints

03

Scripts or witness

04

Output values and locks

05

Locktime

06

txid and wtxid

Key vocabulary

Terms worth knowing

Serialization
The exact conversion of structured fields into an ordered byte sequence.
Outpoint
A previous transaction identifier plus output index that identifies the UTXO an input attempts to spend.
wtxid
The identifier derived from a transaction serialization that includes SegWit witness data.

Worked example

A wallet summary hides a change output

A wallet says it is sending 70,000 sats, while the decoded transaction consumes a 100,000-sat input and creates two outputs.

  1. 1Identify the previous outpoint
  2. 2Read both output values
  3. 3Recognise the recipient and likely change output
  4. 4Subtract outputs from input value
  5. 5Confirm that the difference is the fee

The raw transaction exposes UTXO movement. Wallet labels such as recipient and change are interpretations built from wallet context.

Common misconceptions

What learners often get wrong

Misconception

The fee appears in a fee field.

More accurate

Nodes derive the fee from input value minus output value.

Misconception

A transaction stores Bitcoin addresses in its outputs.

More accurate

Outputs store values and locking scripts; wallets encode standard destinations as addresses for people.

Try it yourself

Decode a public test transaction without signing or broadcasting anything.

  • Use a maintained decoder or local node
  • Locate version and locktime
  • List each input outpoint
  • List output values and script types
  • Compare txid and wtxid when witness is present

Use fictional values and public information only. Never enter seed words, private keys or other wallet secrets into a learning exercise.

Key takeaways

  • Raw transactions are ordered serialized fields, not explorer account entries.
  • An input identifies a previous output using a txid and output index.
  • An output contains satoshis and a locking script, not an address string.
  • Fees equal input value minus output value.
  • SegWit transactions can have different txid and wtxid values.

Lesson recap

Check what you learned

Reveal each model answer, then honestly mark whether you understood it or need another review.

1 of 3

Recall

Where is the transaction fee written in a raw transaction?

References

Further reading

Lesson progress

Loading progress...

Rate this lesson

Was this lesson helpful?

No name or financial information is collected.

Found inaccurate or outdated information? Report a correction