<p>This occurs because Bitcoin Core's coin selection algorithm tries to have a minimum change of 0.01 BTC. Fees are subtracted from the change output so the result is that the change output has a lower value, but before fees, it will try to for the change output to be at least 0.01 BTC.</p>
<p>As we can see in your transaction, the change before fees is approximately 0.01 BTC. Presumably it is actually over that because you have obfuscated the last several digits. Then the transaction fee was subtracted from the change output to get the final change output value that you have.</p>
<hr />
<p>The reason that there is a minimum change is so to avoid creating very small change outputs. Small change outputs can be detrimental to the user's wallet and to the network as a whole. Those small change outputs result in the wallet having more UTXOs, which means that for future transactions, require more UTXOs to spend. Furthermore, small values can quickly become uneconomical outputs when the feerate rises. If lots of small change outputs were being created, a wallet could end up having a significant portion of its UTXOs be unspendable when fees are high.</p>
<p>Additionally, by having a minimum change target, the coin selection algorithm will tend to consolidate and sweep up smaller UTXOs. This behavior is, in general, good for the wallet and good for the network. It reduces the number of UTXOs globally, reduces the number of UTXOs that the wallet needs to handle and keep track of, and makes it less likely that UTXOs in the wallet will become uneconomical in high fee events.</p>
<hr />
<p>In general, coin selection is a hard problem which needs to balance several factors. It is not just what the fees are for the transaction right now, nor is it necessarily just about the user of the wallet in that moment. Coin selection needs to consider the cost of spending outputs in the future and how its behavior will effect the selection of UTXOs in a future transaction. Coin selection needs to balance the health of the network and the performance of the user's wallet.</p>

