The Anatomy of a Transaction: Inputs, Outputs, and the Flow of Value
The Anatomy of a Transaction: Inputs, Outputs, and the Flow of Value
Before we can pick up the drafting tools and start building our own movements of value, we must understand the "Anatomy" of the object we are creating. A Bitcoin transaction is not a single, unified entity; it is a "Link" in a chain, a "Bridge" between the history of the vault and its future. Every transaction is composed of two main parts that act as the "Heart and Lungs" of the movement: Inputs and Outputs. This structure is the "Engine of the Ledger," the "Physics of Value" that ensures no money is ever created or destroyed out of thin air. It is a system of "Total Conservation," where the energy of the past is reformed into the utility of the future. It is a mathematical poem of balance that keeps the global ledger in a state of perfect auditability.
The Sources of Wealth: Transaction Inputs (vin)
The Inputs are the "Sources" of the wealth. One of the most common misconceptions for beginners is that Bitcoin is stored in "Accounts" or "Balances," much like a traditional bank account or a PayPal balance. In reality, there are no accounts in the Bitcoin Core. There is only a massive, global pile of "Unspent Transaction Outputs" (UTXOs). Think of an input as a "Voucher" or a "Legal Reference" that points back to a specific page in the ledger's history. It says, "On this date, at this block height, I was sent 5 BTC in Transaction X. I am now using that 5 BTC to power this new movement." It is the "DNA of the Source," carrying the history of the coin forward into a new expression. Without an input, a transaction has no power; it is an attempt to create wealth from nothing, which the "Librarian" will immediately reject.
In the source code of the Core, an input is represented by the CTxIn class. It is a remarkably lean and efficient structure because it only needs to provide two essential pieces of information:
-
COutPoint: This is the "GPS Coordinate" of the source coin. It consists of the Transaction ID (the 64-character hash) and the "Vout" (the index number of the output in that transaction). This coordinate is the "Universal Identity" of the wealth. It tells the node exactly where in the billions of bytes of history this specific coin is located. It is the "Anchor of Reality" in a sea of data.
-
ScriptSig / Witness: This is the "Key" that unlocks the source. It is the proof—usually a digital signature—that the person creating this new transaction has the legal and mathematical authority to move the coins referenced by the coordinate. Without this proof, the "Librarian" (the validation engine) will reject the blueprint immediately. It is the "Voice of Consent" in the digital world, the final word that allows wealth to flow.
The Destinations of Wealth: Transaction Outputs (vout)
The Outputs are the "New Destinations" for the wealth. An output defines where the money is going and, more importantly, the "Conditions" required for someone else to spend it in the future. If the inputs are the "Roots" of the transaction, gathering the energy of the past, the outputs are the "Fruit," providing sustenance for the future. They are the "Potential Energy" of the network, waiting for the right key to release them. A single transaction can have multiple outputs, allowing you to pay many people simultaneously or to split your coins into smaller denominations.
In the Core's internal logic, an output is represented by the CTxOut class. It contains:
-
nValue: The specific amount of Bitcoin being sent to this destination. This is always measured in "Satoshis"—the smallest unit of Bitcoin (100 million satoshis = 1 BTC). The node does not work with decimals; it works with whole integers of satoshis to avoid rounding errors. This is "High-Precision Accounting" at its most fundamental level. Every satoshi is a "Grain of Truth" in the digital silo, and the Core tracks every single one with absolute zero tolerance for error.
-
scriptPubKey: The "Lock" on the output. This is a small, powerful piece of computer code written in a language called "Script." It doesn't say "Send to Bob." Instead, it says, "Whoever can provide a signature for Public Key X is allowed to spend these 5 BTC in the future." This "Locking Script" is the foundation of Bitcoin's security and its programmability. It is the "Guardian of the Value," ensuring that only the rightful owner can ever access the funds.
The Conservation of Value: The UTXO Model and the Law of Energy
Imagine the blockchain as a series of connected pipes in a vast, global irrigation system. Water (Bitcoin) flows out of one pipe (an output) and into the next pipe (an input). A transaction is the "Joint" or the "Valve" that connects these pipes. The "Librarian" enforces a strict law of physics: the total amount of water flowing into the joint from the inputs must be equal to the total amount flowing out through the outputs. If there is a small "Drip" or "Leak" left over, that remainder is not lost—it is given to the miner as a fee. This is the "Toll of the Messenger," the economic incentive that keeps the planes flying and the servers humming. This conservation law is what prevents "Double Spending" and ensures that the total supply of Bitcoin never exceeds 21 million.
This is the UTXO Model. At any given moment, the "Total Wealth of the Bitcoin Network" is simply the sum of every output that has been created but not yet used as an input. These are the "Waiting Coins." Every time you spend Bitcoin, you are "Destroying" an old output and "Creating" new ones. It is a process of "Continuous Rebirth." By understanding this anatomy, you are learning to read the "Universal Language" of decentralized finance. You are seeing the "Skeleton of the Global Bank," a system that requires no trust because its anatomy is visible to everyone at all times. This model is what gives Bitcoin its "Immutable Auditability"—you can trace every satoshi back to its origin in the "Genesis Block" of 2009. It is the "Ancestry of Wealth," a lineage that can be verified by any node in the world.
Analyzing the "Structure" in the C++ Source: The Core’s DNA
In the header file src/primitives/transaction.h, we find the "Definition of Reality" for a transaction. This is the code that every node in the world—whether it's running on a high-powered server in a data center or a solar-powered laptop in a remote village—uses to understand what a transaction is. It is the "Biological Blueprint" of the system, the fundamental law of the digital universe that overrides all human opinion and politics.
/**
* The basic transaction that is broadcasted on the network and contained in
* blocks. A transaction can contain multiple inputs and outputs.
* This is the "Skeletal Structure of Value."
*/
class CTransaction
{
public:
// Every blueprint has a version, defining the laws it follows.
// Version 1 was the legacy; Version 2 enabled complex time-locks.
static constexpr int32_t CURRENT_VERSION=2;
// The list of inputs (The Sources from the past).
// These are the "Atomic units" of historical wealth.
const std::vector<CTxIn> vin;
// The list of outputs (The Destinations for the future).
// These are the "New Seeds" being planted in the ledger.
const std::vector<CTxOut> vout;
// The Version Number (The Dialect of the Language).
const int32_t nVersion;
// The Locktime (The Temporal Seal).
// This defines "When" the transaction becomes valid.
const uint32_t nLockTime;
// ... (Utilities for hashing and serialization)
};
Explaining the Code to a Non-Coder: Sidebars of Clarity
-
std::vector<CTxIn> vin: A "Vector" is simply a "List" or a "Sequence." This is the list of all the different coins you are gathering together to pay for your transaction. Just as you might pull a $10 bill and two $5 bills out of your physical pocket to pay for a $20 item, thevinlist pulls together multiple sources from across the blockchain. Each entry in this list is a "Claim" on a piece of history. It is the "Inventory of the Past," the collection of artifacts that will power your new architectural masterpiece. -
std::vector<CTxOut> vout: This is the list of where the money is going. One output might go to the person you are paying (the "Destination"), and another output might go back to a new address you own (this is called "Change"). It is a "Multi-Output" system, meaning a single transaction can pay a thousand people at once. This is how "Batching" works—the technique that large exchanges use to save on fees and reduce network congestion. Each entry in this list is a "New Reality" being proposed to the network. It is the "Map of the Future." -
nVersionandnLockTime: The version tells the node which rules to use when checking the math. It's like the "Edition" of a law book or a technical specification. The locktime is a "Timer"—it can prevent the transaction from being recorded in the vault until a specific date or block height is reached. It is the "Clock of the Core," allowing for the creation of "Post-Dated Checks" in a decentralized world. It is the "Mastery of Time" over value.
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: