There is no balance in a Bitcoin wallet. There is a collection of unspent outputs of various sizes, and a payment is made by consuming some of them entirely and returning the remainder to yourself. Which ones to consume is a choice the wallet makes silently, every time, and it is simultaneously a fee decision, a privacy decision and a decision about what your wallet will look like next month.
Why is there a choice at all?
Because inputs are consumed whole, and the combinatorics are large.
To pay 0.3 BTC from outputs of 0.05, 0.1, 0.2 and 0.4, a wallet could spend the 0.4 and return 0.1 as change, or spend 0.1 and 0.2 and return nothing, or spend all four and return a large change output. Each costs a different amount, because every input added makes the transaction bigger and every byte is paid for at the current fee rate.
With a realistic wallet, the number of combinations is far too large to enumerate, so selection is a search problem with several objectives that conflict. Fewer inputs means a smaller transaction now. More inputs means fewer outputs left to spend later, at a fee rate nobody knows. No change output is cheapest and leaks least, and is usually impossible to arrange exactly.
What is the wallet optimising for?
In Bitcoin Core, four algorithms compete and the cheapest answer by one metric wins.
The algorithms are named in the source: BnB (branch and bound), Knapsack, SRD (single random draw) and CG (CoinGrinder), plus a manual mode for coin control. Each takes a different approach. Branch and bound searches for a combination whose total lands close enough to the target that no change output is needed at all. CoinGrinder searches for the lowest-weight solution, which matters when fees are high. Single random draw does what it says, which sounds unserious and has the useful property of being unpredictable to an observer. Knapsack is the older heuristic retained as a fallback.
Core runs the applicable ones, collects the results, and picks the one with the lowest waste. It also tries to avoid mixing output types: it attempts a solution from each script type separately first, and only combines types when no single type can fund the payment. That default is a privacy measure — a transaction spending both legacy and Taproot inputs tells an observer that one wallet holds both.
What is the waste metric?
A single number balancing what inputs cost now against what they will cost later. The formula is in the header and is worth reading literally.
with change: change_cost + inputs × (effective_feerate − long_term_feerate)
without change: excess + inputs × (effective_feerate − long_term_feerate)
The second term is the interesting one. Every input must eventually be spent, at some fee rate; spending it now at the current rate rather than later at the long-term rate is a gain if fees are currently low and a loss if they are high. So when the network is quiet, waste rewards consuming many inputs — you are buying cheap block space for work you would have had to do anyway. When fees are high, the same term punishes it, and selection pulls toward the fewest inputs it can use.
The first term handles change. Creating a change output costs its bytes
now and the bytes to spend it later, which together are change_cost. A
changeless solution avoids both, and pays instead whatever excess it
overshot the target by — a tip to the miner. When that overshoot is less
than the cost of change, giving it away is literally the cheaper option,
which is why branch and bound is tried first.
What the metric does not include is privacy. Waste is denominated in satoshis, and the cost of linking two of your coins has no price.
One more thing the metric knows about is worth noting, because it changes the arithmetic at the margin: an input’s effective value is its amount minus what it costs to spend. An output worth slightly more than its own input fee contributes almost nothing, and one worth less contributes negatively — spending it costs more than it brings. Selection therefore works in effective values rather than face amounts, which is why a wallet showing a balance of a certain size can fail to construct a payment for noticeably less than that. The balance is real and part of it is unreachable at today’s fee rate.
What does your wallet give away when it chooses?
Enough that selection is where most privacy is lost, before any question of addresses arises.
Spending two inputs together asserts that one entity controls both. That is the common-input-ownership heuristic, and it is the foundation of chain analysis — not a probabilistic inference but something close to a proof, since producing both signatures requires both keys.
Change is the second leak. A transaction with two outputs usually has one payment and one change, and an observer who identifies which is which has followed your wallet forward. The tells are familiar: a round-numbered output is a payment, an output whose script type matches the inputs is change, an output that gets spent within minutes is change. Wallets randomise the position of the change output to kill the simplest version, and that is the only one of these defeated by position.
The underrated consequence is that a changeless transaction is a privacy win as well as a fee win. There is nothing to follow forward: every output belongs to someone else.
Does the order of the outputs matter?
It did, it was standardised, and Bitcoin Core deliberately does something else.
BIP 69 proposed that every wallet sort a transaction’s inputs and outputs lexicographically, so that ordering carries no information at all. It is a clean idea: if everyone sorts the same way, the position of the change output tells an observer nothing, because position is determined by the data rather than by the wallet.
The counter-argument is that a deterministic order is itself a fingerprint. A transaction whose outputs happen to be sorted is evidence that it came from a BIP 69 wallet, which narrows the field of candidates — and the benefit only materialises if adoption is near-universal, which it never became. Bitcoin Core randomises the change position instead, giving no information in either direction and no fingerprint either.
This is the same shape as most Bitcoin privacy questions, and worth recognising when it recurs. A defence that works when everyone adopts it can make you more identifiable when few do, because you have joined a small set rather than a large one. The anonymity set is the whole game, and a clever technique with ten users is a label.
When should you consolidate?
When fees are low, deliberately, and not by accident during a payment.
Consolidation — combining many small outputs into one large one — is the same operation as the waste metric’s preference for spending inputs cheaply, made explicit. A wallet holding fifty small outputs will pay a large fee the first time it needs most of them, and doing that work during a quiet week costs a fraction of doing it under pressure.
The cost is privacy, and it is not small. Consolidating links every included output to every other, permanently. If those outputs came from different sources — an exchange withdrawal, a payment from a client, a gift — the consolidation announces that one person received all of them.
So the rule is to consolidate within a context rather than across contexts, and never to let a wallet sweep an unexplained small output into a payment. Dust sent to you by a stranger is sent in the hope of exactly that mistake.
Check it yourself
Bitcoin Core will tell you what it chose and why. Fund a transaction without sending it:
bitcoin-cli -named fundrawtransaction hexstring=<hex> options='{"fee_rate": 10}'
The result reports the fee and the change position, and the debug log names the algorithm that produced the selection when wallet logging is on:
bitcoin-cli logging '["selectcoins"]'
To see the choice change, run the same funding call at a low fee rate and a high one. At a low rate the selection will often pull in more inputs than it needs; at a high rate it will use the fewest it can. That is the waste metric’s second term, visible.
What remains uncertain
Whether the long-term fee rate assumption holds. Waste compares the current rate against a long-term estimate, and the whole consolidation preference rests on that comparison being meaningful. If fee rates trend upward over decades rather than oscillating, spending inputs early was always right and the metric understates it; if a sustained fee market never materialises, the term is noise.
Whether privacy belongs in the metric. Putting a satoshi price on a linkage would let selection trade one against the other, and nobody has proposed a defensible price. The current answer — optimise cost, let users override manually — means the default is the cheapest option, which is rarely the most private one.
What most wallets actually do. The algorithms described here are Bitcoin Core’s. Other wallets use simpler rules, some still spend oldest coins first, and few document their choice. For a user, this is an invisible difference with permanent consequences, and it does not appear in any comparison table.