# How does tx fee calculation work when txin and txout are similar amounts?

This website has an example called "When Too Much is Not Enough" on its main page. I'll quote it an case this is changed in the future:

Suppose you have only two outputs in your wallet, worth 1 XBT and 2 XBT. You want to buy something for 2.999 XBT. The coin selection code has no choice; it has to select both coins to get a big enough total to make the transaction. That means the change will be 0.001 XBT, which triggers the 0.0001 XBT fee for having an output that's less than 0.01 XBT. As a result your transaction will fail, because the amount you're sending plus the fee is more than you have.

What this means is that there's no way of spending 2.999 XBT when you have 3 XBT. You could send the full 3 XBT to the vendor without a fee (assuming the outputs are sufficiently old to satisfy step 3), but some vendors ask you to send the exact amount they specify.

Since the 1 BTC input and the 2 BTC input are interchangeable in this respect, let's (for the sake of simplicity) settle that the bitcoin client decides to send the 2 BTC input in full for this example.

Then it has to split the 1 BTC input into a 0.999 BTC output and a 0.001 BTC output. I assume that doing so requires a fee because one of the outputs is smaller than 0.01 BTC. So 0.0001 BTC have to be paid for this. This means that there now is a 0.999 BTC junk and a 0.0009 BTC. The 2 BTC junk and the 0.999 BTC junk are send away and the 0.0009 BTC junk remains at its owner.

Can you tell me what I did wrong to get an outcome different from the one of the authors of that website?

## 1 Answer

Obviously, the example is erroneous. They also neglect to consider that you could send 2.999 XBT and designate all of the remainder of 0.001 XBT as fee.