May 11, 2026

Introduction to Ethereum Gas – Ciaran Mcveigh

Introduction to Ethereum Gas – Ciaran Mcveigh

Just what on earth is Ethereum gas?

A lot of people have entered the crypto space in the last couple years (including myself) and anyone who has got involved with Ethereum has probably found themselves asking what an earth is gas? Put simply gas powers the Ethereum network in the same way gasoline powers a car. This article will look to unpack that statement for you so that you have solid understanding of what gas really is by the end of it.

The Ethereum Network

Gas powers the Ethereum network in the same way gasoline powers a car, what does that actually mean. Well to explain that I need to give you a little background on what the Ethereum network is primarily used for. The Ethereum network is a network of computers that will execute code on the blockchain and update its global state. Ok that sounds a bit complicated.

What that ultimately means is that computers on the networks are executing code and storing data. The execution of this code takes up resources (CPU, RAM etc) and because it is a blockchain every computer on the network must execute it. This presents a simple way to break the network, create a smart contract with an infinite loop, as each node on the network attempts to execute the code they would find themselves stuck and unable to serve any other transactions essentially DDOSing the network and bringing it to a grinding halt.

The developers and designers of Ethereum realised this and understood that there would have to be a cost associated with code execution and storage to prevent this from happening. This cost is known as gas.

Smart Contracts

When I refer to the execution of code I am referring to all transactions on the Ethereum network however for this article I would like to focus on smart contracts. Smart contracts are usually written in a high level programming language like solidity. Heres an example of a simple solidity smart contract which adds two numbers together and returns the result.

pragma solidity ^0.4.24;contract abc 
}

This solidity code gets compiled into EVM (Ethereum Virtual Machine) bytecode in the same way java is compiled into JVM bytecode. The EVM is a security oriented virtual machine, designed to permit untrusted code to be executed by a global network of computers. https://github.com/CoinCulture/evm-tools/blob/master/analysis/guide.md

https://github.com/ethereum/wiki/wiki/Ethereum-Virtual-Machine-(EVM)-Awesome-List The EVM essentially takes part of your CPU, RAM etc. and sets up a virtual computer. Below is the above solidity code compiled into the hex and string bytecode ,

6080604052348015600f57600080fd5b50603580601d6000396000f3006080604052600080fd00a165627a7a72305820a2425c36ccea0b4e81864448087f7f7a36fb11875dfb63711a27fcb427ad1cd00029

PUSH1 0x80 PUSH1 0x40 MSTORE CALLVALUE DUP1 ISZERO PUSH1 0xF JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST POP PUSH1 0x35 DUP1 PUSH1 0x1D PUSH1 0x0 CODECOPY PUSH1 0x0 RETURN STOP PUSH1 0x80 PUSH1 0x40 MSTORE PUSH1 0x0 DUP1 REVERT STOP LOG1 PUSH6 0x627A7A723058 KECCAK256 LOG2 TIMESTAMP 0x5c CALLDATASIZE 0xcc 0xea SIGNEXTEND 0x4e DUP2 DUP7 DIFFICULTY 0x48 ADDMOD PUSH32 0x7F7A36FB11875DFB63711A27FCB427AD1CD00029000000000000000000000000

Note that the hex and string bytecode are exactly the same in terms of content and are just represented in two different formats. We can see from the string bytecode that there are simple instructions such as PUSH1 etc. Each of these opt codes for the EVM have an associated gas value. For example PUSH1, a command to place 1 byte item on stack has a gas cost of 3 while more expense computations such as KECCAK256 which computes Keccak-256 hash cost 30 + (6 multiplied by the number of words being hashed).

Gas Price, Gas Limit & Running out of Gas

You may have been involved in ICO’s or maybe you’ve just simple transferred some ETH to another account in either case you’ve probably been asked to provide a gas limit and a gas price. Generally they are pre filled with recommended values but what do these two values actually mean. Gas limit is the amount of gas you’re will to use on this transaction, while the gas price is the amount of Ether you’re willing to pay for one gas. The equation for what you pay is simply,

GAS PAID = GAS PRICE * GAS USEDCONSTRAINTGAS USED <= GAS LIMIT

The gas used is the amount of gas used to execute a contract, the gas limit acts a constraint on the maximum amount of gas that can be used on a contraction execution. This stop malicious or inefficient code from draining your account of ether because it uses a large amount of gas.

As a simple example if I set a gas limit of 100 and a gas price of 1ETH and I execute a contract that requires 88 gas i will pay 88ETH for the execution of that code. If I then execute different contract which requires 101 gas instead of 88 with the same gas price and limit conditions the contract will run out of gas before the end of its execution. This is because i set a gas limit of 100 meaning the maximum i was willing to pay for the execution of this contract was 100 gas. Running out of gas during a contract execution will cause it to revert all the changes it has made. Despite this because it has still had to complete the computation you will still be charged for the gas you used up, in this case 100 for a total cost of 100ETH.
Note in reality gas is actually measured in wei a smaller denomination of ether.

To Be Continued…

The information above gives you a good starting point for understanding what gas is and why its important to the network. If you find this article has answered some questions but raised 10 more, don’t worry I was the same and I will try to address them in an upcoming in article delving deeper into Ethereum Gas.

Published at Sun, 07 Jul 2019 22:16:02 +0000

Previous Article

Bitcoin Disrupting Banking; Deutsche Bank To Cut 18,000 Jobs by 2022

Next Article

Bitcoin Disrupting Banking; Deutsche Bank To Cut 18,000 Jobs by 2022

You might be interested in …