Gas is Ethereum's unit for measuring the computational and storage work requested by a transaction. A simple ETH transfer uses a predictable amount, while a contract interaction may perform many checks, storage updates, and nested calls. Separating work units from ETH prices lets the protocol account for resource use even as the market value of ETH changes.
A gas fee is therefore not a flat service charge and gas is not a separate asset. The final cost combines how much work execution consumes with the price offered for each gas unit. Users also specify a ceiling on gas consumption, protecting their accounts from transactions that would otherwise execute without a defined resource bound.
What you will learn
- Distinguish gas units, gas price, gas limit, and total transaction fee
- Explain the roles of the base fee and priority fee
- Estimate maximum cost and understand refunds for unused gas
- Recognize why failed and complex transactions can still be expensive
Measuring work before pricing it
Ethereum assigns gas costs to operations according to their demands on network resources. Reading data, performing arithmetic, writing persistent storage, and creating contracts have different costs. The Ethereum Virtual Machine tracks gas as instructions execute. This accounting prevents a transaction from demanding endless computation from every validating node.
Gas used measures quantity of work, while a fee per gas unit assigns an ETH price to that work. Keeping these concepts separate is essential. Two identical token transfers should consume similar gas, yet one may cost more ETH because it was submitted when blockspace demand and offered priority fees were higher.
Base fee, priority fee, and maximum fee
Each Ethereum block has a protocol-calculated base fee per gas that rises or falls according to recent block usage. The sender must cover that base fee, and the corresponding ETH is burned. A sender can also offer a priority fee, often called a tip, to compensate the block proposer and improve inclusion incentives.
Modern fee settings commonly include a maximum fee per gas and a maximum priority fee per gas. The maximum caps what the sender is willing to pay. The effective price cannot exceed that cap, and any unused difference is not charged. Wallets estimate these values, but users should still inspect total cost and urgency before signing.
Calculating a transaction's cost
The actual execution fee is gas used multiplied by the effective gas price. The gas limit is not the expected gas usage; it is the maximum the transaction may consume. If execution finishes below the limit, the sender pays only for gas actually used. If it exhausts the limit, execution fails and consumed gas remains charged.
Some transactions also transfer ETH as their intended value. Wallets may display transaction value and network fee separately, so a user should add them when checking the account's required balance. On rollups, the total often includes layer-2 execution plus a charge connected to publishing transaction data to Ethereum, making the breakdown different from mainnet.
Why transactions cost different amounts
A plain ETH transfer is relatively simple, while a decentralized exchange route may call several contracts, update multiple storage locations, and move several tokens. Complexity raises gas used. Creating new storage generally costs more than reading existing values, and the precise path through contract logic can change consumption even within the same application.
Congestion changes the price per unit rather than the contract's inherent instruction count. When many users compete for limited blockspace, the base fee can rise and users may offer larger tips for faster inclusion. Waiting can reduce the fee price when activity falls, but urgent transactions such as avoiding liquidation may not have that flexibility.
Failure, estimation, and user controls
A failed transaction can still cost ETH because nodes performed real computation before encountering a revert, expired deadline, changed price, or exhausted gas limit. Preflight simulation helps wallets detect many failures but cannot guarantee the same result after pending transactions alter state. A successful simulation is evidence, not certainty.
Users should verify the network, transaction purpose, estimated total fee, gas limit, and any application's slippage or deadline controls. Manually lowering the gas limit can cause avoidable failure; lowering the priority fee may simply delay inclusion. Replacing or canceling a pending transaction generally means submitting another transaction with the same account sequence number and a competitive fee.
Common misconceptions
“Gas is a second Ethereum token that must be purchased.”
Gas measures execution work; users pay the resulting fee in ETH rather than acquiring a separate gas asset.
“The gas limit is the exact fee a transaction will charge.”
The gas limit caps execution units, while actual cost depends on gas used and the effective price per unit.
“A failed transaction should be free because no state change occurred.”
Validators and nodes still executed instructions before failure, so consumed gas remains chargeable even when state changes revert.
Risks and limitations
- Setting an inadequate gas limit can make execution fail while still charging for the work performed.
- Rapid fee changes can delay a low-priced transaction or make urgent inclusion substantially more expensive than expected.
- Malicious interfaces can disguise a dangerous contract action behind a plausible fee estimate; a reasonable fee does not make the call safe.
- Repeated replacements or failed attempts can compound costs, particularly during congestion or fast-changing application state.
Key takeaways
- Gas measures computational work; ETH pays the fee for that work.
- Actual execution cost equals gas used multiplied by effective gas price.
- The base fee is protocol-calculated and burned, while the priority fee rewards inclusion.
- Complex contract paths consume more gas, while congestion mainly changes gas price.
- Reverts undo state changes but do not refund gas already consumed by execution.
Primary and further reading
Test your understanding
Score at least 2 out of 3 to complete this lesson. Explanations appear after you submit.