<blockquote>
<ol>
<li>a transaction (Tx) can have multiple inputs (which are previous unspent transactions = UTXOs), let's call them the <strong>TxIn</strong></li>
</ol>
</blockquote>
<p>More accurate would be to say &quot;unspent outputs from previous transactions&quot;.</p>
<blockquote>
<ol start="2">
<li>a Tx can have multiple outputs (which thus become UTXOs before they will themselves become spent by being used as TxIn), let's call them
the <strong>TxOut</strong></li>
<li>the TxOut have a specific order <strong>N</strong> in the transaction: TxOut[0], TxOut[1], etc.</li>
<li>each TxIn references the number N which corresponds to the index of the TxOut referred to in point 3 above, so this makes the link between
a specific TxIn and a specific TxOut</li>
</ol>
</blockquote>
<p>Correct, we call the compound of transaction id and output index <code>txid:vout</code> the &quot;outpoint&quot; of a UTXO. As you describe, each input spends exactly one specific UTXO.</p>
<blockquote>
<ol start="5">
<li>each TxOut specifies a specific bitcoin amount (which represents the UTXO amount that can be later spent)</li>
<li>each TxOut references one or multiple (in the case of MultiSig) bitcoin addresses (public keys) that can spend the amount</li>
</ol>
</blockquote>
<p>It's a bit easier if you think of each output as being locked to a set of conditions that need to be fulfilled for spending. In single-sig the spending condition is &quot;pay-to-(witness-)public-key-hash&quot;. This lock is satisfied by a signature of the private key corresponding to the specified address. (The address in turn is derived from the hash of a public key which forms an asymmetric key pair with said private key.) In multisig the spending condition is &quot;pay-to-(witness-)script-hash&quot;. The funds are locked to the fullfilment of a specific script. The address in this case is derived from the hash of the script. Spending such a UTXO requires 1) revealing the script that hashed to the address, 2) fulfilling the conditions specified in the script. In the case where that script is a multisig construction, it would specify a set of public keys some subset of which is sufficient to unlock the funds. However, these scripts can take various other forms as well. I'd nit that &quot;each TxOut references one or multiple bitcoin addresses that can spend the amount&quot; is both an overgeneralization (because not all scripts must be multisig) and an inaccuracy (because the funds are locked to the script, not to multiple addresses).</p>
<blockquote>
<ol start="7">
<li>however, and this is what I don't understand, the TxIn does NOT specify the amount of bitcoins that are used</li>
</ol>
<p>If the TxIn does not specify the amount that is used, how do we
determine the spent amount for each TxIn, and thus the UTXO of the
part of the TxIn that remains unspent?</p>
</blockquote>
<p><a href="https://bitcoin.stackexchange.com/q/20611/5406">There is no way to partially spend a UTXO</a>. Spending UTXO is binary, either they are unspent or they are spent. Since UTXO can only be spent in full, any remainder from a payment gets collected into one or multiple outputs in which the sender pays themselves (see e.g. <a href="https://bitcoin.stackexchange.com/q/736/5406">How does change work in a bitcoin transaction?</a>).</p>
<blockquote>
<p>Example, a transaction with 2 inputs and one output (assuming no
fees):</p>
<ul>
<li>TxIn[0] whose UTXO before spending is 1 BTC</li>
<li>TxIn[1] whose UTXO before spending is 1 BTC</li>
<li>TxOut[0] whose value is 1.5 BTC</li>
</ul>
<p>How do we know which TxIn, and how much of which, was spent?</p>
<ul>
<li>was it TxIn[0] for 0.75 and TxIn[1] for 0.75?</li>
<li>was it TxIn[0] for 0.5 and TxIn[1] for 1?</li>
</ul>
<p>What am I missing? Because given the above, it is not possible to
determine the spent proportion of each input.</p>
</blockquote>
<p>The answer is that both <code>TxIn[0]</code> and <code>TxIn[1]</code> get spent completely and the transaction is created with two outputs: <code>TxOut[0]: 1.5 BTC to recipient</code> and <code>TxOut[1]: 0.5 BTC to sender</code>.</p>

