Gas Fees

Gas Fees

Definition: The fee paid to execute a transaction or smart contract operation on a blockchain, compensating the network for the computation and storage it requires.

How It Works

  • Every operation, a transfer, a contract call, a storage write, costs a fixed amount of “gas,” a unit measuring computational effort
  • Total fee = gas used x gas price, so both how complex the operation is and how congested the network is affect the final cost
  • Users set a gas price (or, under EIP-1559, a tip on top of a network-determined base fee) they’re willing to pay; higher bids get transactions processed faster during congestion
  • A “gas limit” caps how much gas a transaction is allowed to consume, protecting the sender from an infinite loop or runaway contract draining their wallet
  • If a transaction runs out of gas mid-execution, it reverts, changes are rolled back, but the gas already consumed up to that point is still paid, it isn’t refunded
  • Fees go to whoever proposes the block, miners under Proof of Work or validators under Proof of Stake
  • Different operations cost different fixed gas amounts by design, e.g. writing to storage costs far more gas than simple arithmetic, to reflect the real resource cost to the network

Gas Components (EIP-1559 model)

TermMeaning
Gas limitMaximum gas the sender authorizes this transaction to use
Gas usedActual gas consumed by execution, at most the gas limit
Base feeNetwork-set minimum fee per gas, adjusts automatically each block based on demand, and is burned rather than paid to the validator
Priority fee (tip)Extra amount per gas paid directly to the validator to incentivize faster inclusion
Max feeThe sender’s cap on base fee plus tip combined, unused amount is refunded
NonceA per-account transaction counter, ensures transactions execute in order and prevents replay

Fee Market Models

  • Legacy first-price auction: senders bid a gas price directly, highest bidders get included first, prone to overpaying since everyone guesses at the market rate
  • EIP-1559 (Ethereum, since 2021): a base fee is set algorithmically per block and burned, senders add a small tip, base fee rises when blocks are full and falls when they’re not
  • Fixed or negligible fees: some chains (e.g. Solana) target very low, fairly stable fees under normal load through higher throughput design, though local fee spikes still occur during demand surges
  • Gas abstraction (account abstraction): lets a third party sponsor a user’s gas fee, or lets fees be paid in a token other than the chain’s native asset, hiding gas mechanics from the end user
  • Priority gas auctions: during high-value opportunities (e.g. arbitrage, liquidations), bots competitively bid up tips against each other, briefly spiking fees network-wide

Gas Optimization Techniques

  • Minimize on-chain storage writes, storage (SSTORE) is one of the most expensive operations, cache values in memory where possible
  • Batch multiple operations into a single transaction instead of separate calls, each transaction carries its own fixed 21,000 gas base cost
  • Use calldata instead of memory for function arguments that don’t need to be modified, calldata is cheaper to access
  • Avoid unbounded loops over arrays that can grow over time, a big enough array can make a function exceed the block gas limit and become permanently uncallable
  • Clear unused storage slots when possible, some networks offer a partial gas refund for freeing up state
  • Prefer fixed-size types and packed struct layouts over dynamically sized ones, the EVM charges by storage slot, not by logical field

Under the Hood

Worked example: computing a real gas cost

  • Given: a simple ETH transfer costs a fixed 21,000 gas, the current base fee is 30 gwei, the sender adds a 2 gwei tip
  • Step: total fee per gas = base fee + tip = 30 + 2 = 32 gwei
  • Step: total fee = 21,000 gas x 32 gwei = 672,000 gwei
  • Step: convert to ETH, 1 ETH = 1,000,000,000 gwei, so 672,000 / 1,000,000,000 = 0.000672 ETH
  • Answer: at 3,000/ETH,that′s0.000672x3,000=about3,000/ETH, that's 0.000672 x 3,000 = about 2.02 for the transfer

Worked example: congestion spike

  • Given: the same transfer during a period of network congestion, base fee has risen to 200 gwei and the sender adds a 5 gwei tip to compete
  • Step: total fee per gas = 205 gwei, total fee = 21,000 x 205 = 4,305,000 gwei = 0.004305 ETH
  • Answer: at 3,000/ETH,that′sabout3,000/ETH, that's about 12.92, roughly 6x the calm-network cost, for an identical transaction, purely from demand

