Gas Fees Explained: Why Transactions Cost Money

Gas Fees Explained (2025): Why Transactions Cost Money — and How to Pay Less

Beginner → Intermediate Blockchain Basics • ~18–25 min read • Updated: 2025-11-07
TL;DR: Gas exists to price scarce block space and keep networks spam-resistant. On post-EIP-1559 Ethereum, each tx pays for gas used × (base fee + priority tip): the base fee is burned, the tip goes to the block proposer. After EIP-4844, many L2s post data as blobs with a separate “blob gas” market, slashing costs vs raw calldata. You lower fees by transacting off-peak, using L2s, batching actions, using permits to skip extra approvals, and routing sensitive txs over MEV-protect RPCs to avoid wasteful reverts and frontruns.

1) What is “gas” and why it exists

Blockchains are shared computers with limited capacity. Each block can only include so much computation and data. If the network allowed unlimited free transactions, spammers could flood the system, making it unusable. Gas is the meter that measures how much work your transaction asks validators to do (compute, storage reads/writes, signature checks, and so on). You pay for what you consume — and the network decides which transactions make it into the next block by sorting them primarily on price and occasionally on policy (e.g., size targets).

  • Gas unit: abstract measurement of work (e.g., a simple ETH transfer uses ~21,000 gas).
  • Price per gas: denominated in the native token’s subunit (gwei for ETH), multiplied by gas used yields the fee.
  • Spam resistance: fees discourage junk and allocate scarce block space to the highest-value uses at any moment.
Diagram — Why Gas Exists

Users

Send txs of varying complexity
Demand

Fee Market

Base fee + tips
Pricing

Validators

Choose txs for block
Supply

Block

Limited capacity
Inclusion

Primer: Ethereum.org — Gas & Fees

2) How EIP-1559 changed Ethereum’s fee market

Before EIP-1559 (August 2021), Ethereum used a simple first-price auction: users set a single gas price and competed head-to-head. Fees were volatile and hard to estimate. EIP-1559 introduced base fee + priority tip (two-dimensional bidding) and a mechanism to auto-adjust the base fee each block depending on demand.

  • Base fee: algorithmic, rises if blocks are above target size and falls if below; it is burned, removing ETH from circulation.
  • Priority tip: what you pay proposers/validators to prioritize your transaction over others.
  • Max fee: the most you’re willing to pay; unused headroom is automatically refunded.
Effect: More predictable fees and a smoother bidding experience. You no longer need to guess a single exact price — your wallet suggests a tip, and the protocol’s base fee handles the rest. The burn aligns incentives by making spam and congestion costly.

Spec: EIP-1559

3) Fee math: maxFee, priority tip, refunds (with examples)

On post-1559 Ethereum, the amount you actually pay for inclusion is:

Total Fee Paid = gasUsed × (baseFeePerGas + effectivePriorityFeePerGas)
effectivePriorityFeePerGas = min(maxPriorityFeePerGas, maxFeePerGas − baseFeePerGas)

You can think of maxFeePerGas as a safety ceiling. If the base fee is lower than your max, you get the difference back. The only non-refunded piece is what you really spend: gas used × (actual base fee + actual priority tip).

Example A — Simple transfer

gasUsed = 21,000
baseFeePerGas = 20 gwei
maxPriorityFeePerGas = 2 gwei
maxFeePerGas = 40 gwei

effectivePriorityFee = min(2, 40 − 20) = 2 gwei
Total = 21,000 × (20 + 2) = 462,000 gwei = 0.000462 ETH

Example B — Over-provisioned maxFee (refunds)

gasUsed = 100,000
baseFeePerGas (at inclusion) = 15 gwei
maxPriorityFeePerGas = 1.5 gwei
maxFeePerGas = 60 gwei

effectivePriorityFee = min(1.5, 60 − 15) = 1.5 gwei
Paid = 100,000 × (15 + 1.5) = 1,650,000 gwei = 0.00165 ETH
Refund = 100,000 × (60 − (15 + 1.5)) = 4,350,000 gwei (unused headroom)
Failed tx still costs gas: If a transaction reverts, you pay for the computation until the revert. Simulate beforehand to avoid “fee burn with nothing to show.”

