Bitcoin Coin Selection Algorithms Compared
Compare Bitcoin coin selection strategies: Branch-and-Bound, Knapsack, CoinGrinder, FIFO, and largest-first by fee efficiency, privacy, and wallet support.
Coin Selection Algorithms Overview
Every Bitcoin transaction must choose which UTXOs to spend as inputs. This decision, called coin selection, directly affects the transaction fee you pay, whether a change output is created, and how much on-chain information you reveal to chain analysis firms. A poor algorithm can overpay fees by 10% or more on every transaction, while a good one can eliminate change outputs entirely in a significant fraction of payments.
Bitcoin Core v27.0 and later runs four coin selection algorithms in parallel and picks the result with the lowest waste score. Other wallets use different strategies, ranging from simple FIFO ordering to privacy-optimized manual coin control. The table below summarizes the main approaches.
| Algorithm | Goal | Change Output | Best Fee Environment | Privacy Impact |
|---|---|---|---|---|
| Branch-and-Bound (BnB) | Exact match, no change | Avoided | Low to moderate fees | Positive: no change to link |
| Knapsack | Minimize overshoot | Almost always created | Any | Neutral: randomization adds noise |
| Single Random Draw (SRD) | Simple fallback | Usually created | Any | Neutral: random selection order |
| CoinGrinder | Minimum input weight | Usually created | High fees (>30 sat/vB) | Neutral |
| FIFO (Oldest First) | Spend oldest UTXOs first | Usually created | Any | Negative: predictable pattern |
| Largest First | Fewest inputs possible | Usually created (large) | High fees | Negative: predictable, large change |
| Manual Coin Control | User-defined | Depends on user | Any | Positive: if used carefully |
Branch-and-Bound (BnB)
Branch-and-Bound was introduced in Bitcoin Core v0.17.0 (October 2018) based on Mark Erhardt's (Murch) 2016 Master's thesis at Karlsruhe Institute of Technology. The algorithm performs a depth-first search over a binary tree where each branch represents including or excluding a specific UTXO. It searches for an input set that matches the target amount closely enough that no change output is needed.
BnB accepts a small overpayment when the excess is less than the cost of creating and later spending a change output. This makes the resulting transaction smaller (no change output means fewer bytes) and cheaper. In Erhardt's simulations, BnB found changeless matches for approximately 30% of payments. The Bitcoin Core implementation caps the search at 100,000 iterations to prevent excessive computation.
The tradeoff: BnB is not guaranteed to find a solution even when sufficient funds exist, because an exact match may not be possible with the available UTXO denominations. When BnB fails, Bitcoin Core falls back to Knapsack, SRD, or CoinGrinder.
Knapsack
Knapsack is Bitcoin Core's legacy coin selection algorithm, present since the earliest versions of the software. It runs multiple randomized iterations over the wallet's UTXO pool, selecting coins that minimize the overshoot past the target amount plus the minimum change threshold. Each iteration produces a different candidate because the selection order is randomized.
Knapsack almost always produces a change output. Erhardt's thesis showed that despite being designed to find exact matches through randomized attempts, Knapsack rarely achieved changeless transactions in practice. Its randomization does provide a minor privacy benefit: unlike deterministic algorithms, the same wallet balance can produce different input sets for identical payment amounts, making wallet fingerprinting slightly harder.
Single Random Draw (SRD)
Single Random Draw shuffles the available UTXOs randomly and adds them one by one until the accumulated value exceeds the target. It is the simplest algorithm in Bitcoin Core's selection framework and acts as a fallback when BnB and Knapsack both fail to produce an acceptable result.
SRD does not optimize for change avoidance or minimal weight. Its primary value is ensuring that the wallet can always construct a valid transaction when more sophisticated algorithms fail. Because it selects randomly, SRD tends to produce moderate-sized input sets with change outputs.
CoinGrinder
CoinGrinder was added in Bitcoin Core v27.0 (April 2024) via PR #27877. It searches for the input set with the minimum total transaction weight, making it the preferred algorithm when fees are high. At elevated fee rates, every additional input byte is expensive, so CoinGrinder's weight minimization directly translates to fee savings.
CoinGrinder is disabled when the fee rate is below 30 sat/vB, since at low fee rates the cost of extra inputs is small relative to the benefit of UTXO consolidation. CoinGrinder uses a deterministic branch-and-bound search (like BnB) but optimizes for weight rather than change avoidance.
FIFO and Largest-First Strategies
Some wallets, particularly lightweight mobile wallets, use simpler selection strategies. FIFO (First In, First Out) spends the oldest UTXOs first, ensuring that coins do not accumulate indefinitely. Largest-first picks the biggest available UTXOs to minimize the number of inputs.
Both strategies are deterministic and predictable. A chain analysis firm observing a wallet that consistently spends its oldest or largest coins can more easily identify the wallet software and cluster addresses. FIFO tends to produce more inputs than necessary (spending old small UTXOs when a single newer large one would suffice), while largest-first tends to produce unnecessarily large change outputs that reveal balance information.
Bitcoin Core's Waste Metric
Since Bitcoin Core v23.0 (April 2022), the wallet uses a waste metric to compare results from all available algorithms and select the best candidate. The waste score, measured in satoshis, accounts for three components:
- The fee difference between spending inputs at the current fee rate versus a long-term estimated fee rate (the timing cost of spending now rather than later)
- The cost of creating and eventually spending a change output (if one exists)
- Any excess amount paid to the miner beyond the target plus fees (for changeless transactions where overpayment replaces change)
The candidate with the lowest waste score wins. This framework means Bitcoin Core dynamically adapts its selection strategy to current fee conditions: when fees are low, it favors solutions with more inputs (consolidating the UTXO pool), and when fees are high, it prefers minimal input sets.
Wallet Implementation Comparison
Different wallets implement different coin selection strategies. The following table shows which algorithms major Bitcoin wallets support, and whether they offer manual coin control for privacy-conscious users.
| Wallet | Default Algorithm | Manual Coin Control | Notes |
|---|---|---|---|
| Bitcoin Core | BnB + Knapsack + SRD + CoinGrinder (waste metric) | Yes | Runs all four, picks lowest waste |
| Sparrow | BnB with Knapsack fallback | Yes | Strong coin control UI with UTXO labeling |
| Electrum | Proprietary selection | Yes (Coins tab) | Coin control via View > Show Coins |
| Wasabi | Automatic with privacy scoring | Yes (Alt key) | v2.0.3+ reinstated manual selection |
| BlueWallet | Largest-first variant | Yes | Mobile-first, simplified UX |
| Breadwallet / BRD | FIFO (oldest first) | No | Simple mobile wallet approach |
| Mycelium | Pruned FIFO | No | Filters uneconomical UTXOs first |
For a deeper look at which wallets support manual UTXO selection, see our wallet coin control comparison. For privacy-focused selection strategies, see the Bitcoin privacy tools comparison.
Fee Efficiency by Algorithm
The fee efficiency of each algorithm varies dramatically depending on the current fee environment. The table below shows how each algorithm behaves across different fee rate ranges, based on the tradeoffs inherent to each approach.
| Fee Environment | Best Algorithm | Worst Algorithm | Reasoning |
|---|---|---|---|
| Low (<5 sat/vB) | BnB or Knapsack with consolidation | CoinGrinder (disabled) | Extra inputs are cheap; consolidate the UTXO pool |
| Moderate (5-30 sat/vB) | BnB | Largest-first | Change avoidance saves the most; large change wastes fees |
| High (30-100 sat/vB) | CoinGrinder | FIFO | Minimize input count; FIFO may add many small old UTXOs |
| Extreme (>100 sat/vB) | CoinGrinder | FIFO / Knapsack | Weight reduction is critical; every byte costs significantly |
Bitcoin Core's waste metric automates this tradeoff. Wallets without adaptive selection force users to either accept suboptimal fees or manually select inputs through coin control.
Privacy Implications of Coin Selection
Coin selection has direct privacy consequences. The common input ownership heuristic (CIOH) assumes that all inputs in a transaction belong to the same entity. Chain analysis firms implement this using Union-Find data structures: each address starts as its own cluster, and co-spent addresses get merged. Every time your wallet combines UTXOs from different sources, it strengthens this clustering.
Changeless transactions (produced by BnB) offer a privacy advantage because they eliminate the change output that links back to the sender's wallet. However, algorithms that produce consistent patterns (always FIFO, always largest-first) can fingerprint the wallet software itself, which is a separate privacy leak.
For users who need strong privacy, manual coin control remains the gold standard. It allows selecting specific UTXOs to avoid merging coins from different contexts (exchanges, peer-to-peer transactions, CoinJoin outputs). For a comprehensive guide to privacy-preserving UTXO management, see our research on Bitcoin coin control and UTXO privacy.
UTXO Pool Health and Long-Term Strategy
Coin selection is not just about individual transactions. Over time, the algorithm shapes the wallet's entire UTXO set. Algorithms that always pick the largest UTXO create a growing pile of small change outputs that become uneconomical to spend at higher fee rates (stranded UTXOs). Algorithms that consolidate aggressively at low fees keep the UTXO set lean but reduce coin control flexibility.
Bitcoin Core's waste metric addresses this by factoring in a long-term fee rate estimate. When current fees are below the long-term estimate, the metric scores extra inputs as beneficial (consolidating now saves future costs). When current fees are above the long-term estimate, it penalizes extra inputs.
Layer 2 solutions can reduce the pressure on UTXO management entirely. Spark moves Bitcoin payments off-chain, eliminating the need for UTXO selection on routine transactions while preserving self-custody. Users who keep only their long-term savings on-chain can maintain a small, well-managed UTXO set.
Frequently Asked Questions
Which coin selection algorithm does Bitcoin Core use?
Bitcoin Core v27.0 and later runs four algorithms in parallel: Branch-and-Bound (BnB), Knapsack, Single Random Draw (SRD), and CoinGrinder. Each algorithm produces a candidate input set, and the wallet selects the candidate with the lowest waste score. This approach was refined over multiple releases: BnB was added in v0.17.0 (2018), the waste metric became the selection criterion in v23.0 (2022), and CoinGrinder was added in v27.0 (2024).
Does coin selection matter if I use CoinJoin?
Yes. CoinJoin breaks the common input heuristic for the mixed transaction itself, but how you spend the resulting UTXOs afterward determines whether that privacy is preserved. If your wallet automatically combines a CoinJoin output with an unmixed UTXO in a later transaction, the link is re-established. Post-mix coin control is essential: spend CoinJoin outputs individually or only combine them with other mixed outputs of similar provenance.
What is the waste metric in Bitcoin Core?
The waste metric is a scoring function measured in satoshis that evaluates how much a particular input set "wastes" compared to an ideal solution. It sums three components: the timing cost of spending inputs at the current fee rate versus a long-term estimate, the cost of creating and eventually spending a change output, and any excess overpayment to the miner in changeless transactions. Lower waste is better. The metric was introduced as the primary selection criterion in Bitcoin Core v23.0 (April 2022).
Why does change output avoidance reduce transaction fees?
A standard change output adds approximately 31-43 bytes to a transaction (depending on the output type). At a fee rate of 50 sat/vB, a P2WPKH change output costs roughly 15-22 sats to include. Avoiding change also eliminates the future cost of spending that change output as an input in a later transaction (approximately 68 vbytes for P2WPKH). When BnB finds a changeless match, it saves both the immediate output cost and the deferred input cost.
Which coin selection algorithm is best for privacy?
Manual coin control with UTXO labeling offers the strongest privacy because the user decides exactly which coins to combine. Among automatic algorithms, BnB has a privacy advantage through change avoidance (fewer outputs to link). Knapsack's randomization adds minor noise that makes fingerprinting harder. FIFO and largest-first are the worst for privacy because their deterministic patterns are easy to identify and they often combine unrelated UTXOs. For serious privacy needs, use a wallet with strong coin control support like Sparrow or Wasabi.
Should I consolidate UTXOs during low-fee periods?
Yes, if your UTXO set contains many small outputs. Consolidation transactions have many inputs and are large in byte size, so they are cheapest when fee rates drop to 1-5 sat/vB. Bitcoin Core's waste metric naturally favors consolidation during low-fee periods. The tradeoff is privacy: consolidation merges UTXOs from potentially different sources, strengthening address clustering. If privacy matters, consolidate only UTXOs that already share the same provenance.
What is the difference between coin selection and coin control?
Coin selection is the automatic process by which wallet software chooses which UTXOs to spend. Coin control is a manual override that lets the user pick specific UTXOs. Most wallets use automatic coin selection by default and offer coin control as an advanced feature. Privacy-focused users typically prefer coin control because it prevents the wallet from combining UTXOs that the user wants to keep separated.
This tool is for informational purposes only and does not constitute financial advice. Algorithm behavior and wallet implementations change across software versions. Data is based on publicly available documentation and open-source code as of late 2024. Always verify current behavior against the latest release notes for your wallet software.
Build with Spark
Integrate bitcoin, Lightning, and stablecoins into your app with a few lines of code.
Read the docs →
