You send a small payment. Routine. The wallet confirms, you glance at the fee line, and something is wrong: you just paid nearly as much to move the money as the money is worth. The amount was fine. The recipient address was fine. The wallet simply reached into its pile of coins and grabbed the wrong ones, in the wrong order, for reasons it never bothered to explain.

That is coin selection failing you. It happens on every transaction, visible or not.

The Pile of IOUs Under Your Balance

Bitcoin does not store your balance as a single number in a ledger. It stores a collection of unspent transaction outputs, UTXOs, each one a discrete chunk of bitcoin received at some point. Your wallet balance is the sum of those chunks. Spend some bitcoin and your wallet is actually selecting which chunks to use as inputs, combining and splitting them to cover the amount you want to send plus a fee.

Think of it like a change drawer stuffed with bills from different transactions. You owe someone $47. Do you hand over two $20s and a $10 and wait for change? Three $20s and pocket $13 back? One $50 and receive three $1s in return? Each approach touches a different number of bills, creates a different amount of clutter, and takes a different number of seconds at the register. Now imagine that every bill you handle costs a small fee proportional to how many bills you touch. Suddenly the order of operations matters quite a lot.

Why the Algorithm Has a Hard Job

Coin selection is an NP-hard optimization problem in its general form. A wallet holding 200 UTXOs of varying sizes has an astronomically large number of possible input combinations for any given payment. No wallet iterates through all of them.

Instead, they use heuristics. And the heuristic chosen shapes everything downstream.

The oldest and simplest strategy is largest-first: grab the biggest UTXOs until you've covered the target amount. It minimizes input count, keeps transaction size down, and holds fees low in the short term. It also tends to leave a graveyard of tiny UTXOs untouched, accumulating in your wallet like loose change behind the sofa cushions. Over dozens of transactions, those pennies become a structural problem.

The opposite approach, smallest-first, consolidates dust but inflates input counts on every transaction, driving fees up immediately even when there is no benefit to doing so. Neither extreme is obviously correct. The best real-world strategies sit somewhere between them, and they account for something the naive approaches ignore entirely: the cost of spending a UTXO later is always non-zero.

Branch and Bound: The Algorithm That Actually Thinks Ahead

The most sophisticated coin selection algorithm in widespread use is Branch and Bound, first described by Murch (Mark Erhardt) in his 2016 master's thesis and implemented in Bitcoin Core's wallet. It deserves a real explanation.

Branch and Bound tries to find an exact match: a combination of UTXOs that covers the payment amount plus fee precisely, producing zero change. No change output means a smaller transaction, a lower fee, and one less UTXO created in the world. The algorithm explores a binary decision tree where each UTXO is either included or excluded, pruning branches that cannot possibly yield a valid solution. It runs with a configurable cost target and a waste metric that penalizes unnecessary input weight. When no exact match exists within a reasonable search budget (the implementation caps the search to avoid grinding), it falls back to a knapsack-style selection or a single-random-draw approach, then adds a change output.

Here is a worked scenario with specific numbers. You want to send 0.05 BTC. Your wallet holds three UTXOs: 0.03 BTC, 0.02 BTC, and 0.08 BTC. Branch and Bound finds that 0.03 + 0.02 = 0.05 exactly, selects those two, pays the fee from a slight overage, and produces no change output at all. A largest-first algorithm grabs the 0.08 BTC UTXO, sends 0.05, and returns roughly 0.03 BTC to you as change, creating a new UTXO, slightly inflating the transaction, and incurring a marginally higher fee. Over thousands of wallets running thousands of transactions, that difference compounds into something measurable.

Wallets running Branch and Bound produce fewer change outputs over time. Fewer change outputs mean fewer UTXOs. And the global UTXO set size is, it turns out, everyone's concern.

The UTXO Set Is Everyone's Problem

Every full Bitcoin node maintains a complete copy of the UTXO set in memory. That set contains tens of millions of entries and occupies several gigabytes of RAM. Every new unspent output added to it imposes a cost on every node operator on the planet, indefinitely, until that output is eventually spent.

