<blockquote>
<p>Once this transaction is processed, does my wallet remember that these 2 btc came from separate UTXO's? Or does it &quot;get melted&quot; as someone alluded to in my first link. More precisely, if I send these 2 btc to Gerald, will it show 1 input or 2?</p>
</blockquote>
<p>Your wallet may or may not keep track of the history of the funds you received. But all that really matters from that point on is that you have one UTXO that is yours to do with as you wish.</p>
<blockquote>
<p>Lastly, I think I understand that most wallet services &quot;handle&quot; all these details for you in the sense that you can just put the btc address and how much you want to send and they handle the rest. Do they typically do this in a most efficient way? For example, say I use a wallet like a Nano Ledger S. If I have a UTXO for 25 btc, a UTXO for 1 btc, and 5 UTXO's for .5 btc and I go to send someone 1 btc, will it choose the UTXO's that result in the smallest transaction size?</p>
</blockquote>
<p>For simple cases, they typically do. For very complex cases, it's computationally quite expensive to ensure you that always produce the absolutely optimal result given that the number of possibilities that need to be considered can get absurdly large. Most implementations do not guarantee they will always produce the very best result but instead use heuristics that do in fact find the optimal result the vast majority of the time for typical cases and still provide very good results in absurdly complex situations with potentially thousands of UTXOs to choose from.</p>

