Gas fees are one of the most important concepts in Ethereum. Every transaction, every smart contract call, and every token transfer requires gas. Yet gas fees remain one of the most confusing topics for newcomers. This guide breaks down exactly how Ethereum gas fees work, how they are calculated, and how you can optimize them.
What is Gas?
Gas is a unit of measurement for the computational work required to execute operations on the Ethereum network. Every operation in the Ethereum Virtual Machine (EVM) has a fixed gas cost. Simple operations cost less gas; complex operations cost more.
Think of gas like fuel for a car. The more complex your journey (transaction), the more fuel (gas) you need. But unlike fuel, the price of gas fluctuates based on network demand.
Key distinction: Gas is not ETH. Gas is a unit of computation. You pay for gas using ETH, but the two are different concepts. The amount of ETH you pay depends on the gas price, which changes constantly.
The Gas Fee Formula
The total fee for a transaction is calculated as:
Transaction Fee = Gas Used × Gas PriceLet's break down each component.
Gas Limit
The gas limit is the maximum amount of gas you are willing to spend on a transaction. You set this value when submitting a transaction.
- If your transaction uses less gas than the limit, you are refunded the difference.
- If your transaction runs out of gas before completing, the transaction fails and you lose the gas that was consumed. The remaining gas is refunded, but the used gas is not.
Common gas limits for typical operations:
| Operation | Typical Gas Limit |
|---|---|
| Simple ETH transfer | 21,000 |
| ERC-20 token transfer | 65,000 |
| ERC-20 token approval | 46,000 |
| Uniswap swap | 150,000 – 300,000 |
| NFT mint | 80,000 – 150,000 |
| Complex DeFi interaction | 200,000 – 500,000 |
| Contract deployment | 1,000,000 – 5,000,000+ |
A simple ETH transfer always costs exactly 21,000 gas because it performs a fixed set of operations. Smart contract interactions vary because the gas cost depends on the specific code path executed. Try calculating costs for these operations with our Gas Fee Calculator.
Gas Price and EIP-1559
Before August 2021, Ethereum used a simple auction model: users bid a gas price in Gwei, and miners prioritized higher-paying transactions. This led to unpredictable fees and frequent overpayment.
EIP-1559, activated in the London hard fork, replaced this system with a more predictable fee structure. Under EIP-1559, the gas price has two components:
Total Gas Price = Base Fee + Priority Fee (Tip)Base Fee
The base fee is determined algorithmically by the protocol. It adjusts automatically based on network congestion:
- If the previous block was more than 50% full, the base fee increases (up to 12.5% per block).
- If the previous block was less than 50% full, the base fee decreases.
The base fee is burned — it is destroyed and does not go to validators. This is the mechanism that makes ETH deflationary during periods of high usage.
Priority Fee (Tip)
The priority fee is a tip you pay directly to the validator who includes your transaction in a block. Higher tips incentivize validators to prioritize your transaction. During normal network conditions, a tip of 1-2 Gwei is sufficient. During congestion, you may need to increase your tip to get faster inclusion.
Max Fee
When submitting a transaction, you also specify a max fee — the absolute maximum gas price you are willing to pay. This protects you from unexpected fee spikes:
Actual Price Paid = min(Max Fee, Base Fee + Priority Fee)
Refund = (Max Fee - Actual Price Paid) × Gas UsedGas Price Units: Wei, Gwei, ETH
Gas prices are typically expressed in Gwei, a subunit of ETH:
| Unit | Value in Wei | Value in ETH |
|---|---|---|
| Wei | 1 | 0.000000000000000001 |
| Gwei | 1,000,000,000 | 0.000000001 |
| ETH | 1,000,000,000,000,000,000 | 1 |
1 Gwei = 1 billion Wei = 0.000000001 ETH
When someone says "gas is 30 Gwei," they mean the gas price is 30 Gwei per unit of gas. For a simple ETH transfer (21,000 gas), the fee would be:
21,000 gas × 30 Gwei = 630,000 Gwei = 0.00063 ETHAt an ETH price of $3,000, that equals about $1.89. Use our Gas Fee Calculator to compute exact costs for any gas limit and gas price combination, or convert between units with the ETH Unit Converter.
Why Do Gas Fees Change?
Gas fees are driven by supply and demand. Ethereum blocks have a target size of 15 million gas (with a maximum of 30 million gas). When demand for block space exceeds the target:
- More transactions compete for limited block space
- The base fee automatically increases
- Users bid higher priority fees to get included faster
- Total fees rise
Common causes of fee spikes:
- Popular NFT mints: A hyped NFT drop can cause thousands of users to submit transactions simultaneously
- DeFi liquidations: Market crashes trigger cascading liquidations that congest the network
- Token launches: New token launches on DEXes attract high trading volume
- Airdrop claims: When a major airdrop goes live, thousands of users rush to claim
EVM Opcode Gas Costs
Every operation in the EVM has a defined gas cost. Here are some common ones:
| Opcode | Operation | Gas Cost |
|---|---|---|
ADD | Addition | 3 |
MUL | Multiplication | 5 |
SLOAD | Read from storage | 2,100 (cold) / 100 (warm) |
SSTORE | Write to storage | 20,000 (new) / 5,000 (update) |
CALL | Call another contract | 2,600 (cold) / 100 (warm) |
CREATE | Deploy a contract | 32,000 |
KECCAK256 | Compute hash | 30 + 6 per word |
LOG | Emit event | 375 + 375 per topic |
Notice the massive cost difference between computation (ADD: 3 gas) and storage (SSTORE: 20,000 gas). This is by design: storage operations modify the global state that every node must maintain, so they are priced much higher to discourage excessive state growth.
Cold vs Warm Access
EIP-2929 introduced the concept of cold and warm storage access:
- Cold access: First time accessing a storage slot or address in a transaction. Costs more.
- Warm access: Subsequent accesses to the same slot or address in the same transaction. Costs less.
This incentivizes batching reads to the same storage slots, which is more efficient for node implementation.
Gas Optimization Tips
For Users
- Time your transactions: Gas fees are typically lowest during weekends and late night UTC. Monitor gas trackers to find low-fee windows.
- Set appropriate gas limits: Most wallets estimate gas limits automatically. Avoid setting excessively high limits — while unused gas is refunded, a high limit can signal to validators that your transaction is complex.
- Use EIP-1559 transactions: Set a reasonable max fee and let the base fee adjust. The protocol refunds the difference between your max fee and the actual price.
- Consider Layer 2 solutions: For frequent transactions, L2 networks like Arbitrum and Optimism offer fees that are 10-100x cheaper than Ethereum mainnet.
For Developers
- Minimize storage writes: Each SSTORE costs 20,000 gas for new slots. Pack multiple values into a single
uint256when possible.
// Expensive: 3 storage slots (60,000 gas for new writes)
uint256 public a;
uint256 public b;
uint256 public c;
// Cheaper: 1 storage slot (20,000 gas for new write)
// Pack three uint80 values into one uint256
uint256 public packed; // a | (b << 80) | (c << 160)- Use calldata instead of memory for function parameters:
// More gas (copies data to memory)
function process(uint256[] memory data) external { ... }
// Less gas (reads directly from calldata)
function process(uint256[] calldata data) external { ... }- Short-circuit conditions: Place the most likely condition first in
requirechains. - Use events instead of storage for historical data: Emitting an event (LOG) is much cheaper than writing to storage (SSTORE).
- Batch operations: Combine multiple operations into a single transaction using multicall patterns.
Gas on Layer 2
Layer 2 solutions like Arbitrum, Optimism, and Base process transactions off the main Ethereum chain and post compressed data back to L1. This dramatically reduces gas costs:
| Network | Simple Transfer Cost | Compared to L1 |
|---|---|---|
| Ethereum L1 | ~$1-5 | Baseline |
| Arbitrum | ~$0.01-0.10 | ~50-100x cheaper |
| Optimism | ~$0.01-0.10 | ~50-100x cheaper |
| Base | ~$0.001-0.01 | ~100-500x cheaper |
L2 fees still include a small L1 component (for posting data to Ethereum) and an L2 execution fee. The L1 component fluctuates with Ethereum mainnet gas prices.
Frequently Asked Questions
What happens if my transaction runs out of gas?
The transaction reverts (fails), and all state changes are undone. However, you still pay for the gas that was consumed up to the point of failure. The remaining gas (gas limit minus gas used) is refunded to your wallet.
Why is my gas estimate sometimes wrong?
Gas estimates are based on simulating the transaction against the current state of the blockchain. If the state changes between when you estimate and when the transaction executes (for example, another user modifies the same contract), the actual gas consumption may differ.
Can gas fees ever be zero?
On Ethereum mainnet, no. Every transaction requires a minimum of 21,000 gas. However, some L2 networks and sidechains offer sponsored transactions where a third party pays the gas on your behalf, making the fee effectively zero for the user.
What is the gas limit for a block?
The target block size is 15 million gas, with a maximum of 30 million gas. If a block uses more than 15 million gas, the base fee increases for the next block. If it uses less, the base fee decreases.
How much ETH is burned through EIP-1559?
Since EIP-1559 launched in August 2021, billions of dollars worth of ETH have been burned. During periods of high network activity, more ETH is burned than is issued to validators, making ETH temporarily deflationary.
Calculate Your Gas Costs
Ready to estimate the cost of your next transaction? Use our free Gas Fee Calculator to compute the exact cost in Wei, Gwei, ETH, and USD for any gas limit and gas price.
Related Tools
- Gas Fee Calculator — Calculate Ethereum transaction costs instantly
- ETH Unit Converter — Convert between Wei, Gwei, and ETH
- Hex/Decimal Converter — Convert gas values between hex and decimal