TeachMeBitcoin

Anatomy of a Bitcoin Transaction: The Anchor Guide to Data Structure

From TeachMeBitcoin, the free encyclopedia Reading time: 5 min

Anatomy of a Bitcoin Transaction: The Anchor Guide to Data Structure

IMPORTANT

Executive Summary: A Bitcoin transaction is a serialized data structure that records the transfer of value from one set of cryptographic locks to another. Unlike legacy bank accounts, which use a "Balance Model," Bitcoin utilizes a "UTXO Model" where transactions consume existing "inputs" and create new "outputs." Every transaction is a mathematical proof that satisfies the conditions of previous ledger entries while creating new ones for future use.


🔍 Why This Module Matters

The "Transaction" is the atomic unit of the Bitcoin network. Every block, node, and miner exists solely to validate and store these data packets. To understand Bitcoin at a technical level, you must move beyond the "address-to-address" metaphor and understand the raw byte structure. This module will deconstruct the five mandatory fields of a transaction, explaining how they facilitate cryptographic signatures, timelocks, and the preventions of double-spending.


🏛️ The Structure of Value: A 6-Field Schema

A raw Bitcoin transaction is a stream of hexadecimal bytes. When a node receives these bytes, it parses them according to a strict physical schema.

Field Size (Bytes) Description Technical Name
Version 4 Defines the ruleset (e.g., V2 allows Relative Timelocks). nVersion
Input Count 1-9 Number of inputs being consumed. vin_count
Input List Variable References to previous transaction outputs (UTXOs). vin
Output Count 1-9 Number of new outputs being created. vout_count
Output List Variable The amounts and locking scripts for the recipients. vout
LockTime 4 Defines a future block/time when the TX becomes valid. nLockTime

⚙️ Section Breakdown: Deep Dive into the Data

1. The Input (vin): The Reference to the Past

An input is not "money." It is a Proof of Ownership.

2. The Output (vout): The Promise for the Future

An output is where the "New" coins are defined.

3. nLockTime: The Time-Warp Defense

This 4-byte field allows users to create transactions that are "Not Valid Yet."

graph LR
 subgraph Transaction_A
 A1[Input: Prev_TXID_01] --> A2[Output 0: 0.5 BTC]
 A1 --> A3[Output 1: 0.2 BTC]
 end
 subgraph Transaction_B
 B1[Input: Points to TX_A_Output_0] --> B2[Output 0: 0.49 BTC]
 B1 --> B3[Output 1: 0.01 BTC Fee]
 end
 Transaction_A --> Transaction_B

💎 The "Account-less" Advantage: Why UTXO?

Why does Bitcoin use this complex structure instead of a simple "Balance" like a bank?

  1. Parallel Processing: Nodes can verify thousands of transactions simultaneously because they don't have to check a single account balance; they just check if the inputs exist and are signed.

  2. Stateless Privacy: A single user can have thousands of UTXOs across thousands of different addresses. There is no single "Account" that tracks their net worth.

  3. Traceability: Every satoshi in existence can be traced back through a perfectly linked chain of inputs and outputs to its original coinbase block.


🛡️ Serialization: The Network's Language

When your wallet sends a transaction, it "Serializes" it—converts the structured data into a flat string of bytes.

Component Standard SegWit (Witness)
Location Integrated Separated (Discounted)
Weight 1 byte = 4 weight units 1 byte = 1 weight unit
Malleability High None (Fixed)

🎯 Learning Objectives for this Module

By the end of this module, you will be able to:

  1. Identify the five core sections of a Bitcoin transaction.

  2. Describe the relationship between an Input's OutPoint and a previous Output.

  3. Explain how nLockTime creates a delayed validity for a transaction.

  4. Understand the difference between a Locking Script and an Unlocking Script.

  5. Differentiate between the UTXO model and the Account/Balance model used by banks.


🗺️ Module Roadmap: What's Next?

We will now explore the specific functional components of transactions:

  1. Unlocking Scripts: How signatures "prove" ownership.

  2. Locking Scripts: Setting conditions for future spenders.

  3. Transaction Fees: How to calculate the difference between inputs and outputs.

  4. Timelocks (CLTV & CSV): Creating complex time-delayed smart contracts.


🎓 Summary

A Bitcoin transaction is a self-contained proof of value transfer. By linking inputs and outputs in a cryptographic chain, Bitcoin ensures that no coin can ever be spent twice and no value can be created out of thin air. Mastery of transaction anatomy is the foundation for all advanced Bitcoin development.

☕ Help support TeachMeBitcoin

TeachMeBitcoin is an ad-free, open-source educational repository curated by a passionate team of Bitcoin researchers and educators for public benefit. If you found our articles helpful, please consider supporting our hosting and ongoing content updates with a clean donation:

Ethereum: 0x578417C51783663D8A6A811B3544E1f779D39A85
Bitcoin: bc1q77k9e95rn669kpzyjr8ke9w95zhk7pa5s63qzz
Solana: 4ycT2ayqeMucixj3wS8Ay8Tq9NRDYRPKYbj3UGESyQ4J
Address copied to clipboard!