I'm learning that Bitcoin doesn't have a way to represent the account balance, but it's, rather, a sum of UTXO owned by the users of the private key. Then where is the change from the output stored?

What I mean is, when the output of a transaction is used as the input of another transaction, it must be spent in its entirety. Sometimes the coin value of the output is higher than what the user wishes to pay. In this case, the client generates a new Bitcoin address, and sends the difference back to this address.

Does the change get stored back in UTXO?


When a sender creates a transaction, they explicitly define which pieces of bitcoin they spend. We call such pieces of bitcoin Unspent Transaction Outputs (UTXO) and you can think of the UTXO Set as the distributed ledger of Bitcoin's balances. The state of UTXO is ternary: they either don't exist yet, are available for spending, or have been spent. So, you can't deduct from them, but must spend them completely in one transaction.

Spenders explicitly pick the transaction inputs by referencing the UTXO via its unique outpoint txid:vout which is derived from the transaction that created the to-be-spent UTXO. Now the spender essentially has assignable balance to the sum of the inputs' total value. The spender will explicitly assign the value of the consumed inputs to new outputs. Any funds not assigned are considered transaction fees and will be collectable by the miner that includes the transaction in a block.

This means the following hold true for (non-coinbase) transactions:

  • Σ(outputs) ≤ Σ(inputs)
  • transaction fees = Σ(inputs) - Σ(outputs)

So, to be clear, only the inputs and outputs on transactions are explicitly defined. The transaction fee is implicitly defined by the inputs and output.

It follows that a simple transaction sending to a single recipient will generally have two outputs:

  • a recipient output to conduct the payment
  • a change output to return the remaining funds from the inputs to the sender

I grabbed a random transaction from blockchair.com to visualize:

transaction with one input and two outputs of which one has a round number amount

If Alice's wallet had not created the change output to itself, Alice would have paid 11,044.… BTC in additional fees. ;)

Note, that I'm simply guessing that the 610 BTC is the recipient output due to the round number, I'm not intimately familiar with this transaction.

| improve this answer | |
  • Sorry I'm new to Bitcoin, could you elaborate? It looks like the input - output - fee = 0 in this case if I'm not mistaken. What if the input is greater than the sum of the output and the fee, and the change gets returned to the sender, where is this balance stored in within a block? – Kevvv May 7 at 15:33
  • The fee is implicitly equal to (input - output), it is not stored explicitly. So there is literally no way to write a transaction where (input - output - fee = 0) does not hold. – Pieter Wuille May 7 at 15:41
  • Thank you for your answer. What does it mean to say "Sometimes the coin value of the output is higher than what the user wishes to pay" from here then? en.bitcoin.it/wiki/Change – Kevvv May 7 at 15:52
  • Does that sentence regarding "change" imply that input - output = fee + change? – Kevvv May 7 at 15:53
  • No. Change is an output explicitly added by the creator of the transaction. From the perspective of the protocol it is just an output, indistinguishable from other outputs that actual perform the payment. If the inputs are larger the the outputs + fees the user wants to pay, their wallet should (and generally will automatically) add a change output to compensate. – Pieter Wuille May 7 at 15:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.