<p>By default, Bitcoin Core will only spend foreign inputs that have at least six confirmations, and change outputs that have at least one confirmation. If you want to use younger foreign inputs, you can use the <code>minconf</code> parameter present e.g. on <code>sendmany</code>.</p>
<p>Beyond that, Bitcoin Core will split its UTXO pool by output type, and then for each output type uses multiple algorithms to construct one input set candidate. Among all of these candidate input sets, it chooses the least wasteful per the <a href="https://bitcoin.stackexchange.com/q/113622/5406">waste metric</a>.</p>
<p>The algorithms in use in Bitcoin Core v25.1 are <em>knapsack algorithm</em>, <em>single random draw</em>, and <em>branch and bound</em>.</p>
<ul>
<li>Knapsack will perform numerous random walks on all UTXOs with amounts lower than the target to assemble an input set that overshoots <code>target + min_change</code> the least, or pick the <em>lowest larger</em> UTXO if that is closer to <code>target + min_change</code>.</li>
<li>SRD will shuffle all UTXOs and pick from this shuffled list until it has collected enough funds to fund the transaction</li>
<li>BnB will attempt to find an input set that avoids creating change. If there are multiple solutions, it will prefer the least wasteful.</li>
</ul>
<p>None of the above algorithms actually minimize the input set weight. Hence, I am proposing that we add an algorithm that minimizes the input set weight in <a href="https://github.com/bitcoin/bitcoin/pull/27877" rel="nofollow noreferrer">PR#27877</a>, which at the very least should be run at high feerates. The downside of such an algorithm would be that it could bloat a wallet’s UTXO pool when used excessively, but it would ensure an optimal outcome in the short-term. So far, this proposal has not gotten sufficient support to be added to Bitcoin Core.</p>
<p>There are currently no configuration options that directly affect the general coin selection behavior. You would have to perform coin selection manually or externally and build raw transactions to optimize fee expenditure.</p>

CC BY-SA 4.0
2023-11-28T17:42:26.713Z
2023-12-21T20:45:10.847Z
2023-12-21T20:45:10.847Z
Murch
<p>please help me understand the algorithm for selecting UTXO when forming a new transaction in Bitcoin.</p>
<p>For example, my wallet has a lot of incoming transactions (thousands of transactions in amounts of 0.001-0.09 BTC that have more than 70 confirmations and several transactions in amounts of 2-3 BTC that have 2-5 confirmations). When sending a new transaction in the amount of 1.5 BTC, the node for some reason creates a transaction with 500+ inputs for small amounts, thereby the weight of the transaction is 75 kb and, accordingly, the amount of miner's fees increases to enormous values. But if the node sent a transaction from an address that had 2 BTC, the miners's fees to would be minimal.</p>
<p>Please tell me how the node chooses which UTXOs to assemble a new transaction from? What settings on the node can regulate this?</p>
<p>I tried to find an answer on Google, but I couldn't find anything similar.</p>

CC BY-SA 4.0
2023-11-10T09:26:39.390Z
Does this answer your question? [How does the Branch and Bound coin selection algorithm work?](https://bitcoin.stackexchange.com/questions/119919/how-does-the-branch-and-bound-coin-selection-algorithm-work)
Vojtěch Strnad
CC BY-SA 4.0
2023-11-10T12:41:17.587Z
I don't think that's a duplicate of the question about BnB. I think an answer here should describe what coin selection is, what Bitcoin Core is using (and link to the BnB answer for more details, potentially), what options influence Bitcoin Core's coin selection and maybe mention coin control.
Antoine Poinsot
<transactions><transaction-fees><coin-selection>
How bitcoin node selects the output unspent transactions when sending bitcoin?
Ketut Bakle
# How bitcoin node selects the output unspent transactions when sending bitcoin?

(Asked by: username_0 on 2023-11-10)

please help me understand the algorithm for selecting UTXO when forming a new transaction in Bitcoin.

For example, my wallet has a lot of incoming transactions (thousands of transactions in amounts of 0.001-0.09 BTC that have more than 70 confirmations and several transactions in amounts of 2-3 BTC that have 2-5 confirmations). When sending a new transaction in the amount of 1.5 BTC, the node for some reason creates a transaction with 500+ inputs for small amounts, thereby the weight of the transaction is 75 kb and, accordingly, the amount of miner's fees increases to enormous values. But if the node sent a transaction from an address that had 2 BTC, the miners's fees to would be minimal.

Please tell me how the node chooses which UTXOs to assemble a new transaction from? What settings on the node can regulate this?

I tried to find an answer on Google, but I couldn't find anything similar.

**Tags:** transactions, transaction-fees, coin-selection

> **Comments:**
> **username_1**: Does this answer your question? [How does the Branch and Bound coin selection algorithm work?](https://bitcoin.stackexchange.com/questions/119919/how-does-the-branch-and-bound-coin-selection-algorithm-work)  
> **username_2**: I don't think that's a duplicate of the question about BnB. I think an answer here should describe what coin selection is, what Bitcoin Core is using (and link to the BnB answer for more details, potentially), what options influence Bitcoin Core's coin selection and maybe mention coin control.  

---

## 1 answers

### Answer by username_3 on 2023-11-28. Score: 1

By default, Bitcoin Core will only spend foreign inputs that have at least six confirmations, and change outputs that have at least one confirmation. If you want to use younger foreign inputs, you can use the `minconf` parameter present e.g. on `sendmany`.

Beyond that, Bitcoin Core will split its UTXO pool by output type, and then for each output type uses multiple algorithms to construct one input set candidate. Among all of these candidate input sets, it chooses the least wasteful per the [waste metric](https://bitcoin.stackexchange.com/q/113622/5406).

The algorithms in use in Bitcoin Core v25.1 are *knapsack algorithm*, *single random draw*, and *branch and bound*.

* Knapsack will perform numerous random walks on all UTXOs with amounts lower than the target to assemble an input set that overshoots `target + min_change` the least, or pick the *lowest larger* UTXO if that is closer to `target + min_change`.
* SRD will shuffle all UTXOs and pick from this shuffled list until it has collected enough funds to fund the transaction
* BnB will attempt to find an input set that avoids creating change. If there are multiple solutions, it will prefer the least wasteful.

None of the above algorithms actually minimize the input set weight. Hence, I am proposing that we add an algorithm that minimizes the input set weight in [PR#27877](https://github.com/bitcoin/bitcoin/pull/27877), which at the very least should be run at high feerates. The downside of such an algorithm would be that it could bloat a wallet’s UTXO pool when used excessively, but it would ensure an optimal outcome in the short-term. So far, this proposal has not gotten sufficient support to be added to Bitcoin Core.

There are currently no configuration options that directly affect the general coin selection behavior. You would have to perform coin selection manually or externally and build raw transactions to optimize fee expenditure.


---

