Gas is the unit of measurement for computational work on the Ethereum network. Every operation performed by the Ethereum Virtual Machine (EVM)—from a simple addition to a complex smart contract execution—has a defined gas cost. Users pay gas fees to compensate validators for the computational resources required to process their transactions. Gas serves as both a pricing mechanism for network resources and a protection mechanism against abuse (such as infinite loops or denial-of-service attacks).

Why Gas Exists

Unlike Bitcoin, which primarily processes value transfers, Ethereum is a general-purpose computation platform. Smart contracts can execute arbitrary logic, and without a metering system, a single transaction could consume unlimited computational resources, stalling the entire network.

Gas solves this by assigning a cost to every operation:

  • Simple arithmetic operations: 3-5 gas
  • Reading from storage: 2,100 gas (cold access) or 100 gas (warm access)
  • Writing to storage: 20,000 gas (new value) or 5,000 gas (updating existing value)
  • Simple ETH transfer: 21,000 gas (fixed)
  • ERC-20 token transfer: ~65,000 gas (varies by implementation)
  • Uniswap swap: ~150,000-300,000 gas

By requiring users to pay for computation, the protocol ensures that network resources are allocated efficiently through market pricing.

Gas Limit

The gas limit is the maximum amount of gas a user is willing to spend on a transaction. It serves as a safety cap: if the transaction requires more gas than the limit, it will revert and the user is charged only for the gas consumed up to that point.

Setting the gas limit correctly matters:

  • Too low: The transaction runs out of gas and reverts. The user loses the gas fee but the state change is rolled back.
  • Too high: No penalty. Unused gas is refunded. However, setting an extremely high limit can cause the transaction to be deprioritized or rejected by some nodes.
  • Just right: Wallets estimate gas limits by simulating the transaction against the current state. The estimate is typically padded by 20-30% to account for state changes between estimation and execution.

Pre-EIP-1559: The Auction Model

Before August 2021 (the London hard fork), Ethereum used a simple first-price auction for gas pricing. Users specified a single gasPrice, and block producers selected transactions offering the highest price. This model had significant problems:

  • Overpayment: Users routinely overpaid because they could not accurately predict what price was needed for inclusion.
  • Volatility: Gas prices would spike dramatically during periods of high demand, with prices swinging 10-100x within hours.
  • Poor UX: Users had to manually set gas prices or rely on estimators that were often wrong.

EIP-1559: The Current Fee Model

EIP-1559, implemented in the London hard fork, fundamentally restructured Ethereum's fee market. Instead of a single gas price, transactions specify two parameters:

Base Fee

The base fee is a per-gas price determined algorithmically by the protocol. It adjusts automatically based on network congestion:

  • If the previous block used more than 50% of its gas capacity, the base fee increases (up to 12.5% per block).
  • If the previous block used less than 50% of its gas capacity, the base fee decreases.

This mechanism creates a predictable pricing signal. Users can look at the current base fee and know approximately what they need to pay for inclusion. The base fee is burned (permanently removed from circulation), making ETH deflationary when network activity is high.

Priority Fee (Tip)

The priority fee (or tip) is an optional payment that goes directly to the block producer. It incentivizes validators to include your transaction ahead of others. During periods of normal congestion, a tip of 1-2 Gwei is typically sufficient. During extreme congestion (e.g., a popular NFT mint), tips can spike to hundreds of Gwei.

Max Fee

The maxFeePerGas is the absolute maximum the user is willing to pay per unit of gas. It must be at least equal to the current base fee plus the priority fee. If the base fee drops between submission and inclusion, the user pays less than the max—only the actual base fee plus the tip.

Fee Calculation

The effective fee per gas unit is:

effective_fee = min(maxFeePerGas, baseFee + maxPriorityFeePerGas)

The total transaction cost is:

total_cost = effective_fee × gas_used

Scenario Base Fee Max Priority Fee Max Fee Effective Fee Gas Used Total Cost
Simple Transfer 20 Gwei 2 Gwei 25 Gwei 22 Gwei 21,000 0.000462 ETH
Token Swap 20 Gwei 2 Gwei 25 Gwei 22 Gwei 200,000 0.0044 ETH
Complex DeFi 50 Gwei 5 Gwei 60 Gwei 55 Gwei 500,000 0.0275 ETH

Gas and Layer 2 Solutions

High gas costs on Ethereum mainnet (Layer 1) have driven significant activity to Layer 2 rollups—networks that process transactions off-chain and post compressed proofs or data back to Ethereum. Layer 2 solutions dramatically reduce per-transaction gas costs:

  • Optimistic rollups (Optimism, Arbitrum): Transactions cost approximately 10-50x less than equivalent L1 transactions.
  • ZK-rollups (zkSync, StarkNet, Scroll): Similar or greater cost reductions, with faster finality guarantees.

The introduction of EIP-4844 (Proto-Danksharding) in March 2024 further reduced L2 costs by providing a dedicated, cheaper data availability layer ("blob space") for rollup data. This reduced L2 transaction costs by an order of magnitude.

Strategies for Optimizing Gas Costs

  1. Time transactions during low-activity periods. Gas prices follow predictable patterns: lowest on weekends and during off-peak hours (early morning UTC). Gas trackers like Etherscan's Gas Tracker provide real-time and historical data.
  2. Use Layer 2 networks. For most DeFi activity, L2 rollups provide equivalent functionality at a fraction of the cost.
  3. Batch operations. Some protocols allow batching multiple operations into a single transaction, amortizing the base 21,000 gas overhead.
  4. Optimize smart contract code. For developers, gas optimization is a critical skill. Techniques include minimizing storage writes, using efficient data structures, and leveraging compiler optimizations.
  5. Set appropriate gas limits. Overly generous gas limits do not directly cost more (unused gas is refunded), but setting precise limits improves transaction handling.
Gas Units and Gwei: Gas costs are measured in gas units (dimensionless computation measures). Gas prices are denominated in Gwei (1 Gwei = 10−9 ETH = 0.000000001 ETH). A transaction consuming 21,000 gas at a price of 20 Gwei costs 21,000 × 20 = 420,000 Gwei = 0.00042 ETH.

Key Takeaways

  • Gas is a unit of computational work on Ethereum, metering every EVM operation and preventing abuse of network resources.
  • EIP-1559 replaced the first-price auction with a base fee (burned) plus priority fee (paid to validators), creating more predictable pricing.
  • The base fee adjusts algorithmically to target 50% block utilization, providing a reliable pricing signal for users.
  • Layer 2 rollups and EIP-4844 have dramatically reduced effective transaction costs, making Ethereum accessible for smaller transactions.

Related articles