4) Gas limit vs gas used, reverts & out-of-gas

  • Gas limit: the maximum you allow your tx to consume — set by your wallet as a safe cap.
  • Gas used: what the EVM actually consumed. You pay for this (modulo refunds, see below).
  • Revert: logic fails; you pay for work done up to the revert point.
  • Out-of-gas: the EVM halts due to insufficient gas; you typically lose the entire gas limit.
Refund changes: Gas refund mechanics changed with EIP-3529, which reduced gas refunds for clearing storage to prevent “gas token” abuse. Don’t rely on old gas-token strategies.

References: EIP-2929 (cold access cost), EIP-2930 (access lists).

5) Inside the EVM: what costs gas (SSTORE, calldata, hashing…)

Gas isn’t arbitrary — the Yellow Paper defines a cost schedule so resource-heavy operations charge more. Here are common “gas sinks” you’ll encounter:

OperationWhy it’s costlyDeveloper tip
SSTORE (write storage)Durable state write replicated on all nodesPack data, avoid unnecessary writes, use events or memory when possible
Calldata bytesEach byte posted to chain increases DA costCompress off-chain, use blobs on L2 post-4844 where available
HASH (KECCAK)Compute cost grows with input sizeHash once and reuse where possible
LoopsLinear growth with iterationsUse mappings, avoid unbounded loops
Signature checksECDSA verification costBatch verify off-chain when feasible
Access lists (EIP-2930): You can pre-declare which storage slots and addresses you’ll touch; this can save gas for “cold” accesses by making them “warm” and cheaper during execution.

Spec: Ethereum Yellow Paper (technical reference)

6) L2 fee anatomy: execution + data availability (+ blobs post-4844)

Layer-2 rollups (Optimistic and ZK) execute your transactions off-chain but inherit Ethereum security by posting data and/or proofs to L1. Your L2 fee typically has two components:

  • Execution fee: charged by the L2 sequencer for running your tx on its EVM (or ZK VM).
  • Data availability (DA) fee: pays to publish your tx data to Ethereum so others can reconstruct state.

After EIP-4844 (proto-danksharding), rollups can post data in blobs — large, ephemeral data chunks priced by a separate blob-gas market — instead of raw calldata. Blob gas is designed to be cheaper and more scalable, dramatically lowering the DA component for many L2s.

Diagram — L2 Fee Components (Post-EIP-4844)

Your Tx

Swap / Mint / Transfer
L2 app

L2 Sequencer

Executes & batches
Execution fee

Blob Posting

Data to L1 as blobs
Blob gas (cheap)

Ethereum L1

Data available to all
Security

References: EIP-4844 (Proto-Danksharding), Optimism Docs, Arbitrum Docs, ZK Rollup learning.

7) Strategies to save: off-peak windows, batching, permits, simulation

Time your transactions
  • Use a tracker to spot off-peak base fees (nights/weekends vary by region and market conditions).
  • Non-urgent mints, approvals, or NFT listings can wait for calmer blocks.

Tool: Etherscan Gas Tracker

Use L2 for routine activity
  • Swaps, games, smaller mints: L2 is typically cents vs dollars on L1.
  • Bridge only when needed (and compare on-ramps; sometimes direct L2 on-ramp is cheaper).
Batch or combine actions
  • Some dApps offer multicall/batching to share overhead across actions.
  • For ERC-20 approvals, consider EIP-2612 permit signatures to skip a separate on-chain “approve.”

Specs: EIP-2612 (Permit)

Simulate before sending
  • Many wallets and explorers simulate txs to detect reverts.
  • Failed txs still burn gas; simulation prevents “fee burn for nothing.”
Speed-up vs Cancel: If a tx is stuck, you can replace it using the same nonce with higher fee (speed-up) or a 0-ETH self-transfer (cancel). Your wallet likely has buttons for this; ensure the replacement is attractive enough for inclusion.

8) MEV & the mempool: when private orderflow helps

MEV (Maximal Extractable Value) is profit captured by reordering/inserting transactions in a block. In public mempools, attackers can see your swap coming and sandwich it (buy before you, sell after), making you pay more or get worse prices. For sensitive trades and mints, consider MEV-protect RPCs that keep your tx out of the public mempool and deliver it directly to builders/validators.

Diagram — MEV-Protected Routing

Your Wallet

Sign locally
No public mempool

Protect RPC

Bundles privately
Builder relay