Worked example: a complex contract call

  • Given: a token swap through a DEX router typically consumes around 150,000 gas, base fee is 40 gwei, tip is 2 gwei
  • Step: total fee per gas = 42 gwei, total fee = 150,000 x 42 = 6,300,000 gwei = 0.0063 ETH
  • Answer: at 3,000/ETH,that′sabout3,000/ETH, that's about 18.90, roughly 7x the cost of the simple transfer above, reflecting the extra computation a swap requires versus a plain transfer

Why It Matters

  • Directly shapes what’s practical to build on-chain, expensive gas makes frequent small transactions impractical, which is why Layer 2 networks exist
  • Acts as a spam deterrent, without a cost per operation, the network could be flooded with meaningless transactions for free
  • Creates a real economic incentive for validators to include and correctly execute transactions
  • Under EIP-1559, burning the base fee ties network usage directly to the base asset’s supply, heavy usage can make the asset net deflationary
  • Makes fee estimation a real user-experience problem, wallets have to predict a fair bid before submission, guess wrong and a transaction either overpays or stalls for hours

Common Pitfalls

  • Underestimating gas costs when designing a Smart Contract, inefficient contract code (unnecessary storage writes, loops over unbounded arrays) can make routine operations prohibitively expensive for every user who calls it
  • Not accounting for gas price volatility, a transaction that was cheap yesterday can be expensive today during network congestion
  • Setting a gas limit too low, the transaction reverts once it runs out mid-execution, and the gas consumed so far is still lost
  • Setting a max fee far above the actual base fee “just to be safe,” the unused portion is refunded, but a max fee set below the base fee causes the transaction to simply not get included at all
  • Forgetting that a failed or reverted transaction still costs gas, “it didn’t work so it was free” is a common and costly misconception
  • Confusing gas price (per-unit cost) with gas fee (total cost), a low gas price on a very complex contract call can still add up to a large total fee
  • Submitting a replacement transaction with the same nonce but a lower fee, most networks require a strictly higher fee to replace a pending transaction, otherwise it’s simply ignored and the original stays stuck

Comparison

Ethereum L1 (EIP-1559)Ethereum L2 rollupBitcoinHigh-throughput L1 (e.g. Solana)
Fee modelBase fee (burned) + tipSmall L2 fee + share of L1 batch costFee per byte, first-price auctionSmall, mostly fixed per-transaction fee
Typical costCents to tens of dollars, congestion-dependentFractions of a cent to a few centsCents to tens of dollars, congestion-dependentFractions of a cent
VolatilityHigh during congestionLow, smoothed across batched usersHigh during congestionGenerally low
What you’re paying forGlobal L1 computation and storageL2 execution plus amortized L1 settlementBlock space, measured in bytesExecution on a higher-throughput chain
Who receives the feeValidator (tip), base fee burnedL2 sequencer/validatorMinerValidator

Example

During periods of high Ethereum network demand, such as a popular NFT mint, a simple token transfer’s gas fee can spike from a few cents to tens of dollars, purely because many users are competing for the same limited block space. Layer 2 rollups like Arbitrum exist largely to give users an alternative that stays cheap even when Ethereum L1 is congested.

FAQ

Do I pay gas for a failed transaction? Yes, gas is paid for computation actually performed, whether or not the transaction ultimately succeeds or reverts.

Does a higher gas price guarantee faster inclusion? Not guaranteed, but it strongly improves the odds, validators are economically motivated to prioritize higher-paying transactions first.

Can gas fees ever be zero? On most public chains, no, though sponsored transactions (gas abstraction) can make a fee zero from the end user’s perspective while someone else still pays it.

Why did my transaction get stuck pending for hours? Its fee bid was likely below what the network needed at that moment, either wait for demand to drop or submit a replacement with a higher fee and the same nonce.

Dig deeper