<p>Bitcoin Core uses a Branch and Bound algorithm to search for an input set that exactly matches the send request. To that end, it will deterministically search the combination space of all of its available utxos and pick the set that is the most efficient if there are multiple solutions. The Branch and Bound algorithm is briefly described in the <a href="https://github.com/bitcoin/bitcoin/blob/master/src/wallet/coinselection.cpp#L21" rel="nofollow noreferrer">sourcecode</a> and more comprehensively in my <a href="https://murch.one/wp-content/uploads/2016/11/erhardt2016coinselection.pdf" rel="nofollow noreferrer">master's thesis</a>.</p>

<p>If no matching solution is found with the Branch and Bound algorithm, Bitcoin Core will fall back to its <a href="https://bitcoin.stackexchange.com/a/29962/5406">previous strategy</a>. This entails sorting all unspents descendingly by their value and iteratively picking a subset by randomly including or skipping list elements.</p>

CC BY-SA 4.0
2019-05-15T18:28:35.153Z
Interesting, gonna check out your thesis. Thanks!
Bart DV
CC BY-SA 4.0
2019-05-15T15:17:14.930Z
2019-05-15T15:17:14.930Z
Murch
<p>When creating a new transaction, how does the Bitcoin Core wallet (or any other wallet) handle/use the outputs (UTXO's)?</p>

<p>e.g. when 2 outputs have to be used, will Bitcoin spend the highest address (most BTC) first and then the second highest or are the UTXO's used in another way?</p>

<p>Which output will be used for the change (if there is any)?</p>

<bitcoin-core><utxo><coin-selection>
How does a Bitcoin (Core) wallet use inputs?
Bart DV
# How does a Bitcoin (Core) wallet use inputs?

(Asked by: username_0 on 2019-05-15)

When creating a new transaction, how does the Bitcoin Core wallet (or any other wallet) handle/use the outputs (UTXO's)?

e.g. when 2 outputs have to be used, will Bitcoin spend the highest address (most BTC) first and then the second highest or are the UTXO's used in another way?

Which output will be used for the change (if there is any)?

**Tags:** bitcoin-core, utxo, coin-selection


---

## 1 answers

### Answer by username_1 on 2019-05-15. Score: 3

Bitcoin Core uses a Branch and Bound algorithm to search for an input set that exactly matches the send request. To that end, it will deterministically search the combination space of all of its available utxos and pick the set that is the most efficient if there are multiple solutions. The Branch and Bound algorithm is briefly described in the [sourcecode](https://github.com/bitcoin/bitcoin/blob/master/src/wallet/coinselection.cpp#L21) and more comprehensively in my [master's thesis](https://username_1.one/wp-content/uploads/2016/11/erhardt2016coinselection.pdf).

If no matching solution is found with the Branch and Bound algorithm, Bitcoin Core will fall back to its [previous strategy](https://bitcoin.stackexchange.com/a/29962/5406). This entails sorting all unspents descendingly by their value and iteratively picking a subset by randomly including or skipping list elements.

> **Comments:**
> **username_0**: Interesting, gonna check out your thesis. Thanks!  

---

