<p>What might be confusing you, and which is a common misconception, is that the addresses themselves somehow "hold" the bitcoin balances, and gain and lose the coins via transactions. In fact all the blockchain does is link up previous outputs to new inputs, and the keys make sure only the correct person is allowed to send the coins. </p>

<p>Your balance is just the sum of the total unspent outputs and if you want to send a certain amount to someone, you end up creating a transaction which uses, as input, enough unspent outputs to give the right amount of coins. So if you have a few different smaller unspent outputs, and want to send a large amount, the transaction will end up using multiple of the smaller outputs as input. Because inputs and outputs are used as wholes - they can't be split up as such -
 you then usually receive a bit of change based on how much the total inputs sum up to, and how much you intended to send.</p>

<p>Of course, most of this is worked out by your wallet client or website which you use, so as an average user you wouldn't normally know in advance how many "addresses" are going to be involved with a specific transaction. The program will just select enough unspent outputs which you hold the keys to, and use them to create the transaction. Hopefully that answers your question to some degree.</p>

CC BY-SA 3.0
2017-06-30T07:32:02.017Z
2017-07-05T01:59:12.167Z
2017-07-05T01:59:12.167Z
meshcollider
<p>Value in Bitcoin is not stored in &quot;balances&quot; but rather in <em>unspent transaction outputs (UTXOs)</em>. UTXOs behave like checks, you get one each time you receive money, each is exactly for the amount that was signed over, and you can only spend from it once, in full.</p>
<p>When you create a transaction, your software will search for a set of UTXOs that can fund your transaction. This can be any number of inputs from one to all of your wallet's UTXOs.</p>

CC BY-SA 4.0
2017-07-06T17:33:39.720Z
2023-10-26T19:01:49.017Z
2023-10-26T19:01:49.017Z
Murch
<p>Starting from a little far away, the coins are transferred to the Bitcoin Addresses, which are really hashes of public keys. They can be spent using their respective private keys (which is used to generate the public key and the public key hash) which is stored in the Wallet.</p>

<p>Your balance is the sum of <em>unspent transaction outputs</em> (UTXOs) on your Addresses. You can check them manually: in the Bitcoin Core client go to Help > Debug > Console, to check Addresses type <code>listaccounts</code>, to check UTXOs type <code>listunspent</code> or <code>listaddressgroupings</code>.</p>

<p>When you want to send coins to an Address your Bitcoin software goes trough all your <em>unspent transaction outputs</em> and tries to find the best combination to fill that amount (including transaction fee) using as few as possible. In the simplest case one UTXO has enough coin so only that will be used, in other cases more will be combined.</p>

<p>This is the "in" part of the transaction.</p>

<p>After this the Bitcoin software will add the "out" part where the destination Address (or Addresses) you supplied will be present with the amount(s). As a UTXO can only be used up once, all of it must be transferred. From the rest the <em>transaction fee</em> will be paid and the rest is the <em>change</em>, that will be sent back to a newly generated Address of yours (and this will increase the "fragmentation" of your Wallet). The <em>change</em> appears as well in the "out" part (so it will increase the size of the transaction and therefore the fee), while the <em>transaction fee</em> will be left in the transaction with no output.</p>

<p>After this the Bitcoin software will calculate the <em>transaction fee</em> required based on the setting you use (fee amount/byte), update the appropriate amounts (<em>transaciton fee</em> and <em>change</em>) and the transaction is ready to be sent.</p>

CC BY-SA 3.0
2017-06-30T13:29:56.707Z
Why I got the downvote(s), what should I imporve? Thanks.
Gábor Héja
CC BY-SA 3.0
2017-07-02T03:17:01.860Z
Addresses do not have "balances", they have *unspent transaction outputs* associated with them. There can be multiple UTXO associated with the same address at the same time or at different times. Thus, your answer should read UTXO at various points where you use address, and it doesn't describe the input selection correctly.
Murch
CC BY-SA 3.0
2017-07-03T12:08:46.307Z
@Murch, thanks for the correction, I did some more research and updated the answer (I hope I understood it well this time).
Gábor Héja
CC BY-SA 3.0
2017-06-29T22:26:38.580Z
2017-07-03T12:39:35.980Z
2017-07-03T12:39:35.980Z
Gábor Héja
<p>Someone has 7 private keys in their wallet, but none of the private keys have enough unspent outputs for a payment of ~ 2.16 BTC, so the wallet software combines the private keys (and the unspent outputs) to make a 2.16 BTC transaction.</p>

CC BY-SA 3.0
2017-06-29T20:20:45.843Z
Downvoted. Private keys don't have bitcoins, unspent outputs do. This answer continues the confusion that leads to OP's question.
Pieter Wuille
CC BY-SA 3.0
2017-06-29T18:11:40.740Z
2017-06-30T07:16:27.470Z
2017-06-30T07:16:27.470Z
MCCCS
<p>I know a normal transaction has 1 input and 2 outputs (if there is change that is the second output).</p>

<p>But what about this scenario?
<a href="https://i.sstatic.net/k1KzR.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/k1KzR.png" alt="enter image description here"></a></p>