CC BY-SA 4.0
2020-09-17T18:23:54.820Z
Ah thank you for your detailed explanations. One of the pieces I was missing was that a UTXO cannot be partially spent, and that the remainder gets 'sent back to oneself' in a `vout`. Makes much more sense now.
Jean Monet
CC BY-SA 4.0
2020-09-17T18:10:43.337Z
2020-09-17T18:54:07.980Z
2020-09-17T18:54:07.980Z
Murch
<p>My current understanding of a transaction is as follows:</p>
<ol>
<li>a transaction (Tx) can have multiple inputs (which are previous unspent transactions = UTXOs), let's call them the <strong>TxIn</strong></li>
<li>a Tx can have multiple outputs (which thus become UTXOs before they will themselves become spent by being used as TxIn), let's call them the <strong>TxOut</strong></li>
<li>the TxOut have a specific order <strong>N</strong> in the transaction: TxOut[0], TxOut[1], etc.</li>
<li>each TxIn references the number N which corresponds to the index of the TxOut referred to in point 3 above, so this makes the link between a specific TxIn and a specific TxOut</li>
<li>each TxOut specifies a specific bitcoin amount (which represents the UTXO amount that can be later spent)</li>
<li>each TxOut references one or multiple (in the case of MultiSig) bitcoin addresses (public keys) that can spend the amount</li>
<li>however, and this is what I don't understand, the TxIn does NOT specify the amount of bitcoins that are used</li>
</ol>
<p>If the TxIn does not specify the amount that is used, how do we determine the spent amount for each TxIn, and thus the UTXO of the part of the TxIn that remains unspent?</p>
<p>Example, a transaction with 2 inputs and one output (assuming no fees):</p>
<ul>
<li>TxIn[0] whose UTXO before spending is 1 BTC</li>
<li>TxIn[1] whose UTXO before spending is 1 BTC</li>
<li>TxOut[0] whose value is 1.5 BTC</li>
</ul>
<p>How do we know which TxIn, and how much of which, was spent?</p>
<ul>
<li>was it TxIn[0] for 0.75 and TxIn[1] for 0.75?</li>
<li>was it TxIn[0] for 0.5 and TxIn[1] for 1?</li>
</ul>
<p>What am I missing? Because given the above, it is not possible to determine the spent proportion of each input.</p>

<utxo><change><transaction-input>
How is the UTXOs of each partially-spent TxIn determined?
Jean Monet
# How is the UTXOs of each partially-spent TxIn determined?

(Asked by: username_0 on 2020-09-17)

My current understanding of a transaction is as follows:

1. a transaction (Tx) can have multiple inputs (which are previous unspent transactions = UTXOs), let's call them the **TxIn**
2. a Tx can have multiple outputs (which thus become UTXOs before they will themselves become spent by being used as TxIn), let's call them the **TxOut**
3. the TxOut have a specific order **N** in the transaction: TxOut[0], TxOut[1], etc.
4. each TxIn references the number N which corresponds to the index of the TxOut referred to in point 3 above, so this makes the link between a specific TxIn and a specific TxOut
5. each TxOut specifies a specific bitcoin amount (which represents the UTXO amount that can be later spent)
6. each TxOut references one or multiple (in the case of MultiSig) bitcoin addresses (public keys) that can spend the amount
7. however, and this is what I don't understand, the TxIn does NOT specify the amount of bitcoins that are used

If the TxIn does not specify the amount that is used, how do we determine the spent amount for each TxIn, and thus the UTXO of the part of the TxIn that remains unspent?

Example, a transaction with 2 inputs and one output (assuming no fees):

* TxIn[0] whose UTXO before spending is 1 BTC
* TxIn[1] whose UTXO before spending is 1 BTC
* TxOut[0] whose value is 1.5 BTC

How do we know which TxIn, and how much of which, was spent?

