How gas fees work
Every operation in a transaction costs a set amount of gas. You pay gas used × (base fee + priority fee). Since EIP-1559, the base fee is set by the network and burned, and the priority fee goes to the validator.[2]
The gas limit is the most gas you allow the transaction to use. A standard ETH transfer needs 21,000. If you set 50,000 for a transfer, 21,000 is used and 29,000 is returned. If you set 20,000, the transaction is rejected at validation before it enters a block, and no gas is charged.[1]
A transaction that runs out of gas during execution is different: the EVM reverts its changes, but all the gas you provided is consumed for the work already done.[1]
You also set maxFeePerGas, the most you will pay per unit of gas. You are refunded the difference between this cap and the base fee plus tip actually charged. Under EIP-1559 the tip you pay is min(max priority fee, max fee − base fee), so when the base fee rises close to your cap, the tip shrinks before the transaction becomes invalid.[2]
Why fees change
The base fee rises when blocks are fuller than the target and falls when they are emptier, so fees go up at busy times.[2]
The target is half the block gas limit, and a block can use up to twice the target. The change is linear: −12.5% for an empty block, 0% at the target, and +12.5% for a full block. ethereum.org's table with a 36 million gas limit shows the base fee going from 100 gwei to 112.5, then 126.6, then 142.4 gwei over consecutive full blocks.[1]
In EIP-1559 the adjustment is base fee × (gas used − target) ÷ target ÷ 8. With a base fee of 20 gwei, an 18 million target and a block that used 27 million: 20 × 9 ÷ 18 ÷ 8 = 1.25 gwei, so the next base fee is 21.25 gwei. These numbers are illustrative.[2]
Because the next base fee depends only on earlier blocks, a wallet can show a firm upper bound one block ahead: current base fee × 112.5%.[1]
Gas fees vs wallet fees
Gas goes to the network. MetaMask's swap guide splits a swap's cost into the quote rate, the network fee (gas) and a MetaMask fee of 0.875%; that last part is a separate charge added by the app.[4]
Worked example
All values below are illustrative. You send ETH with a gas limit of 21,000, a base fee of 15 gwei, a priority fee of 1.5 gwei and a max fee of 40 gwei.
Fee charged: 21,000 × (15 + 1.5) = 21,000 × 16.5 = 346,500 gwei = 0.0003465 ETH.[1]
Where it goes: 21,000 × 15 = 315,000 gwei (0.000315 ETH) is burned, and 21,000 × 1.5 = 31,500 gwei (0.0000315 ETH) goes to the validator as the tip.[1]
Refund: the wallet reserved 21,000 × 40 = 840,000 gwei. You get back 840,000 − 346,500 = 493,500 gwei, or 0.0004935 ETH.[2]
If the base fee jumped to 39.5 gwei before inclusion, the tip would be min(1.5, 40 − 39.5) = 0.5 gwei, and the total would be 21,000 × 40 = 840,000 gwei. Above 40 gwei the transaction waits until the base fee drops.[2]
How to check it yourself
A block explorer shows the gas used, the effective gas price and the total fee for any transaction. ethereum.org lists Etherscan and Blockscout among the gas price trackers you can check before sending.[1]
Developers can ask a node directly: eth_gasPrice returns an estimate in wei as a hex value. The example in the docs returns 0x1dfd14000, which is 8,049,999,872 wei, or about 8.05 gwei.[3]
The Bottom Line
Gas fees pay for the network’s work. Check the estimate in your wallet before you confirm, and use an L2 for small transactions.
Educational content, not financial advice.