Oops I thought I had already posted it but thanks everyone so much for all of this information. It's hard to sift through all of the information online and find something that just clearly explains these basic things in plain English.
For my future reference:
Input = Credit
Output = Debit
Unspent output = 'spendable'
or balance in your bitcoin address equal to the inputs added up or possible bitcoins you can spend. The number of inputs will determine how high the fee is. Ex: 5 inputs of 0.002 will have a higher fee than 1 input (now an unspent output) of 0.01BTC.
You're getting close, but your use of words like "credit" and "debit" indicates that you are still thinking of addresses like accounts, and they really aren't. Also, either I'm mis-understanding what you've written, or you are still getting a bit confused with the concept of the relationship between inputs and unspent outputs.
Lets start by trying to clear up some common confusions. You may not be confused about some of these things (I'm not sure), so this might not be directed at you, but it still could be helpful to others reading this thread:
There are no accounts. Do not think of bitcoin addresses as accounts, it will only cause you confusion in the long run. If you need an analogy, think of them as invoice numbers, but remember that at the protocol level, there aren't even any bitcoin addresses at all. Addresses are an abstraction that we humans use to make it easier to talk about transferring control of value.
When talking about bitcoin transactions, the word "input" refers to value being put into the transaction, not value being put into an address, or wallet, or account. Again, if you really need an analogy, you can think about an input as being a removal (or subtraction) from your control and an addition to the transaction's control.
When talking about bitcoin transactions, the word "output" refers to value coming out of the transaction, not value coming out of an address, or wallet, or account. If you really need an analogy, you can think about an output as being a removal (or subtraction) from the transaction's control and an addition to the control of a private key.
An unspent output is simply an output that hasn't been used as an input yet. Each output in the blockchain can only be used as an input once. After that, it is considered to have been spent and isn't allowed to be used as an input into any other transactions ever.
Now that we've cleared up some common confusions, lets take a look at how this all works...
You receive three separate payments. Each payment is a transaction output that is associated with a private key that you control, and you haven't spent any of it yet. Therefore, you are in control over 3 unspent transaction outputs. Lets call these outputs A, B, and C. A is valued at 1 BTC, B at 0.5 BTC, and C is 2 BTC. You are using wallet software that has all the associated private keys, so that wallet sees these 3 outputs in the blockchain, and understands that it has the ability to spend all three of them. The wallet therefore adds them all up and shows you a total of 3.5 BTC under your control.
Now, you want to send 2.25 BTC to Jack. Jack gives you a bitcoin address that is associated with a private key that he has. You tell your wallet software to create a transaction sending 2.25 BTC to Jack.
Your wallet searches through the list of outputs that it has the ability to spend, and chooses outputs B & C. The wallet then creates a transaction by listing as inputs the outputs that it wants to spend and listing as outputs the new outputs that it wants to create:
Transaction Inputs:B
C
Transaction Outputs:D has a script that puts it under the control of Jack's private key (valued at 2.25 BTC)
E has a script that puts it under the control of a private key that your wallet has (valued at 0.24 BTC)
The wallet uses the private keys that it controls to generate digital signatures for B and C to prove to the entire network that it is authorized to spend those outputs, broadcasts the transaction to the network, and a miner eventually mines a block confirming this transaction into the blockchain.
Now, since this transaction just spent B & C, those are "spent outputs" and can never be used as inputs to any other transaction. Your wallet still has control over A and it hasn't been spent yet, so it is still an unspent output. Your wallet also now has control over E. Since E hasn't shown up in a list of transaction inputs anywhere yet, it is also an unspent output. Your wallet adds up the values of A and E and shows you a total of 1.24 BTC under your control.
Jack's wallet sees that it has control over output D. Since D hasn't been listed as an input to any other transactions yet, it is an unspent output. Jack's wallet shows him a total of 2.25 BTC under his control.
You'll notice if you add up the values of B & C that they total 2.50 BTC. So, in the list of transaction inputs, you transferred a total of 2.50 BTC to the control of the transaction. If you add up the values of D & E they total 2.49 BTC. So, the transaction transferred a total of 2.49 BTC to the control of Jack and yourself. The extra 0.01 BTC that is not accounted for in the transaction outputs is the transaction fee that the miner gets to assign to himself in the block reward of the block he solved. This is how transaction fees are paid to miners. If your wallet had instead given output E a value of 0.25 BTC, then this transaction would have paid no fee at all. If the sum of the values of the transaction outputs is higher than the sum of the values of the transaction inputs, then the transaction is invalid and every node on the network will reject the transaction and refuse to relay it or add it to any blocks.
Now, lets say Jack decides to pay 3 people in a single transaction. He's going to send 1 BTC to Bob, 0.75 BTC to you, and 0.3 BTC to Sally. Jack receives a bitcoin address from each of you and tells his wallet software what he wants to do.
Jack's wallet searches through the list of outputs that it has the ability to spend, and discovers that D is the ONLY unspent output Jack has. The wallet then creates a transaction by listing D as an input and listing as outputs the new outputs that it wants to create:
Transaction Inputs:D
Transaction Outputs:F has a script that puts it under the control of a private key that Bob's wallet has (valued at 1.00 BTC)
G has a script that puts it under the control of a private key that Sally's wallet has (valued at 0.30 BTC)
H has a script that puts it under the control of a private key that your wallet has (valued at 0.75 BTC)
I has a script that puts it under the control of Jack's private key (valued at 0.11 BTC)
The wallet uses the private keys that it controls to generate a digital signature for D to prove to the entire network that it is authorized to spend that output, broadcasts the transaction to the network, and a miner eventually mines a block confirming this transaction into the blockchain.
As you can hopefully see:
As a transaction has more inputs it gets bigger, because the list gets longer.
As a transaction has more outputs it gets bigger because the list gets longer.
Since the fee that is paid is typically chosen as an amount "per byte", each additional input and each additional output adds to the total fee the transaction is likely to pay. Each input adds about 148 bytes to the size of the transaction. Each output adds about 34 bytes to the size of the transaction.
Hopefully you can see that the value of the transaction has nothing to do with it's size. A single input is 148 bytes regardless of whether that input is 0.0001 BTC or 5000.00 BTC. A single output is 34 bytes regardless of whether that output is 0.0001 BTC or 5000.00 BTC.Looking at the blockchain, there are now a total of 9 outputs.
- 3 of them (B, C, and D) have been used as inputs and are therefore now spent.
- 3 of them (A, E, and H) have not been spent yet and are all under your control
- 1 of them (F) has not been spent yet and is under the control of Bob
- 1 of them (G) has not been spent yet and is under the control of Sally
- 1 of them (I) has not been spent yet and is under the control of Jack
If we add up the values of the unspent outputs we see that you have control over 1.99 BTC, Bob has control over 1.0 BTC, Sally has control over 0.3 BTC and Jack has control over 0.11 BTC.
The blockchain is nothing more than a list of all the blocks that have been created by miners.
Blocks are nothing more than a header record that proves that the miner did the work he was supposed to, and a list of transactions. So, the blockchain is a LONG list of EVERY transaction ever confirmed.
Any new wallet can start at the first block and follow through all the transactions. The wallet can keep track of a list of ALL the unspent transactions. Each time the wallet sees a transaction, it can add all the outputs of that transaction to its list of unspent outputs. It can also remove all the inputs of that transaction from its list of unspent outputs. This process of going step-by-step through every transaction that has ever existed is called "synchronizing" the wallet. When the wallet is done, it will have a complete list of EVERY output that has ever been created and not yet spent. This list of unspent outputs is called the "UTXO". The wallet can now compare the list of private keys that it has to the UTXO to see exactly how many bitcoins it has control over. It can also use the UTXO to make sure that every new transaction that is broadcast on the network ONLY has inputs that are in the UTXO. If any transaction tries to list as an input something that is not in the UTXO, then the transaction is rejected as invalid, and the wallet refuses to accept or relay the transaction. Every time the wallet receives a new solved block it goes through all the transactions in the block, adding all the outputs of all the transactions to its UTXO and removing all the inputs of all the transactions from its UTXO.
See that there are no "accounts". There is just a list of inputs and outputs. That's it. Each transaction simply spends outputs that were created earlier (by listing them as inputs), and creates new outputs. Each wallet simply keeps track of all the outputs that it has control over, and displays to the user a sum of those outputs.