Gas

The unit that measures how much computation an Ethereum transaction uses, and the basis for its fee.

What is Gas?

Gas is the unit that measures how much computational work a transaction requires on Ethereum and similar networks. Every operation has a fixed gas cost, and the sender pays a fee, in ether, for the total gas their transaction uses. Gas itself is not a coin or token; it is a unit of measurement.

How it works

The fee for a transaction is:

gas used x price per unit of gas

The price per unit is quoted in gwei, a small fraction of an ether. Since the EIP-1559 upgrade in 2021, the price has two parts. The base fee is set by the protocol and rises or falls with how full recent blocks are; it is burned. The priority fee, or tip, is chosen by the sender and goes to the validator.

Each transaction also has a gas limit, the maximum amount of gas the sender allows it to consume. Unused gas is not charged. If a transaction runs out of gas before finishing, its effects are undone but the fee for the work already performed is still paid.

Example

A plain transfer of ether uses 21,000 units of gas. If the gas price is 10 gwei, the fee is 210,000 gwei, which equals 0.00021 ether. A token swap on a decentralised exchange involves more computation and may use several times as much gas at the same price.

Why it matters

Gas puts a cost on computation. This prevents spam and endless loops from clogging the network, and it rewards validators. Since block space is limited, the base fee rises when many people want to transact at once, which is why fees vary so much over time.

Common misunderstandings

Related terms