A gas fee is the amount a user pays to have a transaction or smart contract call executed on a blockchain, calculated as the units of gas consumed multiplied by the price per unit. In smart contracts on Ethereum and other networks built on the EVM, gas measures computational and storage work, and the fee compensates the network for processing it while protecting the chain from spam and endless loops.
Gas separates two questions that are easy to confuse: how much work an operation requires and how much each unit of work costs at a given moment. The first is fixed by the code and the protocol rules; the second rises and falls with demand for block space.
How gas measures computation
Every instruction the virtual machine executes has a fixed gas cost set by the protocol. Adding two numbers costs a few units, reading a storage slot for the first time in a transaction costs about two thousand, and writing a new non-zero value to storage costs about twenty thousand units, because permanent state burdens every node forever. A transaction declares a gas limit, the maximum units it may consume, and execution stops when that budget runs out.
When a call runs out of gas, the state changes are reverted, but the gas already consumed is still charged. This rule makes failed transactions costly and is the reason wallets estimate gas before sending. Unused gas below the limit is not charged, so a generous limit is safe as long as the code does not fail.
Typical consumption on Ethereum varies widely with the operation, as the following rough ranges show.
| Operation | Typical gas used | Why it costs that much |
|---|---|---|
| Plain ether transfer | 21,000 | Fixed base cost of any transaction |
| Token transfer | About 35,000 to 65,000 | Two balance updates in contract storage |
| Token approval | About 45,000 | One allowance written to storage |
| Swap on an exchange contract | About 100,000 to 250,000 | Several contracts and storage writes |
| Contract deployment | Hundreds of thousands to millions | Bytecode stored permanently on-chain |
How the gas price is set
Since the EIP-1559 upgrade in 2021, the Ethereum gas price has two parts. The base fee is set by the protocol for each block and is burned, removing that ether from supply. The priority fee, or tip, goes to the validator who includes the transaction and rewards faster inclusion when blocks are busy.
The base fee follows a target block size of half the gas limit. When a block uses more than the target, the next base fee rises by up to 12.5 percent; when it uses less, the fee falls by up to the same amount. A sustained surge therefore doubles the base fee in roughly six full blocks, about a minute and a quarter. Prices are quoted in gwei, one billionth of an ether.
| Parameter | Who sets it | Effect |
|---|---|---|
| Gas limit | Sender or wallet | Caps the units the call may consume |
| Base fee | Protocol, per block | Burned; tracks demand for block space |
| Max priority fee | Sender | Tip offered to the block proposer |
| Max fee per gas | Sender | Ceiling on base fee plus tip combined |
| Effective gas price | Result at inclusion | Base fee plus actual tip, never above max fee |
The sender pays gas used times effective gas price, and any difference between the declared maximum and the actual price is never charged. Setting a high max fee per gas therefore protects a transaction against a rising base fee without overpaying in a calm market.
Gas fees on layer 2 networks and other chains
The gas concept appears across EVM-compatible chains, but the economics differ by network. On a rollup, the fee has an execution component for running the transaction on the layer 2 and a data component for publishing compressed transaction data to Ethereum. Since the 2024 introduction of blob space, a separate fee market for rollup data, these data costs have fallen sharply, and rollup transfers commonly cost a small fraction of a cent to a few cents.
| Network type | Fee components | Typical cost profile |
|---|---|---|
| Ethereum mainnet | Burned base fee plus validator tip | Highest; spikes during congestion |
| Optimistic or ZK rollup | Layer 2 execution plus layer 1 data | Low; tied to blob prices |
| Other EVM layer 1 chains | Native token gas under own rules | Usually low; set by local demand |
| Non-EVM chains | Compute units or fixed fees | Different metering, similar purpose |
Developers who write contracts for several networks should not assume identical costs. Opcode pricing, block limits and data fees vary, and a pattern that is cheap on a rollup can remain expensive on mainnet.
Reducing gas costs in practice
Users control the price they pay, while developers control the amount of gas their code consumes. Users save most by timing transactions outside peak hours and by moving routine activity to layer 2 networks. Developers apply gas optimization: fewer storage writes, packed variables, events instead of stored history and efficient loops.
| Symptom | Likely cause | Fix |
|---|---|---|
| Transaction pending for hours | Max fee below current base fee | Replace with a higher max fee |
| Failed transaction still charged | Revert or out-of-gas during execution | Simulate before sending |
| Unexpectedly high fee | Sent during a demand spike | Wait or use a layer 2 network |
| Contract call costs too much | Excess storage writes in the code | Refactor and cache values in memory |
Never hard-code gas assumptions into contract logic. Protocol upgrades have repriced opcodes several times, and code that forwards a fixed amount of gas to another contract has broken after such changes.
Misconceptions and security aspects
- Gas is not a token: it is a unit of work; the fee is paid in the network’s native currency, such as ether.
- A higher tip does not guarantee success: it speeds inclusion, but a call that reverts still costs gas.
- Gas price is public: transactions with visible tips in the public mempool can be reordered, which creates room for MEV and front-running.
- Gas limits protect the network: the block gas limit caps total work per block, which keeps the chain verifiable on ordinary hardware.
In simple terms
A gas fee works like the postage plus processing fee for a blockchain action. A simple payment is a light envelope and costs little; a complex action, such as trading through a program that touches several accounts, is a heavy parcel and costs more.
The price per unit of postage changes with traffic. When many people want their transactions processed at the same time, the price rises, and when the network is quiet it falls. The work stays the same; only the price of the work moves.
A practical example
A developer at a small game studio deploys a contract that issues in-game items as tokens. On Ethereum mainnet, a test mint uses about 90,000 gas; at a base fee of 20 gwei plus a 1 gwei tip, each mint costs about 0.0019 ether, which is too expensive for items players buy for a few cents.
The team rewrites the contract to pack several fields into one storage slot, which cuts consumption to about 55,000 gas, and deploys it on a rollup. There, each mint costs a fraction of a cent, and the studio settles items in batches to mainnet only when players withdraw them. The outcome is a game economy that remains affordable during busy periods.