Ethereum Gas Explained: Fees, Limits, and How to Spend Less
Reading time: 3 minutesWhy does sending ETH cost money? And why can a failed transaction still charge you?
While working on BlockStream Inspector, I explored how Ethereum measures gas usage and calculates transaction fees. Here’s the simple explanation I wish every new Ethereum developer had.
1. What is gas?
Think of Ethereum as a shared computer. Every transaction uses some of its resources, whether you’re sending ETH, swapping tokens, or updating a smart contract.
Gas measures how much work a transaction uses. Charging for that work helps prevent spam and stops programs from consuming unlimited resources.
Three terms are worth knowing:
- Gas used: The amount of work your transaction actually consumes.
- Gas limit: The maximum work you allow it to consume.
- Gas price: How much you pay for each unit of gas, usually measured in gwei.
A simple ETH transfer between ordinary wallets typically uses 21,000 gas. A smart contract interaction usually needs more.
2. How are gas fees calculated?
With EIP-1559, most Ethereum transactions use two main fees:
- Base fee: Set by the protocol according to network demand. It is burned.
- Priority fee: A tip that helps make your transaction attractive for inclusion.
The amount you pay is:
Transaction fee = Gas used × Effective gas price
Effective gas price = Base fee + Actual priority fee
For example, suppose you send ETH when the base fee is 10 gwei and the tip is 2 gwei:
Gas used: 21,000
Gas price: 12 gwei
Total fee: 252,000 gwei = 0.000252 ETH
Base fee burn: 0.000210 ETH
Priority fee: 0.000042 ETH
Your wallet also lets you set a maximum fee per gas. That’s a ceiling, not necessarily what you’ll pay. If the base fee rises above your maximum, your transaction must wait or be replaced.
3. Gas limit vs. gas used
A gas limit is a budget, not a flat charge. If you set a limit of 100,000 gas but your transaction only uses 60,000, you pay for the gas used, not all 100,000. But if a contract needs more gas than your limit allows, it can run out of gas. Its intended changes are rolled back, and the gas consumed is still charged. A transaction that reverts for another reason also normally costs gas.
This is why it’s worth checking the wallet’s estimate and simulating complex transactions before sending them.
4. What about blob gas?
Ethereum also has blob gas, introduced by EIP-4844. It pays for temporary blob data, mainly used by Layer 2 rollups to publish transaction batches.
Blob gas has a separate fee market from regular execution gas. This can make posting large amounts of L2 data cheaper, although prices still depend on demand. A blob transaction also pays regular execution gas.
5. Tracking gas with BlockStream Inspector
In BlockStream Inspector, I focused on understanding block-level gas metrics, including gas used, gas limits, and the base fee.
One useful metric is block gas utilization:
// Simplified example
fn utilization(gas_used: u64, gas_limit: u64) -> f64 {
if gas_limit == 0 {
return 0.0;
}
(gas_used as f64 / gas_limit as f64) * 100.0
}
For example, if a block uses 30 million gas out of a 36 million gas limit, utilization is about 83%. Remember that the base fee responds to usage relative to the block’s target, not simply whether the block is full.
6. Ways to avoid unnecessary gas costs
- Check fees before sending. If your transaction isn’t urgent, you can wait for lower network demand. There’s no guaranteed cheapest day or hour.
- Use sensible gas limits. Rely on estimates instead of setting the limit too low.
- Simulate contract calls. Catch issues such as insufficient allowance or slippage before paying for a failed transaction.
- Write efficient contracts. Avoid unnecessary storage writes, pack compatible variables, and use events for history that only off-chain applications need.
- Consider L2s. Networks such as Arbitrum, Base, and OP Mainnet can offer lower fees for supported transactions, but remember to account for bridging and withdrawal costs.
Batching operations can sometimes reduce repeated transaction overhead, but the actual savings depend on the contracts involved. Measure rather than guess.
What I learned
Gas is easier to understand once you separate how much work a transaction performs from how much each unit of that work costs.
For developers, the goal isn’t to make every transaction use the fewest possible gas units. It’s to build correct, secure applications, avoid unnecessary work, and measure the cost of each improvement.
Further reading
Originally published on HackMD . Comments and discussion live there.