ReCaseText
9 min read

Ethereum Gas Fees Explained: From Wei to EIP-1559

Every Ethereum transaction costs gas — but how are gas fees calculated, what changed with EIP-1559, and why do fees spike during network congestion? Here's a complete guide to how Ethereum's fee market works.

Every operation on the Ethereum network — transferring ETH, swapping tokens, minting NFTs, deploying contracts, interacting with DeFi protocols — requires a fee paid in ETH. This fee is denominated in gas, a unit that measures computational effort. Gas exists to prevent spam, compensate validators, and allocate scarce block space to the transactions that value it most.

The gas fee system has evolved significantly since Ethereum launched in 2015, most notably with EIP-1559 in August 2021. Understanding how gas works — from the smallest unit of ETH (wei) to the base fee and priority fee mechanism that governs today's fee market — is essential for anyone using Ethereum regularly.

This article explains gas from the ground up, covers the pre- and post-EIP-1559 fee models, breaks down a real fee calculation, and explains how to avoid overpaying.

What Is Gas?

Gas is a unit that measures the computational work required to execute operations on the Ethereum Virtual Machine. Each EVM operation — called an opcode — has a fixed gas cost. Adding two numbers costs 3 gas. Storing a 256-bit value to contract storage costs 20,000 gas (if the slot was previously empty). Reading from storage costs 2,100 gas after EIP-2929. Sending a basic ETH transfer — the simplest possible transaction — costs exactly 21,000 gas.

Gas is not a currency. You can't hold gas, transfer gas, or save gas for later. Gas is a measurement, like kilowatt-hours for electricity. What you actually pay is gas units multiplied by a gas price, denominated in a tiny fraction of ETH called gwei.

ETH Denominations: Wei, Gwei, and Ether

ETH is divisible to 18 decimal places. The smallest unit is called wei, named after Wei Dai, the creator of b-money (a precursor to Bitcoin). One ETH equals one quintillion wei — that's 1 followed by 18 zeros.

Because gas prices in wei produce inconveniently large numbers, the ecosystem uses an intermediate denomination called gwei (gigawei), where one gwei equals one billion wei, or 0.000000001 ETH. Most wallets, gas trackers, and block explorers display gas prices in gwei.

The conversion chain is: 1 ETH equals 1,000,000,000 gwei equals 1,000,000,000,000,000,000 wei. Our Ethereum unit converter and wei-to-gwei converter handle these conversions instantly. For a deeper dive into Ethereum denomination units, see our article on wei, gwei, and ether unit conversions.

The Pre-EIP-1559 Fee Model (Legacy)

Before August 2021, Ethereum used a simple first-price auction for gas fees. Each transaction specified a gas price — the amount in gwei the sender was willing to pay per unit of gas. Validators (miners, at the time) prioritized transactions with higher gas prices because those transactions generated more revenue.

This system had serious problems. Users had to guess the right gas price. Guess too low and your transaction sat in the mempool for hours or never confirmed. Guess too high and you overpaid. During periods of high demand, gas prices spiked unpredictably — sometimes 10x or more within minutes. The user experience was chaotic, especially for newcomers.

The auction also created MEV (maximal extractable value) dynamics, where validators could reorder transactions within a block to extract additional profit — front-running, sandwich attacks, and other strategies that transferred value from users to validators.

EIP-1559: The New Fee Model

EIP-1559, activated in the London hard fork on August 5, 2021, replaced the first-price auction with a mechanism that splits the gas fee into two components: the base fee and the priority fee (tip).

The base fee is set algorithmically by the protocol. It is the minimum price per gas unit that every transaction must pay. The base fee adjusts automatically based on network congestion: if the previous block was more than 50 percent full, the base fee increases (by up to 12.5 percent per block). If the previous block was less than 50 percent full, the base fee decreases. This creates a predictable fee market where users can look at the current base fee and know the minimum they need to pay.

Critically, the base fee is burned — destroyed permanently — rather than paid to the validator. This was one of EIP-1559's most consequential changes. Every transaction removes a small amount of ETH from the total supply, creating a deflationary pressure that partially offsets new ETH issuance from staking rewards.

The priority fee (tip) is set by the user and goes directly to the validator. It serves as an incentive for the validator to include your transaction in the current block rather than ignoring it. During normal conditions, a priority fee of 1 to 2 gwei is usually sufficient. During extreme congestion, higher tips may be necessary to outbid other transactions for limited block space.

Max fee per gas is the absolute maximum the user is willing to pay. It must be at least as large as the base fee plus the priority fee. If the max fee exceeds the base fee plus the tip, the difference is refunded. This protects users from sudden base fee spikes — you set a ceiling, and you never pay more than that ceiling, even if the base fee changes between when you submit the transaction and when it's included in a block.

Calculating a Gas Fee

The formula for the total gas fee under EIP-1559 is: gas units used multiplied by (base fee plus priority fee). Any difference between your max fee and the actual (base fee plus priority fee) is refunded.

For a basic ETH transfer using 21,000 gas, with a base fee of 20 gwei and a priority fee of 2 gwei, the total fee is 21,000 multiplied by 22 gwei, which equals 462,000 gwei, or 0.000462 ETH. At an ETH price of 3,000 dollars, that's about 1.39 dollars.

For a complex DeFi transaction — say a Uniswap swap using 150,000 gas — the same base fee and tip produce 150,000 multiplied by 22, which equals 3,300,000 gwei, or 0.0033 ETH (about 9.90 dollars). During peak congestion, with a base fee of 100 gwei and a tip of 10 gwei, the same swap costs 150,000 multiplied by 110, which equals 16,500,000 gwei, or 0.0165 ETH (about 49.50 dollars).

