Transactions are stored in the block chain, so you never lose them. However, if you lose the private key associated with an unspent output, then you can never spend it. So it is important to always back up your private keys (the public key and bitcoin address can be derived from just the private key). When you import a private key into a new wallet, the wallet will scan the block chain looking for transactions that match the associated bitcoin address. These transactions will then appear in your wallet without any further action on your part.
Some wallets use discrete private keys, which means you must backup the wallet each time a new private key is generated. For example, Bitcoin-Qt keeps a pool of 100 new private keys, so you only need to backup the wallet after every 100 send requests (since change is returned to a new private key).
Deterministic wallets only need to be backed up once since they generate new keys using a stored seed. If you need to restore the wallet, the private keys can be regenerated from this seed. Electrum is an example of a deterministic wallet.
I noticed that every transaction has multiple inputs (the outputs of the previous transaction) and multiple outputs. I presume an "unspent output" means the sum_of_outputs < sum_of_inputs? – user11286 – 2013-12-24T17:07:48.633
No, an unspent output is an output that hasn't been included as an input in a later transaction. So, at any given point in time, a transaction can have a mix of spent and unspent outputs. And it isn't necessary to have multiple inputs as long as the single input is large enough to cover the outputs plus the miner fee. The simplest case is a transaction with one input and two outputs. One output goes to the designated recipient and the second output returns the change to your wallet (a transaction completely spends all of its inputs). – ScripterRon – 2013-12-24T17:22:05.700
OK so if I have a transaction with 1 input (of 1 BTC) and zero outputs and I need to pay someone 0.9BTC...the system will create 2 outputs of 1BTC to the B party and another output of 0.1 BTC that goes back as an input to this particular transaction? Why not just one output of 0.9 BTC to the B party? – user11286 – 2013-12-24T20:14:00.153
You can't have a transaction with 0 outputs. If you need to send 0.9 BTC, the wallet code will look for one or more unspent outputs belonging to one of your addresses until the total covers the 0.9 BTC plus the miner fee. These will be the inputs for the new transaction. The transaction will then have one output to send the 0.9 BTC. If there is any change left from the sum of the inputs, there will be a second output to return the change back to an address in your wallet. – ScripterRon – 2013-12-24T21:44:46.153
OK now I am starting to understand :) will the second output to return change also go onto the block chain or is it just an internal transfer to one of my existing addresses? – user11286 – 2013-12-26T13:03:59.743
It is a single transaction with two outputs. So, yes, the entire transaction will be in the block chain (anything not in the block chain doesn't count). This is the reason that it is recommended to use a new address for each change return. It makes it harder to associate an address with a person (and it also increases security somewhat). – ScripterRon – 2013-12-26T14:48:33.407