<p>The change is anything that's left over when you take the outputs you'll be spending, subtract the value of the transaction sent, and subtract fees. Since transactions should be as small as possible, as few outputs as needed will be spent. In your case, 3 outputs will be spent, no fee is in place, so the following new outputs will be created:</p>

<ul>
<li>5 BTC to recipient</li>
<li>1 BTC to a change address.</li>
</ul>

CC BY-SA 3.0
2014-08-09T23:02:51.953Z
2014-08-09T23:02:51.953Z
nanofarad
<p>If none of your transaction outputs is large enough to be the sole input, <a href="https://github.com/bitcoin/bitcoin/blob/master/src/wallet.cpp#L1129" rel="nofollow">Bitcoin Core's coin selection algorithm</a> does multiple rounds of randomly adding unspent transaction outputs until their total is greater than or equal to the amount you are trying to transfer. Finally, it selects the combination with the least resulting change.</p>

<p>In your example, it would use a combination of three of your four outputs, as 6BTC is more than the required 5BTC.<br>
Therefore, you would end up with one of the four original 2BTC transaction outputs, and the change of your transaction as a new transaction output with 1BTC.</p>

CC BY-SA 3.0
2014-08-10T01:25:19.913Z
Also see [What is the coin selection algorithm?](http://bitcoin.stackexchange.com/a/29962/5406)
Murch
CC BY-SA 3.0
2014-08-10T00:02:55.573Z
2014-08-10T08:25:23.023Z
2014-08-10T08:25:23.023Z
Murch
<p>I'm confused about how exactly I should compute a change for transactions.<br>
Say, for a given address I have 4 unspent outputs containing 2 BTC each and I want to send 5 BTC to other address.</p>

<p>Here's what I do:</p>

<ol>
<li>Find 3 outputs needed so the total is 6 BTC</li>
<li>Now, what should the change be? 6-5=1 or 8-5=3?</li>
</ol>

<development><change>
Transaction change calculation
src091
# Transaction change calculation

(Asked by: username_0 on 2014-08-09)

I'm confused about how exactly I should compute a change for transactions.  
Say, for a given address I have 4 unspent outputs containing 2 BTC each and I want to send 5 BTC to other address.

Here's what I do:

1. Find 3 outputs needed so the total is 6 BTC
2. Now, what should the change be? 6-5=1 or 8-5=3?

**Tags:** development, change


---

## 2 answers

### Answer by username_1 on 2014-08-09. Score: 2 | Accepted answer

The change is anything that's left over when you take the outputs you'll be spending, subtract the value of the transaction sent, and subtract fees. Since transactions should be as small as possible, as few outputs as needed will be spent. In your case, 3 outputs will be spent, no fee is in place, so the following new outputs will be created:

* 5 BTC to recipient
* 1 BTC to a change address.


---

### Answer by username_2 on 2014-08-10. Score: 1

If none of your transaction outputs is large enough to be the sole input, [Bitcoin Core's coin selection algorithm](https://github.com/bitcoin/bitcoin/blob/master/src/wallet.cpp#L1129) does multiple rounds of randomly adding unspent transaction outputs until their total is greater than or equal to the amount you are trying to transfer. Finally, it selects the combination with the least resulting change.

In your example, it would use a combination of three of your four outputs, as 6BTC is more than the required 5BTC.  
Therefore, you would end up with one of the four original 2BTC transaction outputs, and the change of your transaction as a new transaction output with 1BTC.

> **Comments:**
> **username_2**: Also see [What is the coin selection algorithm?](http://bitcoin.stackexchange.com/a/29962/5406)  

---