Our gas fee calculator lets you input the gas limit, base fee, and priority fee to see the total cost in gwei, ETH, and your local currency.

Why Gas Fees Spike

Gas fee spikes happen when demand for block space exceeds supply. Each Ethereum block has a target size of 15 million gas and a maximum size of 30 million gas. Under EIP-1559, the base fee adjusts to keep blocks at approximately the target size.

When demand surges — during a popular NFT mint, a DeFi exploit causing a rush for exits, a memecoin frenzy, or a sharp market move triggering a cascade of liquidations — blocks fill to their maximum. The base fee increases by up to 12.5 percent per block, and at Ethereum's roughly 12-second block time, it can double in under two minutes. During the most extreme episodes, base fees have exceeded 500 gwei, making even simple transfers cost tens of dollars.

The base fee also decreases when demand drops, and the 12.5 percent maximum adjustment per block means it cannot fall instantly. After a spike, the base fee often takes several minutes to return to normal levels, creating a "hangover" period where fees remain elevated.

Gas Limits and Out-of-Gas Errors

Every transaction specifies a gas limit — the maximum amount of gas the transaction is allowed to consume. For a simple ETH transfer, the gas limit is always 21,000. For contract interactions, the gas limit must be estimated based on the specific function being called and the current contract state.

If a transaction runs out of gas during execution — because the gas limit was set too low — the transaction fails. The state changes are reverted, but the gas fee is still charged. You pay for the computation that was performed, even though it produced no result. This is one of the most frustrating experiences in Ethereum: a failed transaction that costs real money.

Wallets like MetaMask estimate the gas limit automatically by simulating the transaction against the current state. This estimate is usually accurate, but it can be wrong if the contract state changes between estimation and execution (a common issue during high-activity periods). Adding a 10 to 20 percent buffer to the estimated gas limit is standard practice — unused gas is refunded, so overestimating the gas limit costs nothing extra.

Gas Optimization and Smart Contract Design

For developers, gas efficiency is a primary concern. Every opcode, every storage write, every byte of calldata costs gas that the user pays. Writing gas-efficient Solidity code can reduce transaction costs by 50 percent or more.

Common gas optimization techniques include using uint256 instead of smaller integer types (the EVM operates natively on 256-bit values, and smaller types require extra conversion operations), packing multiple values into a single storage slot, using events instead of storage for data that doesn't need to be read on-chain, and minimizing external contract calls.

The relationship between gas and ABI encoding is direct — every byte of calldata costs gas (16 gas per non-zero byte, 4 gas per zero byte after EIP-2028). Efficiently encoded function calls described in our article on ABI encoding and decoding consume less calldata gas.

Layer 2 and Gas Fee Reduction

Layer 2 scaling solutions — rollups like Arbitrum, Optimism, Base, and zkSync — dramatically reduce gas costs by executing transactions off the Ethereum mainnet and posting only compressed transaction data (or validity proofs) back to Layer 1.

A token swap that costs 150,000 gas on Ethereum mainnet might cost the equivalent of a few cents on a Layer 2. The trade-off is that you're trusting the rollup's security model (optimistic fraud proofs or zero-knowledge validity proofs) rather than Ethereum's full consensus for each individual transaction. But for most users and most use cases, Layer 2s offer the same functionality at a fraction of the cost.

EIP-4844 (Proto-Danksharding), activated in the Dencun upgrade in March 2024, introduced "blob" transactions that further reduced Layer 2 data posting costs by providing a dedicated, cheaper data space on Ethereum for rollup data.

Practical Tips for Managing Gas Fees

Time your transactions. Gas fees follow predictable patterns — lower on weekends and during off-peak hours (roughly 2 AM to 8 AM UTC on weekdays), higher during US and European business hours and during market volatility.

Use gas trackers. Sites like Etherscan's gas tracker, Blocknative, and Gas.Network show current base fees, priority fee recommendations, and historical trends. Check before submitting large transactions.

Set appropriate max fees. If your transaction is not time-sensitive, set a lower max fee and let it wait for a period of lower congestion. EIP-1559 transactions remain in the mempool until the base fee drops below your max fee or the transaction expires.

Use Layer 2 for routine transactions. If you're swapping tokens, transferring stablecoins, or interacting with DeFi, consider whether the same functionality is available on a Layer 2 at lower cost.

Batch operations. Some protocols allow batching multiple operations into a single transaction, amortizing the base 21,000 gas overhead across multiple actions.

The Bottom Line

Gas fees are the cost of using a decentralized, censorship-resistant computer that thousands of validators maintain simultaneously. The system has evolved from a chaotic first-price auction to a more predictable mechanism under EIP-1559, with base fees that adjust algorithmically and get burned, plus priority fees that compensate validators. Understanding how gas is calculated — and how denominations like wei, gwei, and ether relate to each other — gives you the knowledge to time your transactions, set appropriate fees, and avoid the frustration of failed transactions and unexpected costs. Use our Ethereum unit converter, gas fee calculator, and wei-to-gwei converter to make the math easy.

References

Ethereum.org — Gas and Fees — Official documentation on gas, fee calculation, and EIP-1559.

EIP-1559: Fee market change — The original Ethereum Improvement Proposal for the new fee model.

MetaMask — Ethereum Gas Fees Explained — User-friendly breakdown of gas fees under EIP-1559.

Eco — EIP-1559 Explained: Fee Market Reform — Detailed analysis of the base fee adjustment mechanism.

Decentralized Thoughts — EIP-1559 In Retrospect — Academic perspective on EIP-1559's economic properties and outcomes.