Why does the transaction fee not show up as a transaction output in the block explorer?

"Why does the transaction fee not show [up] as a transaction output in the block explorer?" "I just bought 'Mastering Bitcoin.'" "I had this question [after] looking at a sample transaction in a block explorer." "Is there a public address where the transaction fee is sent, or is that address hidden on purpose?" That is a great question. It is something that is very confusing at first. [When] you look in the block explorer, it is supposedly showing you all of the information in the block. It seems that fees are not in there at all. The reason is because fees are indeed not in there. A transaction does not include a specific output for fees; fees are not [explicitly] part of the transaction. One of the reasons is, [if they were an output], that would require you to know [the address of the miner]. You would need to put an output in your transaction that could be redeemed by a miner. But [since] you don't know who will mine it yet, that would be impossible. The second problem is, [if fees were an output], then you would have an extra output in every transaction. If you have 4,000 transactions in a block, that would be 4,000 [extra] outputs for fees. Yet if the fees [of the transactions in that block] will all go to one miner [or mining pool], why do we need 4,000 outputs? [Luckily], that is not how fees work. Fees are leftover, meaning you have inputs that bring a certain [amount of] value into a transaction, and then you have outputs that spend less than that. The difference, the [portion] that is funded by the inputs but isn't spent by the outputs, the over-fund of inputs minus outputs, whatever is left over, is the fee. You make a fee in a bitcoin transaction by funding the transaction with inputs... and then spending less than the entire amount. Whatever is left over is the fee.

Where is the public address that receives all the fees? Where is that payment?

It is implicit, it is not explicit. [You may be thinking], 'Okay, great. But if it is not in the transact, then where is it?' Where is the public address that [receives] all the fees? Where is that payment? Here is the answer: it is [calculated as 'nFees'] in the coinbase [with] the block [reward, 'nSubsidy']... where the transaction is mined. If you [currently] look at your transaction in a block and at the coinbase transaction of that block... the coinbase reward ('nSubsidy') is 12.5 bitcoin. The coinbase transaction pays to a specific pay-to-public-key-hash (P2PKH), or it might be a different type of script, but usually it is a pay-to-public-key-hash (P2PKH). You can see which address the miner is [being paid] to, which is not [just] the 12.5 bitcoin [reward]. They are [paid an amount like] 12.513621, 12.6, or 12.6253 [bitcoin]... Where did [those extra satoshis] come from, that [additional] 0.1253 bitcoin? That is the fees, the fees from all of the transactions included in that block. [You can] do the math! Go [count the fees of] every transaction in a block. It would probably be best to pick a block that is relatively empty. You can find [more of] those in the early days of Bitcoin, but the same rules apply. You can find blocks with two or three transactions, [and still do] the math. You could even run a little script, if you want to try out your [programming] skills with the Bitcoin software. Run scripts that interrogate the blockchain so you can see [how it works] for yourself. Download a block, pull out all the transactions, add up the amounts of all the inputs and the outputs, deduct the outputs from the inputs, and [what you have as] leftover is the fees for all of the transactions. If you look at the coinbase, the amount above and beyond the reward that comes in each block, which is currently 12.5 bitcoin (or whatever it was when the block you are looking at [was mined), you will see the coinbase is more than that reward. That amount should correspond exactly to the excess input of all the transactions... of the implicit fees. That is where the output [of the coinbase] is sent, and the address where the transaction fees are sent. It is [calculated as part of] the coinbase transaction It works like that because, when a miner mines a block, they construct the block by [collecting] transactions... and count up all of the fees. Then they construct a coinbase transaction that gives them all of those fees, plus the reward. Then they [must] find proof-of-work to make it a valid block. The miner writes the coinbase transaction. They know where the fees should go and they [calculate it as part of their reward]. There are no fee outputs in any of the individual transactions, [just] one fee output for the block: the combined amount of [block subsidy] plus all the fees from the transactions. I hope that answers your question. It is a little tricky thing [to understand], but it is very interesting how it [was] designed... and why it has been designed like that. I hope you enjoyed that answer.