How come the fees were higher than the actual amount in the bitcoin transaction? First of all, sorry for the newbie and probably a stupid question, I am so new to the digital currency thing :)

A day ago, I sent $2.5 worth bitcoin from my coinbase account to the copay wallet for testing. It went through OK, but later when I looked at the transaction details (via Blockcypher) I noticed that the fee shows up way higher than the actual amount: It was 0.004084 BTC (~16 US dollar as of yesterday).



I understand that the miner fees changes based on the demand and the block space of a transaction takes, and nowadays they are quite high. But I didn't get why the transaction went through in the first place if the fees that high, and I didn't pay for them (I think). Maybe I am missing something (probably I am)!

So, can someone kindly explain to me what's happening?

Thanks in advance.

PS: I am also adding the transaction information from coinbase. In that, the fee shows as 0.000316764 where as in the transaction details page via Blockcypher shows the fees as 0.004084. That is the part I am confused about. In other words, the fees don't match, and I was wondering what is the big discrepancy all about!
Basic explanation:

Two things are happening here, first, the transaction is quite big (2903 bytes). And second, the inputs of the transaction hold really low value (
27982 Satoshi each). If we put together this two facts, what happens is what you have seen, that the most of the transaction value is spent in fees.

Extended explanation:

When a previous transaction output (utxo) is used to create an input of a new transaction, there is a minimum amount of data that it will add to the transaction. This data can be split in two parts, a fixed_size that will be non-dependant of the input type, and a variable_size,that will depend on the input type (and therefore in the utxo type). 

The fixed_size can be defined as follows:

fixed_size = prev_tx_id + prev_out_index + nSequence = 32 + 4 + 4 = 40 


In the transaction you are referencing, all inputs are P2PKH, which means that the minimum amount of variable_size data that creating an input will contribute to the transaction can be expressed as follows:

min_variable_size = scriptSig_len + PUSH signature + signature + PUSH public_key + public_key


Signatures can be 71-73 bytes depending on their r and s components, and public keys can be 33/65 bytes, depending whether they are compressed or uncompressed. If we take the minimum signature size, and compressed public keys, the result is as follow:

min_variable_size = 1 + 1 + 71 + 1 + 33 = 107


and therefore:

min_size = fixed_size + min_variable_size = 147


Then, if we check how big was the transaction (2093 bytes) and how much was paid as fees (408400 Satoshi) we get that the fee ratio paid is around 141 sat/b. Now, if we check how much we should pay just for including one of our inputs in the best case we get:

min_size * fee_ratio = 107 * 141 = 20727 


So, around the 74% (20727/27982 * 100) of each input value is spent just for paying the fees required to spend itself. If you take into account the rest of the transaction (version, outputs and nLockTime), we got that around the 85% of the inputs value is paid as fee:

total_value = 475694
fee = 408400

perc = fee / total_value * 100 = 85.85