What is Ethereum Gas? An Easy to Understand Guide

Ethereum Gas is the fuel behind Ethereum, an open-source and decentralized world computer used to create and execute smart contracts. Naturally, this leads to many follow up questions, such as why is fuel necessary to power Ethereum and who sets the gas fees? Below, we explore what Ethereum Gas is, why it’s necessary, and the implication of gas fees for the Ethereum ecosystem and its participants.   

What is Ethereum Gas? 

Ethereum Gas is a unit of Ether (ETH) used to measure the computer power needed to execute a task on the Ethereum network. Generally speaking, the more complex the action on the network, the more gas it will take to ensure execution. Gas is used to pay miners, the backbone to the Ethereum network, for their efforts since they provide the computational power necessary to complete actions on the network. Without gas fees there would be no incentive for a miner to use their computing power to execute smart contracts. 

Every action taking place on the network requires a certain amount of gas. For example, if you were to build a smart contract that pays insurance claims when weather in a certain region registers a certain amount of flooding, there would likely be gas fees associated with the actions of the contract. 

Below, we display the role of Ethereum gas in the execution of a simple transaction on the Ethereum network.

Diagram Explaining Ethereum Transaction
Pro Tip: Gas is Measured in gwei
Ethereum gas is measured in “gwei”, which is the smallest unit of ETH that can be transacted. This idea is similar to how the term “satoshi” is used to refer to the smallest unit of Bitcoin. One single ETH is made up of  1,000,000,000 gwei and conversely one single gwei is worth 0.000000001 ETH.

Ethereum Gas Limit vs. Ethereum Gas Price

To better understand the difference between some common terms used when discussing Ethereum Gas, let’s imagine you wanted to send one ETH to your friend as a college graduation gift (you’re very generous). Since this constitutes a transaction on the Ethereum network, you would have to pay a gas fee, denominated in Gwei, to ensure execution. Here’s how that fee is determined:

As a user of the Ethereum network, you are allowed to set your own gas price

Gas price is the recommended cost to ensure completion of your transaction.

Your gas price is denoted in price per unit, meaning the gas price isn’t the total gas fee. The gas price you select determines how quickly your transaction gets executed. Transactions with higher gas prices are generally executed faster and those with lower gas prices are executed slower. If you were in no rush for your friend to receive the ETH in his wallet, you could lower your gas price. On the flip side, if you wanted to ensure swift delivery, you might set a higher gas price.

Let’s imagine you decided on a gas price of 200 GWEI because you wanted fast execution. The next step in determining your total gas fee would be to determine your gas limit. 

Gas limit is the maximum units of gas you’re willing to spend on any given transaction.

Each action on the Ethereum network requires a certain number of gas units. Sending ETH from one wallet to another, as you would be attempting, typically requires 21,000 units of gas. More complex tasks require a higher number of gas units and therefore a higher gas limit as well. 

To calculate your total gas fee you would multiply your gas price by your gas limit. In your case, you would multiply 200 GWEI by 21,000 units of gas to get 4,200,000 Gwei or 0.0042 ETH. The miner, who is utilizing their computational power to process your transaction, would receive the 0.0042 ETH transaction fee.

Below, we provide a visualization of the components of gas and how the total gas for this specific transaction was calculated.

           

Gas Prices vs Fees Explained
Pro Tip: Beware of Exchange Related Fees
Keep in mind that if you’re executing transactions on an exchange, like buying or selling ETH, you’ll be subject to separate exchange specific fees that have nothing to do with the Ethereum network.

Unused Ethereum Gas and Failed Transactions

If I’m only charged for the gas used within an ethereum transaction, what happens to all the unused gas that isn’t charged? 

All unused gas is returned to the person who originated the transaction. This might occur when a person sets a gas limit beyond what’s needed for the transaction. For example, setting a gas limit of 100,000 when all you need to do is send one ETH from one wallet to another would result in a gas refund of approximately 79,000. That’s because as previously covered, simple transactions typically require a 21,000 gas limit.

Be aware that a transaction may fail to execute if it doesn’t have the necessary gas allotted to it. If a transaction fails to execute you would still have to pay gas fees. The reason behind this is that miners on the network still have to process your transaction up to the point where it fails, meaning they are still providing computational power to process your request to the network.

If I’m refunded excess gas, wouldn’t an optimal strategy be to set a high gas limit for transactions?

Not necessarily since each block that is added to the Ethereum network has a gas limit. A miner is only able to add transactions to a block provided the sum of the gas associated with each transaction is less than the gas limit of the block. Executing a transaction with an egregiously high gas limit would result in a gas refund for the user. The result is that miners would rather pack a block with more accurately reported gas limits to ensure a higher payout.

Pro Tip: Blocks in Ethereum Explained
Transactions on the Ethereum network are batched and processed in blocks. Blocks make it easy for participants of the network to stay synchronized and also allow for hundreds of transactions to be committed at once. Each block added to the network is uniquely connected to the previous block, ensuring security of the blockchain. 

What Computational Work Does Gas Pay For?

Before diving into the specific work accomplished in exchange for Ethereum Gas it’s important to understand what the Ethereum Virtual Machine (EVM) is. The EVM is a single entity formed from the distributed network of nodes verifying blocks and transaction data on the Ethereum network. 