CC BY-SA 4.0
2021-03-24T23:49:30.883Z
@Prayank You're right, it's probably an outdated, hardcoded value that shouldn't be needed. But we also can't just get rid of it - Bitcoin Core's coin selection algorithm is the result of many tweaks over the years, and we know it works okayish in most cases. It is obviously suboptimal in some, but small and innocently looking changes can have very dramatic effects (in fact, seemingly good ideas have been reverted in the past because they resulted in very bad wallet states). We need improvements to coin selection, but they're not as simple as getting rid of things you don't understand.
Pieter Wuille
CC BY-SA 4.0
2021-03-24T23:51:03.440Z
@Andrew Chow Perhaps explain why a rule like this - albeit outdated - is useful: without it, the wallet in some usage patterns quickly grinds down its UTXO set to dust.
Pieter Wuille
CC BY-SA 4.0
2021-03-25T00:04:03.397Z
ok, i understand that the matter is not easy and there are many needs to be taken into account, but what scary me a bit is that this transaction alone, after a few days, allows to group dozens of other transactions and in a few months there will probably be hundreds ...
does this loss of privacy really make sense to avoid further fragmenting the utxos?
in my view, if there is a subset of utxos within the bitcoin-core chosen utxos group, which is sufficient to reach the amount to be sent, the utxos that are not in this subset are just an unsolicited consolidation.
leevancleef
CC BY-SA 4.0
2021-03-25T00:05:48.800Z
I've updated my answer to specify why there is a minimum change target.
Ava Chow
CC BY-SA 4.0
2021-03-25T00:10:25.273Z
Related to this question is [PR 4096](https://github.com/bitcoin/bitcoin/pull/4906) which does exactly as you suggest: "It will prune any extraneous inputs in the selected subset, in order to decrease the number of inputs and the resulting change." On the surface, this seems like a good idea, and many contributors agreed. However, in practice, it was found to create many small change UTXOs (as I explain in my answer) which was detrimental to wallets and caused a significant increase in the UTXO set size. This PR was later reverted in [PR 8298](https://github.com/bitcoin/bitcoin/pull/8298).
Ava Chow
CC BY-SA 4.0
2021-03-25T00:20:40.347Z
@AndrewChow we agree that prevent fragmentation is good and that to reduce utxos we need to consolidate, but why consolidate randomly (as happen in this way) is better than consolidate only when necessary? this behavior prevents me from consolidating the utxos by hand when I think it is more appropriate.
leevancleef
CC BY-SA 4.0
2021-03-25T00:25:27.310Z
@leevancleef I never said that this approach that Bitcoin Core does is good or better. This is merely an explanation of what and why this behavior occurs. I agree that consolidating randomly is not good, and currently, Bitcoin Core's coin selection needs work. There is ongoing work (from myself) to improve the coin selection algorithm, but it has not garnered much review. However consolidation should not be left up to the user to do as many users are not aware of consolidation or knowledgable about UTXO management in general.
Ava Chow
CC BY-SA 4.0
2021-03-25T00:26:47.017Z
A strategy that is in the works to improve this is to use a more consolidatory algorithm when fees are low, and use a less consolidatory one when fees are high. The current coin selection algorithm is always consolidatory and does not take into account the current feerates and this is something that I am trying to change.
Ava Chow
CC BY-SA 4.0
2021-03-25T00:38:17.733Z
happy to know these things, for my need I will try to find a selection algorithm that takes privacy as a first requirement ... i wonder if there are other business that need to send automatic payment respecting privacy, but probably the most need the opposite :D
leevancleef
CC BY-SA 4.0
2021-03-25T00:39:29.853Z
If your primary goal is non-linkage between addresses, the only real solution is having completely separate wallets (or *very* rigorous use of manual coin control).
Pieter Wuille
CC BY-SA 4.0
2021-03-24T23:25:16.700Z
2021-03-25T00:21:46.640Z
2021-03-25T00:21:46.640Z
Ava Chow
<p>for business reason i need to use the bitcoin-core (v0.20.1) automatic coin selection feature and few days ago i saw a transaction come out that left me puzzled, it was like that:</p>
<pre><code>input

  0.00017[...]  bc1qaddr1
  0.01292[...]  bc1qaddr2
  0.00030[...]  bc1qaddr3
  0.00020[...]  bc1qaddr4
  0.00015[...]  bc1qaddr5
  0.00035[...]  bc1qaddr6
  0.02371[...]  bc1qaddr7

output

  0.02783[...]  bc1qaddr8  &gt; amount sent
  0.00965[...]  bc1qaddr9  &gt; change
</code></pre>
<p>in this transaction 5 out of 7 utxos are unnecessary, is there some benefit in chaining toghether utxos in this way?<br/>from my point of view this is a terrible way of loosing privacy and pay way more fee than needed, what i miss?<br/>i read that bitcoin-core tries to find an exact match from available utxos and the amount to send, but if it fails then try to find a subset of utxos to reach a change of 0.01btc, is that right?<br/>so, in my case, the unneeded utxos are added to get the change of my trasaction closer to 0.01?</p>

CC BY-SA 4.0
2021-03-24T23:02:19.790Z
bc1qaddr2 and bc1qaddr7 summed are already more than 0.03663
leevancleef
CC BY-SA 4.0
2021-03-24T23:09:29.710Z
the issue here is not that there are better (smaller) subset to choose, but that most utxos in this subset are completely useless to reach the amount needed
leevancleef
CC BY-SA 4.0
2021-03-24T23:20:17.390Z
I say that they are useless because, if i understand well, they are not needed to reach the amount i have chosen to send, but they are needed to reach the amount chosen by bitcoin-core (my amount + 0.01 btc)
leevancleef
<bitcoin-core><transaction-fees><privacy><coin-selection>
bitcoin-core automatic coin selection
leevancleef
# bitcoin-core automatic coin selection

(Asked by: username_0 on 2021-03-24)

for business reason i need to use the bitcoin-core (v0.20.1) automatic coin selection feature and few days ago i saw a transaction come out that left me puzzled, it was like that:

```
input

  0.00017[...]  bc1qaddr1
  0.01292[...]  bc1qaddr2
  0.00030[...]  bc1qaddr3
  0.00020[...]  bc1qaddr4
  0.00015[...]  bc1qaddr5
  0.00035[...]  bc1qaddr6
  0.02371[...]  bc1qaddr7

output

  0.02783[...]  bc1qaddr8  > amount sent
  0.00965[...]  bc1qaddr9  > change

```

in this transaction 5 out of 7 utxos are unnecessary, is there some benefit in chaining toghether utxos in this way?  
from my point of view this is a terrible way of loosing privacy and pay way more fee than needed, what i miss?  
i read that bitcoin-core tries to find an exact match from available utxos and the amount to send, but if it fails then try to find a subset of utxos to reach a change of 0.01btc, is that right?  
so, in my case, the unneeded utxos are added to get the change of my trasaction closer to 0.01?

**Tags:** bitcoin-core, transaction-fees, privacy, coin-selection

> **Comments:**
> **username_0**: bc1qaddr2 and bc1qaddr7 summed are already more than 0.03663  
> **username_0**: the issue here is not that there are better (smaller) subset to choose, but that most utxos in this subset are completely useless to reach the amount needed  
> **username_0**: I say that they are useless because, if i understand well, they are not needed to reach the amount i have chosen to send, but they are needed to reach the amount chosen by bitcoin-core (my amount + 0.01 btc)  

---

## 1 answers

### Answer by username_1 on 2021-03-24. Score: 3 | Accepted answer

This occurs because Bitcoin Core's coin selection algorithm tries to have a minimum change of 0.01 BTC. Fees are subtracted from the change output so the result is that the change output has a lower value, but before fees, it will try to for the change output to be at least 0.01 BTC.

As we can see in your transaction, the change before fees is approximately 0.01 BTC. Presumably it is actually over that because you have obfuscated the last several digits. Then the transaction fee was subtracted from the change output to get the final change output value that you have.

---

The reason that there is a minimum change is so to avoid creating very small change outputs. Small change outputs can be detrimental to the user's wallet and to the network as a whole. Those small change outputs result in the wallet having more UTXOs, which means that for future transactions, require more UTXOs to spend. Furthermore, small values can quickly become uneconomical outputs when the feerate rises. If lots of small change outputs were being created, a wallet could end up having a significant portion of its UTXOs be unspendable when fees are high.

Additionally, by having a minimum change target, the coin selection algorithm will tend to consolidate and sweep up smaller UTXOs. This behavior is, in general, good for the wallet and good for the network. It reduces the number of UTXOs globally, reduces the number of UTXOs that the wallet needs to handle and keep track of, and makes it less likely that UTXOs in the wallet will become uneconomical in high fee events.

---

In general, coin selection is a hard problem which needs to balance several factors. It is not just what the fees are for the transaction right now, nor is it necessarily just about the user of the wallet in that moment. Coin selection needs to consider the cost of spending outputs in the future and how its behavior will effect the selection of UTXOs in a future transaction. Coin selection needs to balance the health of the network and the performance of the user's wallet.

> **Comments:**
> **username_2**: @Prayank You're right, it's probably an outdated, hardcoded value that shouldn't be needed. But we also can't just get rid of it - Bitcoin Core's coin selection algorithm is the result of many tweaks over the years, and we know it works okayish in most cases. It is obviously suboptimal in some, but small and innocently looking changes can have very dramatic effects (in fact, seemingly good ideas have been reverted in the past because they resulted in very bad wallet states). We need improvements to coin selection, but they're not as simple as getting rid of things you don't understand.  
> **username_2**: @Andrew username_1 Perhaps explain why a rule like this - albeit outdated - is useful: without it, the wallet in some usage patterns quickly grinds down its UTXO set to dust.  
> **username_0**: ok, i understand that the matter is not easy and there are many needs to be taken into account, but what scary me a bit is that this transaction alone, after a few days, allows to group dozens of other transactions and in a few months there will probably be hundreds ... does this loss of privacy really make sense to avoid further fragmenting the utxos? in my view, if there is a subset of utxos within the bitcoin-core chosen utxos group, which is sufficient to reach the amount to be sent, the utxos that are not in this subset are just an unsolicited consolidation.  
> **username_1**: I've updated my answer to specify why there is a minimum change target.  
> **username_1**: Related to this question is [PR 4096](https://github.com/bitcoin/bitcoin/pull/4906) which does exactly as you suggest: "It will prune any extraneous inputs in the selected subset, in order to decrease the number of inputs and the resulting change." On the surface, this seems like a good idea, and many contributors agreed. However, in practice, it was found to create many small change UTXOs (as I explain in my answer) which was detrimental to wallets and caused a significant increase in the UTXO set size. This PR was later reverted in [PR 8298](https://github.com/bitcoin/bitcoin/pull/8298).  
> **username_0**: @AndrewChow we agree that prevent fragmentation is good and that to reduce utxos we need to consolidate, but why consolidate randomly (as happen in this way) is better than consolidate only when necessary? this behavior prevents me from consolidating the utxos by hand when I think it is more appropriate.  
> **username_1**: @username_0 I never said that this approach that Bitcoin Core does is good or better. This is merely an explanation of what and why this behavior occurs. I agree that consolidating randomly is not good, and currently, Bitcoin Core's coin selection needs work. There is ongoing work (from myself) to improve the coin selection algorithm, but it has not garnered much review. However consolidation should not be left up to the user to do as many users are not aware of consolidation or knowledgable about UTXO management in general.  
> **username_1**: A strategy that is in the works to improve this is to use a more consolidatory algorithm when fees are low, and use a less consolidatory one when fees are high. The current coin selection algorithm is always consolidatory and does not take into account the current feerates and this is something that I am trying to change.  
> **username_0**: happy to know these things, for my need I will try to find a selection algorithm that takes privacy as a first requirement ... i wonder if there are other business that need to send automatic payment respecting privacy, but probably the most need the opposite :D  
> **username_2**: If your primary goal is non-linkage between addresses, the only real solution is having completely separate wallets (or *very* rigorous use of manual coin control).  

---

