Coin Selection Strategy

The chosen policy behind coin selection, such as minimise fees, minimise change or protect small coins.

Basically

Your wallet picks which bitcoin coins to use for a payment. Its choice affects fees, privacy, and whether you receive change.

Key Takeaways

  • A coin selection strategy is the algorithm your wallet uses to choose which UTXOs to spend. It directly affects fees, privacy, and future wallet health.
  • Bitcoin Core runs Branch and Bound, Knapsack, Single Random Draw, and CoinGrinder in parallel. It scores each result with a waste metric and keeps the cheapest option.
  • No single strategy wins in all conditions. Low fees favour consolidation with more inputs, high fees favour minimal inputs, and you may prefer avoiding change outputs for privacy.

What Is a Coin Selection Strategy?

A coin selection strategy is the method your Bitcoin wallet uses to decide which unspent transaction outputs (UTXOs) to include as inputs in a new transaction. Bitcoin uses the UTXO model rather than an account model, so every payment must consume one or more discrete "coins" from your wallet's pool. Your wallet's choice determines the transaction's size, fee cost, whether it creates a change output, and how much information it leaks about your wallet's history.

Simple wallets might just take the first UTXOs that cover the payment amount. Production-grade wallets like Bitcoin Core use sophisticated algorithms that weigh current fee rates, long-term fee expectations, change output costs, and the overall health of the UTXO set. They aim to minimise the total economic cost of a transaction, not just the immediate fee.

How It Works

Your wallet follows these steps at a high level every time it builds a transaction. Coin selection determines which UTXOs become inputs.

Different algorithms excel in different conditions. Bitcoin Core runs all its strategies and picks the winner rather than relying on any single approach.

Branch and Bound (BnB)

Branch and Bound searches for an exact-match input set: a combination of UTXOs whose total value equals the payment amount plus fees, with no change output needed. It performs a bounded depth-first search over the UTXO pool. It caps the search at 100,000 iterations to prevent runaway computation.

BnB was introduced in Bitcoin Core 0.17.0 (2018), based on Murch's research thesis on coin selection optimisation. Before BnB, the Knapsack algorithm almost never found exact matches. Simulations showed BnB could eliminate change outputs in up to 30% of transactions.

BnB's key advantage is that no change output means a smaller transaction with lower fees and better privacy, since there is no change address to link back to the sender. Its limitation is that an exact match may not exist for a given payment amount. BnB therefore frequently returns no result.

Knapsack

Knapsack was Bitcoin Core's original coin selection algorithm. It runs multiple random walks over the UTXO pool, selecting coins that push the total past the target. It keeps the combination that minimises overshoot: the difference between the selected amount and the target plus the minimum change amount.

Knapsack almost always produces a change output, which adds weight to the transaction and creates an additional UTXO your wallet must manage later. Despite this downside, its randomised approach provides reasonable results across a wide range of UTXO pool compositions.

Single Random Draw (SRD)

Single Random Draw shuffles the available UTXOs randomly and selects them one by one until the target is met or exceeded. If the resulting transaction would exceed the maximum allowed weight, SRD drops the least valuable inputs, using weight as a tiebreaker, until the transaction fits.

SRD tends to consolidate UTXOs naturally because random draws frequently include small UTXOs that other strategies might skip. This helps keep your wallet's UTXO pool healthy over time. The benefit is especially clear during low-fee periods when the consolidation cost is minimal.

CoinGrinder

CoinGrinder was added in Bitcoin Core 27.0 (2024) to optimise for high-fee environments. It searches for the input set with the smallest total weight, minimising the number of input bytes and therefore the fee. BnB optimises for zero change and Knapsack optimises for minimal overshoot, while CoinGrinder optimises purely for transaction size.

CoinGrinder often produces the winning result during fee spikes because using fewer, larger UTXOs keeps the transaction compact. It complements BnB. When an exact match is not possible, CoinGrinder finds the next cheapest option.

The Waste Metric

Bitcoin Core compares candidates from all four algorithms using a waste metric measured in satoshis. The formula accounts for three components.

