DEV Community

Cover image for Ethereum-Solidity Quiz Q26: How is the base fee(used in calculating the total gas fee) calculated by Ethereum?
MihaiHng
MihaiHng

Posted on

Ethereum-Solidity Quiz Q26: How is the base fee(used in calculating the total gas fee) calculated by Ethereum?

In the current Ethereum system (introduced by EIP-1559), the Base Fee is not set by users or miners/validators, it is automatically calculated by the network’s protocol itself based on block space demand. It's like a dynamic congestion tax that updates every block (~ 12 seconds).

1. The Target Capacity (50% Rule)

Ethereum has a Target size for each block, currently set at 15 million gas, with the Hard Limit at 30 million gas.

The protocol calculates the next Base Fee based on how full the current block is compared to that 15 million target:

  • If the block is > 50% full: The Base Fee increases for the next block (the network is busy).

  • If the block is < 50% full: The Base Fee decreases for the next block (the network has idle capacity).

  • If the block is exactly 50% full: The Base Fee remains the same.

2. The Mathematical Formula

The maximum the Base Fee can change between two consecutive blocks is 12.5%.

The simplified logic for the next block's Base Fee is:

New Base Fee = Current Base Fee + [Current Base Fee × (Actual Gas Used - Target Gas) / Target Gas × 0.125]

Enter fullscreen mode Exit fullscreen mode

Example Scenarios:

Maximum Congestion: If a block is 100% full (30M gas), the Base Fee increases by exactly 12.5% for the next block.

Empty Network: If a block is 0% full (0 gas), the Base Fee decreases by exactly 12.5% for the next block.

3. What happens to the Base Fee? (The Burn)

One of the most important aspects of the Base Fee is that it is burned. Before this update, all fees went to the miners/validators.

Now, the Base Fee is removed from the total supply of ETH. Only the Priority Fee (Tip) goes to the validator. This creates deflationary pressure — when the network is extremely busy, Ethereum actually destroys more ETH than it creates.

4. Why this change?

Before this calculation method was introduced, users had to "guess" the right price in a blind auction. If you guessed too low, the transaction sat pending for hours.

With the algorithmic Base Fee:

Predictability: You know exactly what the minimum price is to get into the next block.

Efficiency: Wallets (like MetaMask) can automatically calculate the "correct" fee without you having to look at gas trackers constantly.

Top comments (0)