In layman’s terms, the EVM is not a singular computer, but rather a collective of thousands of computers spread across the world that make up the Ethereum network. Anyone is able to run an Ethereum node and start supporting the EVM provided they have the necessary computer equipment.

Miners support the EVM by using their computational power to aid in the execution of smart contracts and other calculations and are rewarded for doing so in the form of Ethereum gas fees, this is what’s commonly referred to as “mining.” If you’re interested in learning more about mining or the technical details behind running your own node to support the EVM, check out the resources provided by the Ethereum Foundation.

Smart Contracts and Gas Fees

A smart contract is a contract which is executed via a computer protocol without the need for a third party. This is one of the areas where Ethereum has an advantage over Bitcoin, as bitcoin is not programmable and therefore cannot use smart contracts. A really simple way to think about smart contracts that most people will be able to relate to would be to think of them like “If, then” statements in excel. The computer protocol checks to see if a certain action has been performed and if it has it proceeds to perform a separate action. 

Like all other transactions on the Ethereum network, smart contracts require gas fees as an incentive for miners to effectuate the transaction. The gas needed to run a smart contract would be equivalent to the total gas required by the number of actions the smart contract requires. Therefore, gas fees vary among smart contracts, depending on what exactly a smart contract is designed to do.

Example

Smart Contract In Action

Let’s expand upon our earlier example of a smart contract utilized to pay insurance claims when weather in a region shows signs of flooding. 

In this scenario, there are various tasks that might have to be accomplished by the smart contract. For one, the smart contract would likely have to calculate approximate property damage through math equations. Each single math equation required for the smart contract would require gas fees – even the simplest equations, such as adding two numbers carries a gas cost of 3.

Why Do Ethereum Gas Fees Exist?

According to the Ethereum Foundation, gas fees keep the network secure. By adding a tangible cost tied to actions on the network, it becomes costly for malicious people to spam the network with useless actions. 

Another added benefit of gas fees is that they help optimize computational power being used by the network. This is best explained through the following metaphor:

Example

Gas Fees Help Optimization Efforts on Ethereum

Ethereum gas helps optimize computing power by introducing a cost to making transactions on the network. Imagine the fuel you use to drive your car was free. How would that change how you utilize your vehicle? 

For one, we imagine you might leave your car idling in situations where you might not have if you were paying for gas, like running into a convenience store. It’s also easy to imagine a scenario where people who take the bus or carpool to work to save money, might opt to revert back to driving themselves to work. 

In the real world, gas isn’t free. You only use gas when you need to accomplish something and you weigh the benefit of accomplishing said task against the cost of gas. This cost-benefit analysis is useful when trying to preserve a valuable resource, such as the environment, the gas itself, or in Ethereum’s case: the computational power on the network.

Who Sets Ethereum Gas Fees? 

Ethereum gas prices are set according to supply and demand in the market. The dynamic nature of Ethereum gas prices has interesting influences on users and miners alike. One important overarching implication of dynamic gas fees is that the cost to process a transaction on the Ethereum network can vary widely depending on the time of day and how many users are attempting to process transactions at the same time.    

How Ethereum’s Gas Prices Influence Users

As we’ve established, higher gas prices result in faster transaction execution times. However, users of the Ethereum network aren’t privy to each other’s gas prices. While users can use online tools to estimate how much they should pay in terms of gas for a certain execution time, there is no certainty of accuracy. The end result is that users of the network likely overpay for their transactions since they are more or less making an informed guess when setting their gas prices.

How Ethereum’s Gas Prices Influence Miners 

Since miners power the Ethereum network, they are in control of the prioritization of transactions. Given that miners earn the gas fees associated with transactions on the network, they will almost always process transactions with the highest fees first. 

How to Check Gas Prices

Thankfully, there are several great online resources for checking gas prices prior to executing a transaction on the Ethereum network. These resources allow you to see how much estimated gas you’d have to pay to push a transaction through the network and even offer estimates on timing based on how much you’re willing to pay.

Some of our favorites include Etherscan and ETH Gas Station.

EIP-1559: The Future of Ethereum Gas

Given that Ethereum is a continuously improving network, there are proposed changes to the way gas fees are structured in the blockchain. Ethereum Improvement Proposal (EIP) 1559, which will be included with an upcoming hard fork of the currency, aims to upend how users pay gas fees to miners on the network. As a reminder, a hard fork is a change in the underlying protocol of a blockchain, creating two divergent paths for the network.

In EIP-1559, the gas fee is automatically generated by creating something called a BASE FEE. The BASE FEE is adjusted up or down depending on the number of transactions attempting to be validated on the network. The main difference between the proposed change and the current system is that the BASE FEE effectively takes the guesswork out of the user’s hands in the sense that they no longer have to select a gas price. In theory, this would allow for fairer prices on the network.

Miners are upset with the proposal because it includes plans for the new gas fees to be burned, meaning the fees would cease to exist in the protocol, rather than being sent to miners as they currently are. Instead, miners would be rewarded with a tip, which users can add onto the BASE FEE. Theoretically, the larger the tip, the faster your transaction would be processed.

EIP-1559 marks a substantial change in the way Ethereum functions and it’s something users should keep an eye on as we approach the scheduled July rollout.