* was it TxIn[0] for 0.75 and TxIn[1] for 0.75?
* was it TxIn[0] for 0.5 and TxIn[1] for 1?

What am I missing? Because given the above, it is not possible to determine the spent proportion of each input.

**Tags:** utxo, change, transaction-input


---

## 1 answers

### Answer by username_1 on 2020-09-17. Score: 3 | Accepted answer

> 1. a transaction (Tx) can have multiple inputs (which are previous unspent transactions = UTXOs), let's call them the **TxIn**

More accurate would be to say "unspent outputs from previous transactions".

> 2. a Tx can have multiple outputs (which thus become UTXOs before they will themselves become spent by being used as TxIn), let's call them
>    the **TxOut**
> 3. the TxOut have a specific order **N** in the transaction: TxOut[0], TxOut[1], etc.
> 4. each TxIn references the number N which corresponds to the index of the TxOut referred to in point 3 above, so this makes the link between
>    a specific TxIn and a specific TxOut

Correct, we call the compound of transaction id and output index `txid:vout` the "outpoint" of a UTXO. As you describe, each input spends exactly one specific UTXO.

> 5. each TxOut specifies a specific bitcoin amount (which represents the UTXO amount that can be later spent)
> 6. each TxOut references one or multiple (in the case of MultiSig) bitcoin addresses (public keys) that can spend the amount

It's a bit easier if you think of each output as being locked to a set of conditions that need to be fulfilled for spending. In single-sig the spending condition is "pay-to-(witness-)public-key-hash". This lock is satisfied by a signature of the private key corresponding to the specified address. (The address in turn is derived from the hash of a public key which forms an asymmetric key pair with said private key.) In multisig the spending condition is "pay-to-(witness-)script-hash". The funds are locked to the fullfilment of a specific script. The address in this case is derived from the hash of the script. Spending such a UTXO requires 1) revealing the script that hashed to the address, 2) fulfilling the conditions specified in the script. In the case where that script is a multisig construction, it would specify a set of public keys some subset of which is sufficient to unlock the funds. However, these scripts can take various other forms as well. I'd nit that "each TxOut references one or multiple bitcoin addresses that can spend the amount" is both an overgeneralization (because not all scripts must be multisig) and an inaccuracy (because the funds are locked to the script, not to multiple addresses).

> 7. however, and this is what I don't understand, the TxIn does NOT specify the amount of bitcoins that are used
>
> If the TxIn does not specify the amount that is used, how do we
> determine the spent amount for each TxIn, and thus the UTXO of the
> part of the TxIn that remains unspent?

[There is no way to partially spend a UTXO](https://bitcoin.stackexchange.com/q/20611/5406). Spending UTXO is binary, either they are unspent or they are spent. Since UTXO can only be spent in full, any remainder from a payment gets collected into one or multiple outputs in which the sender pays themselves (see e.g. [How does change work in a bitcoin transaction?](https://bitcoin.stackexchange.com/q/736/5406)).

> Example, a transaction with 2 inputs and one output (assuming no
> fees):
>
> * TxIn[0] whose UTXO before spending is 1 BTC
> * TxIn[1] whose UTXO before spending is 1 BTC
> * TxOut[0] whose value is 1.5 BTC
>
> How do we know which TxIn, and how much of which, was spent?
>
> * was it TxIn[0] for 0.75 and TxIn[1] for 0.75?
> * was it TxIn[0] for 0.5 and TxIn[1] for 1?
>
> What am I missing? Because given the above, it is not possible to
> determine the spent proportion of each input.

The answer is that both `TxIn[0]` and `TxIn[1]` get spent completely and the transaction is created with two outputs: `TxOut[0]: 1.5 BTC to recipient` and `TxOut[1]: 0.5 BTC to sender`.

> **Comments:**
> **username_0**: Ah thank you for your detailed explanations. One of the pieces I was missing was that a UTXO cannot be partially spent, and that the remainder gets 'sent back to oneself' in a `vout`. Makes much more sense now.  

---