<p>Lets say I'm withdrawing bitcoin from my gemini account and want to calculate the fees. How would I even know if it's 7 addresses sending (which would make the byte size of the transaction larger = higher miner fees) or just 1 address sending?</p>

<p>To further elaborate on test-net here is our system with withdrawing btc to another wallet:
<a href="https://test-insight.bitpay.com/tx/8bc3db6a4a119e369752a52f0be39ae3a4d579adcdc49e9d92429b920000f934" rel="nofollow noreferrer">https://test-insight.bitpay.com/tx/8bc3db6a4a119e369752a52f0be39ae3a4d579adcdc49e9d92429b920000f934</a>
<a href="https://test-insight.bitpay.com/tx/553a27e38a73ed90c792b70add3c3f894e94955440205917ee754787c17ea62b" rel="nofollow noreferrer">https://test-insight.bitpay.com/tx/553a27e38a73ed90c792b70add3c3f894e94955440205917ee754787c17ea62b</a>
<a href="https://test-insight.bitpay.com/tx/cecf112c7e3494826b165f4bcbeca9ef20cc800dce3d433c04b070e4fbc1da81" rel="nofollow noreferrer">https://test-insight.bitpay.com/tx/cecf112c7e3494826b165f4bcbeca9ef20cc800dce3d433c04b070e4fbc1da81</a></p>

<p>Here is when I deposited back into our wallet (from copay wallet that supports test net):
<a href="https://test-insight.bitpay.com/tx/5871e5957ef6ec67a336de01e6f3e4f6f4cffd9986d2f5db181fdcbf6b00d1e0" rel="nofollow noreferrer">https://test-insight.bitpay.com/tx/5871e5957ef6ec67a336de01e6f3e4f6f4cffd9986d2f5db181fdcbf6b00d1e0</a></p>

CC BY-SA 3.0
2017-06-29T17:38:35.503Z
What software? Typically your wallet is responsible for constructing transactions, and you don't do this manually.
Pieter Wuille
CC BY-SA 3.0
2017-06-29T17:47:13.343Z
What about it?  What is your question?  It's perfectly possible, a transaction is allowed to have an arbitrary number of inputs and outputs.
Nate Eldredge
CC BY-SA 3.0
2017-06-29T17:49:43.800Z
A case scenario of how this would happen. How would one transaction do this? Is it kind of like 7 people sending money to two people (but one if the other is change). Or..? Are all those 7 outputs from one node / wallet that has different addresses?
Marc Alexander
CC BY-SA 3.0
2017-06-29T17:50:55.070Z
Bitcoin transactions don't send from/to addresses. They spend coins integrally and produce new ones. Is there are reference question/answer to explain this?
Pieter Wuille
CC BY-SA 3.0
2017-06-29T17:52:43.800Z
Lets say I'm withdrawing bitcoin from my gemini account and want to calculate the fees. How would I even know if its 7 addresses sending (which would make the byte size of the transaction larger = higher miner fees) or just 1 address sending?
Marc Alexander
CC BY-SA 3.0
2017-07-03T14:57:39.007Z
@MarcAlexander, that would be up to the software that is constructing the transaction.  Gemini may allow you to customize and lower the fee...or it may not.  If Gemini is constructing the transaction, then you will have to ask Gemini how they do it.
Jestin
CC BY-SA 3.0
2017-07-06T17:34:56.593Z
@MarcAlexander: I've edited your title and retagged your question to better represent what you're actually asking about. Please feel free to revert or further edit your question if you feel that I didn't quite get it right.
Murch
<utxo><coin-selection>
Why do some transactions have more than one input?
Marc Alexander
# Why do some transactions have more than one input?

(Asked by: username_0 on 2017-06-29)

I know a normal transaction has 1 input and 2 outputs (if there is change that is the second output).

