The first transaction in any block is called a coinbase transaction. Unlike regular transactions, the coinbase transaction does not consume the unspent transaction output (UTXO) as inputs. Instead, it has only one input, called the coinbase that creates bitcoin from nothing. The coinbase transaction has one output, payable to the miner’s own bitcoin address. The output of the coinbase transaction sends the bitcoin reward value to the miner’s bitcoin address
To construct the coinbase transaction, the bitcoin node first calculates the total amount of transaction fees by adding all the inputs and outputs of the transactions that were added to the block. The fees are calculated as:
Total Fees = Sum(Inputs) - Sum(Outputs)
Next, the bitcoin node calculates the correct reward for the new block. The reward is calculated based on the block height, starting at 50 bitcoin per block and reduced by half every 210,000 blocks.
Source: Mastering Bitcoin 2nd Edition; Antonopoulos, A.; 2017