Validator

Includes in block
No sandwich

Learn more: Flashbots Protect, MEV Blocker, Ethereum.org — MEV.

9) Case studies: transfers, swaps, NFT mints, bridging, L2 vs L1

Case 1 — Simple ETH transfer on L1

Scenario: Alice sends Bob 0.5 ETH. The EVM does minimal work (21,000 gas). If the base fee is 18 gwei with a 1.5 gwei tip:

gasUsed = 21,000
Total = 21,000 × (18 + 1.5) = 409,500 gwei = 0.0004095 ETH

Tip: This is the cheapest kind of transaction. If it’s not urgent, try off-peak windows to trim the base fee further.

Case 2 — ERC-20 approval + swap

Scenario: You approve a DEX to spend your USDC, then swap USDC→ETH.

  • Two transactions on L1: an approve (often ~45–65k gas) and the swap (varies, e.g., 120–200k+ depending on routing).
  • On L2, fees for both could be cents, especially post-4844.
  • Where supported, use EIP-2612 permit to skip the on-chain approve and save one transaction.

Case 3 — NFT mint (hot drop with surge)

Scenario: A hyped mint drives mempool congestion. Base fee can double quickly.

  • Set a reasonable tip; don’t panic-bid a huge tip unless the dApp requires it. Your wallet’s “aggressive” preset can help.
  • Consider L2 versions of the mint if available; the DA cost via blobs is usually far lower than raw calldata on L1.
  • Always simulate if possible — failed mints in rushes are expensive.

Case 4 — Bridging to an L2

Scenario: You bridge funds to an L2 for cheaper activity.

  • One L1 transaction (bridge deposit) + destination execution costs. If L1 is busy, deposit costs more.
  • Compare native on-ramps to the L2 (fiat→L2) vs bridging from L1. Sometimes direct is cheaper and faster.
  • On some rollups, withdrawals have a delay (Optimistic proofs). If timing matters, use instant liquidity bridges (with a fee premium).

Case 5 — L2 vs L1 swap baseline

NetworkBaseline simple swap fee*When L1 is busyNotes
Ethereum L1Often $5–$30+Spikes to $50+ in extremesMost secure, but pricey at peak
Optimism/Arbitrum/BaseOften $0.05–$0.50Rises if L1 DA price rises, still cheaperPost-4844 blobs cut DA cost
ZK rollupsOften $0.05–$0.60Proof/DA costs varyGreat for frequent small txs

*Illustrative only; varies with markets. Always check current trackers.

10) Myths & gotchas

  • “Validators set the base fee.” False — the base fee is algorithmic (EIP-1559). Validators earn your tip, not the base.
  • “Higher gas limit means higher cost.” Not directly. You pay for gas used, except when you run out of gas (then you lose the limit).
  • “Gas tokens still work.” Mostly obsolete after EIP-3529 reduced refunds.
  • “Throw more tip to fix a broken tx.” Tips improve priority, but can’t fix logical reverts (wrong params, too-tight slippage).
  • “L2 fees are independent from L1.” Not fully — DA costs still reference L1 pricing, but blobs reduce sensitivity.

11) Your gas-saving toolbox

L2 Docs: OptimismArbitrumBasezkSync

12) Quick FAQ & mini calculator

How do I pick maxFee and maxPriorityFee?

For non-urgent txs, wallets’ “market” presets are fine. If urgent, increase priority a bit. Avoid absurdly high maxFee unless you understand refunds; it won’t overcharge you, but can confuse budgeting.

Will I pay more on a higher gas limit?

No. You pay for gas used, not the limit — except in out-of-gas failures where you lose the whole limit. Keep the suggested limit unless you’re doing something unusual the wallet can’t estimate.

Mini calculator

# Replace with current numbers
gasUsed = 120000
baseFee = 14      # gwei
priority = 1.5    # gwei

totalETH = gasUsed * (baseFee + priority) / 1e9
print(totalETH, "ETH")
# For USD, multiply by spot ETHUSD
Reminder: Even if the base fee drops while your tx is pending, you get refunds automatically — the protocol handles it.

13) Further learning resources (external)

Next, make fees almost a non-issue: set up L2 flow, MEV-protect RPCs, and learn to spot off-peak windows automatically.

Next: Gas-Fee Engineering in 2025 →