Dust outputs are particularly corrosive. A UTXO worth 500 satoshis costs roughly 68 vbytes to spend as an input. At a fee rate of 10 sat/vbyte, spending it costs 680 satoshis. You would spend more in fees than you would recover. So that UTXO sits in the set indefinitely, doing nothing useful except consuming node memory across the entire network.

Wallets that generate excessive change outputs, particularly small ones, are quietly externalizing costs onto every node operator and onto every future user who runs a node. It is the tragedy of the commons, one dust output at a time. This is not a neutral design choice; it is a decision with real externalities, and wallet developers who shrug at it are making a mistake.

Good coin selection addresses this in two ways: by targeting exact matches to avoid change entirely when possible, and by deliberately consolidating small UTXOs during low-fee periods. Some wallets implement automatic consolidation, bundling several small inputs into a single larger output when fees are low. It costs a fee now and saves more in the future.

Two Wallets, One Payment, Different Outcomes

Consider two people, Priya and Daniel, who both receive bitcoin through similar patterns over two years: regular small purchases, occasional larger transfers, the odd refund. Both end up with wallets containing roughly 40 UTXOs.

Priya's wallet uses a basic largest-first algorithm. Each payment grabs the biggest available UTXO, generates change, and deposits a new small UTXO back into the wallet. Her UTXO count creeps upward. By month 18, she holds 60 UTXOs, several under 1,000 satoshis. When she tries to send a medium-sized payment during a congested period, her wallet assembles 9 inputs. Her transaction is 1,400 vbytes. At 25 sat/vbyte, she pays 35,000 satoshis in fees.

Daniel's wallet uses Branch and Bound with periodic consolidation. It found exact matches on roughly 30% of his transactions, eliminating change outputs on those. It ran a consolidation pass when fees dropped to 3 sat/vbyte, merging 15 small UTXOs into 3 larger ones for a one-time cost of about 4,200 satoshis. His UTXO count sits at 28. The same medium payment requires 3 inputs, produces a 600 vbyte transaction, and costs 15,000 satoshis at the same fee rate.

Same usage pattern. Same network conditions. The difference is entirely in how the wallet managed its coin pile.

One Thing That Trips People Up

A common misconception: lower fee rates always mean lower fees paid. Not quite, and the arithmetic is worth following. Transaction fees are fee rate multiplied by transaction size in virtual bytes. A wallet that assembles 12 inputs to avoid paying a slightly higher rate on fewer inputs can easily cost more in absolute terms. You are not paying per transaction. You are paying per byte.

This is why consolidation during low-fee periods is financially rational even though it means spending money when you have no immediate need to. You are buying smaller future transactions in advance, at a discount. Think of it as prepaying for efficiency.

One further complication worth noting: privacy-conscious coin selection, where a wallet avoids linking UTXOs from different sources in a single transaction, can directly conflict with fee-minimizing selection. There is a real tradeoff there. Some wallets let you configure which goal takes priority. Most do not, and the ones that hide this from you are making a choice on your behalf without telling you.

Check Your Own UTXO Count

Most wallets do not surface this information prominently, but many will show it if you look. In Bitcoin Core, `listunspent` in the console gives you the full picture. Sparrow Wallet shows UTXO details in a dedicated tab. Electrum surfaces them under the Coins view.

So here is the question worth asking yourself: when did you last look?

If you are sitting on fewer than 20 UTXOs with none under a few thousand satoshis, you are in decent shape. If you have 80 UTXOs and a long tail of dust, the next low-fee window is a consolidation opportunity, not merely a cheap time to send.

Coin selection is the kind of mechanism that works silently until it doesn't, at which point you are overpaying fees on a congested afternoon and wondering why. The wallet you choose and the way you use it either compounds good decisions over time or quietly accumulates the cost of bad ones. Your UTXO count is the ledger.