Gas is a fundamental component of the Ethereum network. It powers operations, much like a car needs fuel to run.
Prerequisites
To better understand this guide, it is recommended you have a basic familiarity with Ethereum transactions and the Ethereum Virtual Machine (EVM).
What is Gas?
Gas is the unit that measures the amount of computational effort required to execute specific operations on the Ethereum network.
Since every Ethereum transaction requires computational resources, a fee must be paid for these resources. This payment mechanism ensures the Ethereum network remains secure against spam attacks and is not bogged down by infinite computational loops. The payment for computation is made in the form of gas fees.
Gas fees are the total amount of gas used to perform an operation, multiplied by the cost per unit of gas. These fees are paid regardless of whether the transaction succeeds or fails.
Gas fees must be paid in Ethereum's native currency, Ether (ETH). The price of gas is typically quoted in gwei, which is a denomination of ETH. One gwei equals one-billionth of an ETH (0.000000001 ETH or 10⁻⁹ ETH).
For example, instead of saying your gas costs 0.000000001 Ether, you can say it costs 1 gwei.
The word "gwei" is a portmanteau of "giga-wei," meaning "a billion wei." One gwei equals one billion wei. "Wei" (named after Wei Dai, creator of b-money), is the smallest unit of ETH.
How are Gas Fees Calculated?
When you submit a transaction, you can specify the maximum amount you are willing to pay for its execution. By offering a certain gas price, you are bidding for your transaction to be included in the next block. If your bid is too low, validators are less likely to select your transaction, meaning it might be executed late or not at all. If you bid too high, you may waste ETH. So, how do you know what to pay?
The total gas fee you pay consists of two parts: a base fee and a priority fee (tip).
The base fee is set by the protocol—you must pay at least this amount for your transaction to be considered valid. The priority fee is a tip you add to the base fee to make your transaction attractive to validators, encouraging them to include it in the next block.
A transaction that pays only the base fee is technically valid but is unlikely to be included because it doesn't incentivize validators to choose it over others. The "correct" priority fee is determined by network demand at the time you submit your transaction. If demand is high, you may need to increase your priority fee; otherwise, you might pay less.
For example, let's say Jordan needs to pay 1 ETH to Taylor. An ETH transfer requires 21,000 units of gas, the base fee is 10 gwei, and Jordan adds a tip of 2 gwei.
The total fee would be calculated as:
units of gas used * (base fee + priority fee)
21,000 * (10 + 2) = 252,000 gwei (0.000252 ETH).
When Jordan sends the money, 1.000252 ETH will be deducted from Jordan's account. Taylor will be credited 1.0000 ETH. The validator receives a tip of 0.000042 ETH. The base fee of 0.00021 ETH is burned.
Base Fee
Each block has a base fee that acts as a reserve price. To be eligible for inclusion in a block, the offered gas price must be at least the base fee. The base fee is calculated independently of the current block and is determined by the preceding blocks, making transaction fees more predictable for users. When a block is created, the base fee is "burned," permanently removing it from circulation.
The base fee is calculated by a formula that compares the size of the previous block (the amount of gas used for all transactions) with the target size. The base fee will increase by a maximum of 12.5% per block if the target block size is exceeded. Economically, this exponential growth makes it unsustainable to maintain oversized blocks indefinitely.
| Block Number | Gas Used | Fee Increase | Current Base Fee |
|---|---|---|---|
| 1 | 15 M | 0% | 100 gwei |
| 2 | 30M | 0% | 100 gwei |
| 3 | 30 M | 12.5% | 112.5 gwei |
| 4 | 30 M | 12.5% | 126.6 gwei |
| 5 | 30 M | 12.5% | 142.4 gwei |
| 6 | 30 M | 12.5% | 160.2 gwei |
| 7 | 30 M | 12.5% | 180.2 gwei |
| 8 | 30 M | 12.5% | 202.7 gwei |
Based on the table above—to create a transaction for block number 9, a wallet can confidently inform the user that the maximum base fee to be added to the next block is current base fee * 112.5% or 202.8 gwei * 112.5% = 228.1 gwei.
It's also important to note that prolonged spikes of full blocks are unlikely due to the rapid rate at which the base fee increases.
Priority Fee (Tip)
The priority fee (tip) incentivizes validators to include a transaction in a block. Without tips, validators would find it economically viable to mine empty blocks, as they would receive the same block reward. Small tips provide little incentive for validators to include a transaction. To have a transaction prioritized over others in the same block, a higher tip can be added to outbid competing transactions.
Max Fee
When executing a transaction on the network, users can specify a maximum limit they are willing to pay for the transaction to be processed. This optional parameter is known as maxFeePerGas. For a transaction to be executed, the max fee must exceed the sum of the base fee and the tip. The difference between the max fee and the sum of the base fee and tip is refunded to the transaction sender.
Block Sizes
Each block targets a size of 15 million gas, but blocks can adapt to network demands up to a limit of 30 million gas (twice the target block size). The protocol achieves an equilibrium average block size of 15 million through a tâtonnement process (groping towards equilibrium). This means that if the block size is greater than the target block size, the protocol will increase the base fee for the next block. Conversely, the protocol will decrease the base fee if the block size is smaller than the target. The amount by which the base fee is adjusted is proportional to how far the current block size is from the target.
Calculating Gas Fees in Practice
You can explicitly state how much you are willing to pay for your transaction to be executed. However, most wallet providers automatically set recommended transaction fees (base fee + recommended priority fee) to reduce complexity for their users.
👉 Explore tools for calculating real-time gas fees
Why Do Gas Fees Exist?
In short, gas fees help secure the Ethereum network. By requiring a fee for every computation executed on the network, we prevent malicious actors from spamming it. To avoid accidental or hostile infinite loops or other computational waste in code, each transaction must limit the number of computational steps in code execution. The fundamental unit of computation is "gas."
Although a transaction includes a gas limit, any unused gas in a transaction is returned to the user (e.g., Max fee - (base fee + tip) is refunded).
What is the Gas Limit?
The gas limit refers to the maximum amount of gas you are willing to consume on a transaction. More complex transactions involving smart contracts require more computational work and thus a higher gas limit than a simple payment. A standard ETH transfer requires a gas limit of 21,000 units.
For example, if you set your gas limit to 50,000 for a simple ETH transfer, the EVM will consume 21,000, and you will get back the remaining 29,000. However, if you set too low an amount, say a gas limit of 20,000 for a simple ETH transfer, the EVM will consume your 20,000 units of gas attempting to fulfill the transaction, but it will not complete. The EVM then reverts any changes, but since the validator has already done work worth 20,000 gas units, that gas is consumed.
Why Can Gas Fees Get So High?
High gas fees are a product of Ethereum's popularity. If demand is too high, users must offer higher tips to try and outbid other users' transactions. A higher tip increases the likelihood that your transaction will be included in the next block. Furthermore, more complex smart contract applications perform many operations to fulfill their functions, causing them to consume a lot of gas.
Initiatives to Reduce Gas Costs
Ethereum's scaling upgrades are ultimately expected to resolve some gas fee issues and will allow the platform to process thousands of transactions per second at a global scale.
Layer 2 scaling is a primary initiative to significantly improve gas costs, user experience, and scalability.
Tracking Gas Fees
If you want to monitor gas prices to send your ETH at a lower cost, you can use various gas tracker tools and estimators available online. These resources provide real-time data on network congestion and recommended fee prices to help you optimize your transaction costs.
Frequently Asked Questions
What happens if I set my gas fee too low?
If you set your gas fee (particularly the priority fee) too low relative to current network demand, validators will prioritize other transactions with higher tips. Your transaction may remain in the mempool for a long time, potentially for hours or even days, before it is eventually included in a block or drops out. In some cases, it may never be processed.
Can I get a refund for unused gas?
Yes. You specify a gas limit for your transaction, which is the maximum amount of gas you are willing to consume. The EVM will only charge you for the gas actually used to execute your transaction. Any unused gas from your limit is refunded to your wallet. However, if your transaction fails, you are still charged for all the computational work that was performed up to the point of failure.
What is the difference between gas limit and gas price?
The gas limit is the maximum amount of computational work you authorize for a transaction. The gas price is the amount of ETH you are willing to pay per unit of gas. Your total fee is calculated as Gas Used * (Base Fee + Priority Fee). The limit protects you from bugs that could cause a transaction to use a catastrophic amount of gas, while the price determines how quickly it gets processed.
Why are some transactions more expensive than others?
Simple ETH transfers between wallets have a fixed cost (21,000 gas). Interactions with smart contracts are more expensive because they execute complex code on the EVM. The cost depends on the number and type of computational steps (opcodes) the smart contract performs. Functions that modify storage on the blockchain are far more expensive than those that simply read data.
How can I reduce my gas fees?
To reduce fees, you can try transacting during periods of low network congestion (often weekends or late at night UTC). You can also adjust your priority fee based on how quickly you need the transaction confirmed. For frequent smart contract interactions, consider using Layer 2 scaling solutions, which batch transactions off the main Ethereum chain, dramatically reducing costs.