<ol>
<li><p>The standard software uses some heuristics trying to minimize the transaction data size (which mostly means as few inputs as possible), with preference to older outputs which have higher priority. More information is available at <a href="https://bitcoin.stackexchange.com/questions/1077/what-is-the-coin-selection-algorithm">What is the coin selection algorithm?</a> and <a href="https://en.bitcoin.it/wiki/User:Gmaxwell/coin_selection" rel="nofollow noreferrer">https://en.bitcoin.it/wiki/User:Gmaxwell/coin_selection</a>.</p></li>
<li><p>If the sum of the inputs you use is larger than the amount of coins you wish to send, and you want to get the difference back rather than paying to the miner, you'll need a change output. Since the inputs almost never happen to sum up exactly, and you do want the change, almost all transactions have a change output; but there's no rule saying there must be one.</p></li>
<li><p>Every block has a special generation transaction. The miner who finds the block can freely choose the outputs for this transaction, as long as their total value is no more than the generated coins + total transaction fee.</p></li>
</ol>

CC BY-SA 3.0
2013-08-17T18:04:29.533Z
2013-08-17T18:04:29.533Z
2017-04-13T12:47:34.187Z
Meni Rosenfeld
<p>I'm a newbie at this and still trying to get my head around Bitcoin. Three linked questions around how the transaction works...</p>

<p>1) How does the wallet decide which balances/addresses form part of a new payment transaction (to go as the input)?</p>

<p>2) Do all transactions generate 'change' - i.e. a second output?</p>

<p>3) Does the fee for a transaction go to a newly generated miner's Bitcoin address, a pre-recorded miner's address, or is there no output in the blockchain associated with this?</p>

<p>Thanks and apologies for technical inaccuracies and silly questions. </p>

CC BY-SA 3.0
2013-07-15T09:45:53.257Z
related: http://bitcoin.stackexchange.com/questions/2527/how-can-i-control-which-coins-to-spend-in-a-transaction?rq=1
Thilo
CC BY-SA 3.0
2014-12-12T12:22:59.853Z
related: [What is the coin selection algorithm?](http://bitcoin.stackexchange.com/q/1077/5406)
Murch
<transactions><wallet>
How do wallets select which balances get sent as part of a transaction?
LostCause
# How do wallets select which balances get sent as part of a transaction?

(Asked by: username_0 on 2013-07-10)

I'm a newbie at this and still trying to get my head around Bitcoin. Three linked questions around how the transaction works...

1) How does the wallet decide which balances/addresses form part of a new payment transaction (to go as the input)?

2) Do all transactions generate 'change' - i.e. a second output?

3) Does the fee for a transaction go to a newly generated miner's Bitcoin address, a pre-recorded miner's address, or is there no output in the blockchain associated with this?

Thanks and apologies for technical inaccuracies and silly questions.

**Tags:** transactions, wallet

> **Comments:**
> **username_1**: related: http://bitcoin.stackexchange.com/questions/2527/how-can-i-control-which-coins-to-spend-in-a-transaction?rq=1  
> **username_2**: related: [What is the coin selection algorithm?](http://bitcoin.stackexchange.com/q/1077/5406)  

---

## 1 answers

### Answer by username_3 on 2013-08-17. Score: 1

1. The standard software uses some heuristics trying to minimize the transaction data size (which mostly means as few inputs as possible), with preference to older outputs which have higher priority. More information is available at [What is the coin selection algorithm?](https://bitcoin.stackexchange.com/questions/1077/what-is-the-coin-selection-algorithm) and <https://en.bitcoin.it/wiki/User:Gmaxwell/coin_selection>.
2. If the sum of the inputs you use is larger than the amount of coins you wish to send, and you want to get the difference back rather than paying to the miner, you'll need a change output. Since the inputs almost never happen to sum up exactly, and you do want the change, almost all transactions have a change output; but there's no rule saying there must be one.
3. Every block has a special generation transaction. The miner who finds the block can freely choose the outputs for this transaction, as long as their total value is no more than the generated coins + total transaction fee.


---

