Transaction Change and Fees
A transaction output is required to be spent in its entirety. Typically, however, it is unlikely that the input coins exactly match the desired output amount. Bitcoin addresses this problem by creating change outputs to where the difference between the input coins and output coins is spent. Change outputs typically correspond to new randomly generated Bitcoin addresses whose private keys are retained by the current owner of the input coins. These addresses are often referred to as shadow addresses.
Note that the sum of BTCs issued to all transaction outputs cannot exceed the sum of BTCs of the transaction inputs. The sum of Bitcoins of the transaction outputs, however, can be smaller than the sum of Bitcoins of the transaction inputs. This difference is paid as a fee to the Bitcoin miner that includes the transaction within a block.
All transactions contain a field nLockTime that specifies the earliest time or the earliest block within which the transaction can be confirmed. Once a time-locked transaction is broadcasted in the network, miners can keep it in their list of transactions to be mined at a later stage. If the creator of the time-locked transaction changes his or her mind, they can create a new transaction that uses the same inputs (at least one overlapping input) as the time-locked transaction. The nontime-locked transaction would be confirmed immediately in a block, which would effectively make the time-locked transaction invalid.
The locktime field is 4 bytes long and is interpreted in two ways: (1) if locktime is less than 500 million, it corresponds to a block height (the highest block number of the current main blockchain), (2) if the locktime is greater to or equal than 500 million, then the locktime field is parsed as a UNIX time stamp.