The formula naturally adapts to market conditions. When fees are low and below the long-term estimate, the timing cost turns negative and favours solutions with more inputs, so your wallet consolidates UTXOs at a discount. When fees are high, the timing cost is positive and favours minimal input sets to avoid overpaying; for a deeper look at how fee dynamics shape these decisions, see the Bitcoin fee market dynamics research article.

Privacy Implications

Coin selection has significant privacy consequences. Every input in a transaction reveals that those UTXOs belong to the same wallet, a heuristic known as common input ownership. The more inputs a transaction uses, the more of your wallet's history is exposed.

Change outputs also leak information because they create a new UTXO that chain analysis firms can link back to the sender. Strategies like BnB that eliminate change entirely offer a privacy advantage. Coin control takes this further by letting you manually select which UTXOs to spend, avoiding the mixing of coins from different sources.

CoinJoin and PayJoin break the common input heuristic for users who prioritise privacy. You can combine these techniques with careful coin selection to minimise information leakage across transactions.

Fee Optimization

The primary use case for advanced coin selection is reducing transaction fees. A wallet with hundreds of small UTXOs, which is common for Lightning node operators and mining pools, can see dramatically different fee costs depending on which coins it selects. During fee spikes, CoinGrinder or BnB can save 20-40% compared to naive selection by choosing fewer, larger inputs.

UTXO Consolidation

Wallets accumulate small UTXOs over time, especially those receiving frequent payments. During low-fee periods, the waste metric encourages SRD and Knapsack to include extra inputs, naturally consolidating the UTXO pool. This prevents stranded UTXOs that cost more to spend than they are worth, a problem known as dust; for strategies on managing this proactively, see the UTXO management strategies research article.

Exchange and Payment Processor Wallets

High-volume wallets on exchanges and payment processors handle thousands of withdrawals daily. Efficient coin selection combined with transaction batching can reduce on-chain fees by orders of magnitude. These operations typically run custom coin selection tuned to their specific UTXO distribution and fee targets.

Layer 2 Channel Funding

Opening Lightning channels or funding other Layer 2 constructs requires on-chain transactions. Your choice of inputs affects the funding transaction's fee and the resulting channel's on-chain footprint. Wallets like LDK-based implementations let developers plug in custom coin selection to optimise for their use case.

Why It Matters

Coin selection is one of the most impactful yet least visible parts of a Bitcoin wallet. You rarely think about which UTXOs are being spent, but the algorithm's choices compound over time. Poor coin selection leads to a fragmented UTXO pool, higher future fees, dust accumulation, and reduced privacy, while good coin selection keeps fees low, maintains a healthy UTXO set, and minimises the information footprint of each transaction.

Wallet developers building on Bitcoin Layer 2 systems like Spark must also consider coin selection when constructing on-chain transactions for channel opens, closes, and splices. The coin selection algorithm comparison research article provides a detailed analysis of how each strategy performs across different fee environments and UTXO distributions.

No Universal Best Strategy

Each algorithm makes tradeoffs. BnB is optimal when it finds an exact match, but it fails frequently, while CoinGrinder minimises fees but may create large change outputs. Knapsack provides consistent results but rarely finds the cheapest option; the multi-strategy approach mitigates this, but the waste metric itself embeds assumptions about future fee rates that may prove wrong.

Privacy vs. Fee Tradeoffs

Consolidating UTXOs during low-fee periods is economically rational but links multiple addresses together on-chain. You may need to accept higher fees if you prioritise privacy. You can limit input counts or use coin control to manually select inputs from isolated sources.

Dust and Stranded UTXOs

Small UTXOs may become uneconomical to spend if your wallet accumulates many of them and fees rise sharply. Their value is less than the fee required to include them as inputs. This is the stranded UTXO problem, and proactive UTXO consolidation during low-fee windows is the standard mitigation.

Implementation Complexity

Building correct coin selection is non-trivial. Edge cases include transactions that exceed the maximum weight, UTXOs with different script types, which affect input weight calculations, and interactions with replace-by-fee where your wallet must select coins for a replacement transaction that conflicts with the original. Libraries like Bitcoin Core's built-in coin selection and the standalone coin selection libraries handle these edge cases, but custom implementations require careful testing.

The glossary entry is for informational purposes only and does not constitute financial or investment advice. Always do your own research before using any protocol or technology.

0

← All 1876 glossary terms