CC BY-SA 4.0
2021-03-08T02:06:33.480Z
2021-03-08T02:06:33.480Z
David Schwartz
<blockquote>
<p>does my wallet remember that these 2 btc came from separate UTXO's? Or does it &quot;get melted&quot; as someone alluded to in my first link. More precisely, if I send these 2 btc to Gerald, will it show 1 input or 2?</p>
</blockquote>
<p>It shows as 1 UTXO that you can spend. Your wallet does not care about the UTXOs that were spent to create the UTXOs that you can spend. There's nothing there it needs to know, so it doesn't care about it.</p>
<blockquote>
<p>Does this mean she now has 3 inputs and 2 outputs contributing to the size of the transaction (and thus contributing to the size of the fee) (she needs all three coins to pay me and cover the fee, and then I will be one output and her &quot;change address&quot; will be the other.</p>
</blockquote>
<p>Yes.</p>
<blockquote>
<p>Do they typically do this in a most efficient way? For example, say I use a wallet like a Nano Ledger S. If I have a UTXO for 25 btc, a UTXO for 1 btc, and 5 UTXO's for .5 btc and I go to send someone 1 btc, will it choose the UTXO's that result in the smallest transaction size?</p>
</blockquote>
<p>Not necessarily.</p>
<p>Now you are getting into an area that is considered hard. In general, this question is about coin selection algorithms, of which there are many and they optimize for different things. Coin selection is also a multidimensional problem, and what is considered good, bad, efficient, or inefficient is not well defined.</p>

CC BY-SA 4.0
2021-03-08T02:13:06.907Z
Thank you the for the elaboration on coin selection. My background is in pure mathematics - which led to cryptography - which led to studying bitcoin. Glad to know this is an interesting area of questions. Can you point me to anywhere that I can find out more about hot research areas surrounding btc / crypto / blockchain?
Prince M
CC BY-SA 4.0
2021-03-08T02:08:28.280Z
2021-03-08T02:08:28.280Z
Ava Chow
<blockquote>
<p>does my wallet remember that these 2 btc came from separate UTXO's? Or does it &quot;get melted&quot; as someone alluded to in my first link. More precisely, if I send these 2 btc to Gerald, will it show 1 input or 2?</p>
</blockquote>
<p>(1) Your have a single 2 BTC UTXO, created by Alice's transaction. That transaction spent two UTXOs, but melded them into a single one. Your wallet doesn't care about its history - it has one UTXO, and when spending it, it needs a transaction with one input.</p>
<p>It is possible for wallet or other software to figure out the history of the coins, and figure out that it came from a transaction that spent two. But it has no impact on future transactions with it.</p>
<blockquote>
<p>Does this mean she now has 3 inputs and 2 outputs contributing to the size of the transaction (and thus contributing to the size of the fee)</p>
</blockquote>
<p>That's right. You'd create a transaction with 3 inputs (each 1 BTC) and 2 outputs (one of 2 BTC, one of 0.5 BTC). The difference is 0.5 BTC going to fees.</p>
<blockquote>
<p>Do they typically do this in a most efficient way?</p>
</blockquote>
<p>Often, no, actually. Because &quot;most efficient&quot; isn't the only criterion to optimize for. For example, you want to minimize the cost of transactions now, but you also don't want to bring your wallet in a state that increases the cost of transactions later. For example, some strategies for coin selection (as this problem is called) would result in continuously grinding down your coins into ever-smaller change in typical workloads, making it more and more expensive to send out future coins.</p>
<p>Some wallets will take current fee conditions into account to make these decisions.</p>
<p>Overall there is a significant amount of work analyzing various coin selection schemes. Some are featured in Mark Erhardt's <a href="https://murch.one/wp-content/uploads/2016/11/erhardt2016coinselection.pdf" rel="nofollow noreferrer">master thesis</a>.</p>

CC BY-SA 4.0
2021-03-08T02:14:03.983Z
Thank you the for the link! My background is in pure mathematics - which led to cryptography - which led to studying bitcoin. Glad to know this is an interesting area of questions.
Prince M
CC BY-SA 4.0
2021-03-18T22:53:39.407Z
a related question to this post. Is the reason that transaction fee is related to size because smaller size tx implies the miner could have fitten more tx's in a block?
Prince M
CC BY-SA 4.0
2021-03-18T22:56:31.730Z
Yes, exactly that. Optimizing for maximum fee income automatically leads miners to prioritize by fee per byte (or per weight, since segwit, as constraint is limited block weight, not block size now).
Pieter Wuille
CC BY-SA 4.0
2021-03-08T02:07:35.947Z
2021-03-08T02:28:03.797Z
2021-03-08T02:28:03.797Z
Pieter Wuille
<p>I have been working on understanding the inputs/outputs and transaction details as according to the UTXO model which is discussed in <a href="https://bitcoin.stackexchange.com/questions/96822/why-is-there-change-in-bitcoins/96832#96832">this question</a> and also thinking about how it relates to transaction fee based on size in kb of the transaction which is discussed in <a href="https://bitcoin.stackexchange.com/questions/1195/how-to-calculate-transaction-size-before-sending-legacy-non-segwit-p2pkh-p2sh">this question</a>. I want to clarify a few things, feel free to pick apart anything I say that is wrong in addition to answering my questions - since the questions are derived from my understandings.</p>
<p>It seems that the transaction size is mostly a function of number of inputs and outputs (in the sense that those are the things I as a sender have control over, where the other components contributing to size are more or less static).</p>
<p><strong>Clarification 1: (ignoring the fee and change)</strong>
Suppose Alice sends me (Bob!) 2 btc. She got these 2 btc as a result of Larry and Greg each sending her 1 btc. This means she has these two UTXO outputs each for 1 btc associated to her wallet, and when she sends them to me the transaction will have 2 inputs and 1 output, kind of like this transaction I found on a block explorer.</p>
<p><a href="https://i.sstatic.net/0Qc7M.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/0Qc7M.png" alt="enter image description here" /></a></p>
<p>Once this transaction is processed, <code>does my wallet remember that these 2 btc came from separate UTXO's? Or does it &quot;get melted&quot; as someone alluded to in my first link. More precisely, if I send these 2 btc to Gerald, will it show 1 input or 2?</code></p>
<p><strong>Clarification 2: (with fee and change)</strong>
Alice wants to send me 2 btc. She has previously been sent 1 btc by each of Larry, Greg, and Allan. So she has 3 UTXO's associated with her wallet, each worth 1 btc. She goes to send me 2 btc, but needs to cover the fee. For convenience lets say a .5 btc fee. <code>Does this mean she now has 3 inputs and 2 outputs contributing to the size of the transaction (and thus contributing to the size of the fee)</code> (she needs all three coins to pay me and cover the fee, and then I will be one output and her &quot;change address&quot; will be the other.</p>
<p>Lastly, I think I understand that most wallet services &quot;handle&quot; all these details for you in the sense that you can just put the btc address and how much you want to send and they handle the rest. <code>Do they typically do this in a most efficient way?</code> For example, say I use a wallet like a Nano Ledger S. If I have a UTXO for 25 btc, a UTXO for 1 btc, and 5 UTXO's for .5 btc and I go to send someone 1 btc, will it choose the UTXO's that result in the smallest transaction size?</p>
<p>Addendum: I do plan on being active on this site, so please do critique if my questions can be improved to better fit this community.</p>

<transactions><transaction-fees><utxo><transaction-weight>
UTXO Model and Trans Fee / Kb Clarification
Prince M
# UTXO Model and Trans Fee / Kb Clarification

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

I have been working on understanding the inputs/outputs and transaction details as according to the UTXO model which is discussed in [this question](https://bitcoin.stackexchange.com/questions/96822/why-is-there-change-in-bitcoins/96832#96832) and also thinking about how it relates to transaction fee based on size in kb of the transaction which is discussed in [this question](https://bitcoin.stackexchange.com/questions/1195/how-to-calculate-transaction-size-before-sending-legacy-non-segwit-p2pkh-p2sh). I want to clarify a few things, feel free to pick apart anything I say that is wrong in addition to answering my questions - since the questions are derived from my understandings.

It seems that the transaction size is mostly a function of number of inputs and outputs (in the sense that those are the things I as a sender have control over, where the other components contributing to size are more or less static).

**Clarification 1: (ignoring the fee and change)**
Suppose Alice sends me (Bob!) 2 btc. She got these 2 btc as a result of Larry and Greg each sending her 1 btc. This means she has these two UTXO outputs each for 1 btc associated to her wallet, and when she sends them to me the transaction will have 2 inputs and 1 output, kind of like this transaction I found on a block explorer.

[![enter image description here](https://i.sstatic.net/0Qc7M.png)](https://i.sstatic.net/0Qc7M.png)

Once this transaction is processed, `does my wallet remember that these 2 btc came from separate UTXO's? Or does it "get melted" as someone alluded to in my first link. More precisely, if I send these 2 btc to Gerald, will it show 1 input or 2?`

**Clarification 2: (with fee and change)**
Alice wants to send me 2 btc. She has previously been sent 1 btc by each of Larry, Greg, and Allan. So she has 3 UTXO's associated with her wallet, each worth 1 btc. She goes to send me 2 btc, but needs to cover the fee. For convenience lets say a .5 btc fee. `Does this mean she now has 3 inputs and 2 outputs contributing to the size of the transaction (and thus contributing to the size of the fee)` (she needs all three coins to pay me and cover the fee, and then I will be one output and her "change address" will be the other.

Lastly, I think I understand that most wallet services "handle" all these details for you in the sense that you can just put the btc address and how much you want to send and they handle the rest. `Do they typically do this in a most efficient way?` For example, say I use a wallet like a Nano Ledger S. If I have a UTXO for 25 btc, a UTXO for 1 btc, and 5 UTXO's for .5 btc and I go to send someone 1 btc, will it choose the UTXO's that result in the smallest transaction size?

Addendum: I do plan on being active on this site, so please do critique if my questions can be improved to better fit this community.

**Tags:** transactions, transaction-fees, utxo, transaction-weight


---

## 3 answers

### Answer by username_3 on 2021-03-08. Score: 4 | Accepted answer

> does my wallet remember that these 2 btc came from separate UTXO's? Or does it "get melted" as someone alluded to in my first link. More precisely, if I send these 2 btc to Gerald, will it show 1 input or 2?

(1) Your have a single 2 BTC UTXO, created by Alice's transaction. That transaction spent two UTXOs, but melded them into a single one. Your wallet doesn't care about its history - it has one UTXO, and when spending it, it needs a transaction with one input.

It is possible for wallet or other software to figure out the history of the coins, and figure out that it came from a transaction that spent two. But it has no impact on future transactions with it.

> Does this mean she now has 3 inputs and 2 outputs contributing to the size of the transaction (and thus contributing to the size of the fee)

That's right. You'd create a transaction with 3 inputs (each 1 BTC) and 2 outputs (one of 2 BTC, one of 0.5 BTC). The difference is 0.5 BTC going to fees.

> Do they typically do this in a most efficient way?

Often, no, actually. Because "most efficient" isn't the only criterion to optimize for. For example, you want to minimize the cost of transactions now, but you also don't want to bring your wallet in a state that increases the cost of transactions later. For example, some strategies for coin selection (as this problem is called) would result in continuously grinding down your coins into ever-smaller change in typical workloads, making it more and more expensive to send out future coins.

Some wallets will take current fee conditions into account to make these decisions.

Overall there is a significant amount of work analyzing various coin selection schemes. Some are featured in Mark Erhardt's [master thesis](https://murch.one/wp-content/uploads/2016/11/erhardt2016coinselection.pdf).

> **Comments:**
> **username_0**: Thank you the for the link! My background is in pure mathematics - which led to cryptography - which led to studying bitcoin. Glad to know this is an interesting area of questions.  
> **username_0**: a related question to this post. Is the reason that transaction fee is related to size because smaller size tx implies the miner could have fitten more tx's in a block?  
> **username_3**: Yes, exactly that. Optimizing for maximum fee income automatically leads miners to prioritize by fee per byte (or per weight, since segwit, as constraint is limited block weight, not block size now).  

---

### Answer by username_1 on 2021-03-08. Score: 2

> Once this transaction is processed, does my wallet remember that these 2 btc came from separate UTXO's? Or does it "get melted" as someone alluded to in my first link. More precisely, if I send these 2 btc to Gerald, will it show 1 input or 2?

Your wallet may or may not keep track of the history of the funds you received. But all that really matters from that point on is that you have one UTXO that is yours to do with as you wish.

> Lastly, I think I understand that most wallet services "handle" all these details for you in the sense that you can just put the btc address and how much you want to send and they handle the rest. Do they typically do this in a most efficient way? For example, say I use a wallet like a Nano Ledger S. If I have a UTXO for 25 btc, a UTXO for 1 btc, and 5 UTXO's for .5 btc and I go to send someone 1 btc, will it choose the UTXO's that result in the smallest transaction size?

For simple cases, they typically do. For very complex cases, it's computationally quite expensive to ensure you that always produce the absolutely optimal result given that the number of possibilities that need to be considered can get absurdly large. Most implementations do not guarantee they will always produce the very best result but instead use heuristics that do in fact find the optimal result the vast majority of the time for typical cases and still provide very good results in absurdly complex situations with potentially thousands of UTXOs to choose from.


---

### Answer by username_2 on 2021-03-08. Score: 2

> does my wallet remember that these 2 btc came from separate UTXO's? Or does it "get melted" as someone alluded to in my first link. More precisely, if I send these 2 btc to Gerald, will it show 1 input or 2?

It shows as 1 UTXO that you can spend. Your wallet does not care about the UTXOs that were spent to create the UTXOs that you can spend. There's nothing there it needs to know, so it doesn't care about it.

> Does this mean she now has 3 inputs and 2 outputs contributing to the size of the transaction (and thus contributing to the size of the fee) (she needs all three coins to pay me and cover the fee, and then I will be one output and her "change address" will be the other.

Yes.

> Do they typically do this in a most efficient way? For example, say I use a wallet like a Nano Ledger S. If I have a UTXO for 25 btc, a UTXO for 1 btc, and 5 UTXO's for .5 btc and I go to send someone 1 btc, will it choose the UTXO's that result in the smallest transaction size?

Not necessarily.

Now you are getting into an area that is considered hard. In general, this question is about coin selection algorithms, of which there are many and they optimize for different things. Coin selection is also a multidimensional problem, and what is considered good, bad, efficient, or inefficient is not well defined.

> **Comments:**
> **username_0**: Thank you the for the elaboration on coin selection. My background is in pure mathematics - which led to cryptography - which led to studying bitcoin. Glad to know this is an interesting area of questions. Can you point me to anywhere that I can find out more about hot research areas surrounding btc / crypto / blockchain?  

---

