JOVANA
Library Glossary Getting Started Three Levels Fields How it works Mission
Join the mission
All guides

The EVM and Gas

Every node on Ethereum runs the same world computer in perfect lockstep. Gas is the meter that makes each step of that computation cost something — so code gets paid for and can never run forever.

One computer, run by everyone

Picture a vast hall filled with thousands of identical calculators, each in front of a different person on a different continent. Someone reads out a recipe of steps — add this, store that, compare these — and every person keys in exactly the same steps at exactly the same moment. Because the calculators are identical and the steps are identical, they all land on the same answer. No one calculator is in charge; the answer is simply whatever they all agree on. That hall is the Ethereum Virtual Machine, usually shortened to the EVM.

A smart contract is one of those recipes, written down once and stored on the chain forever. When you send a transaction that calls a contract, you are reading out its recipe to the whole hall. Every full node on Ethereum re-runs the EVM through those same steps and checks that it gets the same result. This is why people call the EVM a single global computer: it is one machine, but its work is mirrored on every node so that no single one can lie about the outcome.

Why computation needs a meter

Here is the catch. Thousands of nodes are about to run your recipe for free, on their own machines. What stops a careless — or malicious — contract from telling them all to count to a trillion, or loop around forever and never stop? If even one recipe could run without limit, it would freeze the entire global computer. The fix is delightfully simple: charge for every single step. That price tag on computation is called gas.

Think of gas as a fuel gauge in a taxi. Every operation the EVM performs has a fixed gas cost set by the rulebook — cheap things like adding two numbers cost a little, expensive things like writing a value into permanent storage cost a lot. As your transaction runs, the meter ticks up, draining a tank you paid to fill. Run a short, simple recipe and you spend little fuel. Run a long, storage-heavy one and you spend a great deal. The meter makes the amount of work visible and chargeable, the same way a taxi charges by distance rather than by a flat fare.

Gas limit, gas price, and the bill

When you send a transaction you set two separate numbers, and it pays to keep them apart in your mind. The gas limit is the size of the tank — the most gas you will allow this transaction to burn before the EVM yanks it to a stop. It protects you from a buggy contract draining your wallet. The gas price is how much you are willing to pay for each unit of that gas, quoted in a tiny fraction of ether. One says *how far am I prepared to drive*; the other says *how much per litre I will pay*.

The bill you actually pay is roughly the two multiplied together: gas used × gas price. Crucially, you are charged for the gas you truly burned, not for the whole tank — if your recipe only needs forty thousand gas out of a hundred-thousand limit, the unused sixty thousand is handed back. The limit is a ceiling for safety; the real cost tracks the work actually done. One refinement worth knowing: today's gas price splits into two parts — a base fee the network sets automatically for each block and then destroys, plus a small tip you add on top to nudge your transaction ahead. The base fee is not pocketed by anyone; it is burned, permanently removed from circulation.

So why does the same action cost more at busy times? Because each block can hold only so much gas in total. When the mempool is crammed with people all wanting in at once, blocks fill up, and the network automatically ratchets the base fee upward block after block until demand cools — that is the part that makes a quiet-day action suddenly pricey. The tip is your lever to jump the queue: offer a fatter tip and a block builder slots you in sooner; offer little when the chain is calm and you still get in. The gas amount for your action barely changes — what swings is the price per unit, driven by how many others are competing for the same scarce block space.

A tiny trace, step by step

Let's watch a tiny contract actually run on the meter. Here is a fragment of Solidity, the most common language for writing EVM contracts. It just adds two numbers and saves the result into permanent storage:

contract Tiny {
    uint256 total;

    function bump(uint256 a, uint256 b) public {
        uint256 sum = a + b;   // do the math in memory
        total = sum;           // save it to storage
    }
}
A minimal Solidity contract: add two numbers, then store the result on the chain.

The EVM never sees that tidy text. It runs a list of tiny operations the code compiles down to, and meters each one. Watch the gas tank drain — note how the single storage write dwarfs everything else, because making thousands of nodes remember a value forever is the most expensive thing you can ask of them:

step  operation        gas    running total
----  ---------------  -----  -------------
 1    PUSH a               3              3
 2    PUSH b               3              6
 3    ADD  (a + b)         3              9
 4    PUSH slot            3             12
 5    SSTORE (save sum) 20000          20012
                                  ^^^^^
                          one storage write
                          dominates the bill
Each EVM operation has a fixed gas cost. Arithmetic is nearly free; writing to permanent storage is by far the priciest step.

Read it as a running tally. The three arithmetic steps barely move the needle; the lone write to storage costs thousands of times more. This is the single most useful instinct to carry forward: on the EVM, doing math is cheap and remembering things is expensive. Good contract authors spend much of their effort touching storage as little as possible, precisely because that is where the gas goes.

The takeaway

Pull it together and the picture is clean. The EVM is one global computer that every node re-runs in lockstep, so its results are something the whole network can verify rather than trust. Gas is the meter that prices each step of that computation: it makes work payable, keeps any contract from looping forever, and — as congestion drives the per-block base fee up and down — decides how much you pay right now. Gas limit caps your risk; gas price (a burned base fee plus your tip) sets the rate; the bill is that rate multiplied by the work you actually used.

Now you can feel why one chain might cost a few cents while another costs dollars: it comes down to how much block space there is and how many people are bidding for it. With the engine and its meter understood, the next guides climb up a level — to the standards that let contracts mint and move value, and the wallets and apps that drive the whole machine.