Creating a new Transaction. The In’s and Out’s of Transactions
Note:
Transaction Fee
Change is given to the original spender if the sum of the inputs is greater than the amount being sent to the recipient. After adding the "change" output, if the sum of the inputs is greater than the sum of the outputs, the remainder is collected by the miner who confirms your transaction, which is called the "fee".
The transaction fee that goes to the miner is the delta between the total input and output amounts. In the example transaction, the miner fee is calculated as:
fee = (input amount) - (spend amount + change amount)
fee = (17373066) - (390582 + 16932484)
fee = 50000 satoshi
Change is given to the original spender if the sum of the inputs is greater than the amount being sent to the recipient. After adding the “change” output, if the sum of the inputs is greater than the sum of the outputs, the remainder is collected by the miner who confirms your transaction, which is called the “fee”. Naturally, the sum of all bitcoins in the inputs must be greater than or equal to the sum of all bitcoins in the outputs, or else your transaction will get rejected.
Replace-by-fee (RBF) Bitcoin
Replace-by-fee (RBF) is a feature that allows users to replace one version of an unconfirmed transaction with a different version of the transaction that pays a higher transaction fee. This can be done multiple times while the transaction is unconfirmed.
Transaction replacement
Additional materials
Bitcoin Wiki