But what about this scenario?
[![enter image description here](https://i.sstatic.net/k1KzR.png)](https://i.sstatic.net/k1KzR.png)

Lets say I'm withdrawing bitcoin from my gemini account and want to calculate the fees. How would I even know if it's 7 addresses sending (which would make the byte size of the transaction larger = higher miner fees) or just 1 address sending?

To further elaborate on test-net here is our system with withdrawing btc to another wallet:
<https://test-insight.bitpay.com/tx/8bc3db6a4a119e369752a52f0be39ae3a4d579adcdc49e9d92429b920000f934>
<https://test-insight.bitpay.com/tx/553a27e38a73ed90c792b70add3c3f894e94955440205917ee754787c17ea62b>
<https://test-insight.bitpay.com/tx/cecf112c7e3494826b165f4bcbeca9ef20cc800dce3d433c04b070e4fbc1da81>

Here is when I deposited back into our wallet (from copay wallet that supports test net):
<https://test-insight.bitpay.com/tx/5871e5957ef6ec67a336de01e6f3e4f6f4cffd9986d2f5db181fdcbf6b00d1e0>

**Tags:** utxo, coin-selection

> **Comments:**
> **username_1**: What software? Typically your wallet is responsible for constructing transactions, and you don't do this manually.  
> **username_2**: What about it?  What is your question?  It's perfectly possible, a transaction is allowed to have an arbitrary number of inputs and outputs.  
> **username_0**: A case scenario of how this would happen. How would one transaction do this? Is it kind of like 7 people sending money to two people (but one if the other is change). Or..? Are all those 7 outputs from one node / wallet that has different addresses?  
> **username_1**: Bitcoin transactions don't send from/to addresses. They spend coins integrally and produce new ones. Is there are reference question/answer to explain this?  
> **username_0**: Lets say I'm withdrawing bitcoin from my gemini account and want to calculate the fees. How would I even know if its 7 addresses sending (which would make the byte size of the transaction larger = higher miner fees) or just 1 address sending?  
> **username_3**: @username_0, that would be up to the software that is constructing the transaction.  Gemini may allow you to customize and lower the fee...or it may not.  If Gemini is constructing the transaction, then you will have to ask Gemini how they do it.  
> **username_4**: @username_0: I've edited your title and retagged your question to better represent what you're actually asking about. Please feel free to revert or further edit your question if you feel that I didn't quite get it right.  

---

## 4 answers

### Answer by username_5 on 2017-06-30. Score: 6

What might be confusing you, and which is a common misconception, is that the addresses themselves somehow "hold" the bitcoin balances, and gain and lose the coins via transactions. In fact all the blockchain does is link up previous outputs to new inputs, and the keys make sure only the correct person is allowed to send the coins.

Your balance is just the sum of the total unspent outputs and if you want to send a certain amount to someone, you end up creating a transaction which uses, as input, enough unspent outputs to give the right amount of coins. So if you have a few different smaller unspent outputs, and want to send a large amount, the transaction will end up using multiple of the smaller outputs as input. Because inputs and outputs are used as wholes - they can't be split up as such -
you then usually receive a bit of change based on how much the total inputs sum up to, and how much you intended to send.

Of course, most of this is worked out by your wallet client or website which you use, so as an average user you wouldn't normally know in advance how many "addresses" are going to be involved with a specific transaction. The program will just select enough unspent outputs which you hold the keys to, and use them to create the transaction. Hopefully that answers your question to some degree.


---

### Answer by username_4 on 2017-07-06. Score: 1

Value in Bitcoin is not stored in "balances" but rather in *unspent transaction outputs (UTXOs)*. UTXOs behave like checks, you get one each time you receive money, each is exactly for the amount that was signed over, and you can only spend from it once, in full.

When you create a transaction, your software will search for a set of UTXOs that can fund your transaction. This can be any number of inputs from one to all of your wallet's UTXOs.


---

### Answer by username_6 on 2017-06-29. Score: 0

Starting from a little far away, the coins are transferred to the Bitcoin Addresses, which are really hashes of public keys. They can be spent using their respective private keys (which is used to generate the public key and the public key hash) which is stored in the Wallet.

Your balance is the sum of *unspent transaction outputs* (UTXOs) on your Addresses. You can check them manually: in the Bitcoin Core client go to Help > Debug > Console, to check Addresses type `listaccounts`, to check UTXOs type `listunspent` or `listaddressgroupings`.

When you want to send coins to an Address your Bitcoin software goes trough all your *unspent transaction outputs* and tries to find the best combination to fill that amount (including transaction fee) using as few as possible. In the simplest case one UTXO has enough coin so only that will be used, in other cases more will be combined.

This is the "in" part of the transaction.

After this the Bitcoin software will add the "out" part where the destination Address (or Addresses) you supplied will be present with the amount(s). As a UTXO can only be used up once, all of it must be transferred. From the rest the *transaction fee* will be paid and the rest is the *change*, that will be sent back to a newly generated Address of yours (and this will increase the "fragmentation" of your Wallet). The *change* appears as well in the "out" part (so it will increase the size of the transaction and therefore the fee), while the *transaction fee* will be left in the transaction with no output.

After this the Bitcoin software will calculate the *transaction fee* required based on the setting you use (fee amount/byte), update the appropriate amounts (*transaciton fee* and *change*) and the transaction is ready to be sent.

> **Comments:**
> **username_6**: Why I got the downvote(s), what should I imporve? Thanks.  
> **username_4**: Addresses do not have "balances", they have *unspent transaction outputs* associated with them. There can be multiple UTXO associated with the same address at the same time or at different times. Thus, your answer should read UTXO at various points where you use address, and it doesn't describe the input selection correctly.  
> **username_6**: @username_4, thanks for the correction, I did some more research and updated the answer (I hope I understood it well this time).  

---

### Answer by username_7 on 2017-06-29. Score: 0

Someone has 7 private keys in their wallet, but none of the private keys have enough unspent outputs for a payment of ~ 2.16 BTC, so the wallet software combines the private keys (and the unspent outputs) to make a 2.16 BTC transaction.

> **Comments:**
> **username_1**: Downvoted. Private keys don't have bitcoins, unspent outputs do. This answer continues the confusion that leads to OP's question.  

---

