The Change Architect: Calculating and Managing Change Outputs
15. The Change Architect: Calculating and Managing Change Outputs
In the "Forge of the Ledger," almost every payment results in a "Leftover." If you spend a 1 BTC coin to pay someone 0.1 BTC, the other 0.9 BTC comes back to you as a Change Output. But "Change" is not free. It adds size to your transaction, it creates a new UTXO in your inventory, and it "Links" your identity to the recipient. The wallet's Change Logic is the "Architect of the Residual," deciding exactly how much change to make and when to avoid making it altogether. It is the "Efficiency of the Residual."
For the Sovereign Architect, change is the "Shadow of the Payment." If you manage it poorly, your wallet will fill up with hundreds of tiny "Dust" coins that cost more to spend than they are worth. If you manage it well, you will maintain a "Lean Inventory" of high-value coins.
Analyzing the Change Target: m_cost_of_change
In the source code, the wallet calculates if a change output is "Economically Viable" by comparing its value to the cost of creating and spending it.
/**
* This function calculates the "Price of a Leftover."
*/
void RecalculateChangeTarget(CFeeRate feerate, ...)
{
// 1. Calculate the "Fee" to create the change output NOW.
CAmount change_fee = feerate.GetFee(change_output_size);
// 2. Calculate the "Future Fee" to spend this change later.
// We use a "Long-Term Fee Rate" (LTFR) as an estimate.
CAmount future_spend_fee = long_term_feerate.GetFee(input_size);
// 3. The "Cost of Change" is the sum of both.
m_cost_of_change = change_fee + future_spend_fee;
// 4. If the leftover is LESS than this cost, we "Avoid Change."
// The extra money is given to the miners as a "Bounty."
}
Explaining the Change: The Recycled Material
-
long_term_feerate: The computer asks: "What is the average price of block space over the last month?" This is the "Baseline Fee." By using this to estimate the "Future Cost" of your change, the wallet avoids making "Economic Mistakes." It will not create a change output today if it knows you will not be able to afford to spend it in the future. It is the "Economic Foresight of the Core." -
"Bounty" (Mining Tip): If you have $0.10 in change, but it costs $0.50 to record that change on the blockchain, you are losing money just by trying to keep it. In this case, Bitcoin Core is smart enough to say: "Just give the $0.10 to the miners." This keeps your wallet "Clean" of dust. It is the "Pruning of the Vault."
-
change_output_size: A change output is just data (a script and an amount). The wallet knows exactly how many "vBytes" this data takes up. By multiplying this by your "Fee Rate," it knows the "Price of the Leftover." It is the "Precision of the Costing."
The "Change Address" Strategy
In a modern Bitcoin Core wallet, change is always sent to a "New Address" (Address Rotation). This ensures that your "Internal Change" is not easily linked to your "Main Balance." To the outside world, your change looks like just another payment. This "Camouflage of the Residual" is one of the most important privacy features of the wallet. You are the "Master of the Rotation," ensuring your financial "Shadows" are always moving.
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: