Skip to content

What is the Ethereum Virtual Machine (EVM)? How Ethereum runs smart contracts

What the Ethereum Virtual Machine is, how it turns transactions into a new state, how contracts become opcodes, why gas exists and what EVM-compatible means.

Figures checked against 5 official and primary sources on . See the sources · How we check

Key points

  • The Ethereum Virtual Machine (EVM) is the environment that runs smart contract code in the same way on every Ethereum node.
  • ethereum.org describes Ethereum as a distributed state machine: the EVM applies each block's transactions to the current state to produce the next one.
  • Contracts written in languages like Solidity or Vyper are compiled to bytecode, which the EVM runs as a sequence of opcodes, each with a gas cost.
  • The EVM is deterministic: the same inputs give the same result on every node, which is how thousands of computers agree on the outcome.
In this guide
  1. Ledger versus state machine
  2. How the state changes
  3. Deterministic by design
  4. From code to opcodes
  5. Inside the machine
  6. Why gas exists
  7. Many implementations, one set of rules
  8. What “EVM-compatible” means
  9. A transaction, step by step
  10. Why it matters to users

When people say Ethereum is “programmable money”, they’re talking about the Ethereum Virtual Machine, or EVM. It’s the part of Ethereum that runs smart contracts: the lending apps, exchanges, tokens and NFTs built on the network all depend on it.

This guide explains what the EVM is, how it works at a high level, and why it matters even if you never write code. It follows ethereum.org’s documentation. For the basics, see what is Ethereum? and what is a smart contract?

Ledger versus state machine

ethereum.org draws a useful contrast. Bitcoin is often described as a distributed ledger: a shared record of who owns what. Ethereum is that and more. It describes Ethereum as a distributed state machine: a large data structure that holds accounts and balances and also a machine state, which changes from block to block according to predefined rules and can run arbitrary code.

The EVM is what defines those rules. ethereum.org calls it a decentralized virtual environment that executes code consistently and securely across all Ethereum nodes.

How the state changes

ethereum.org sums up the EVM’s job with a simple formula:

Y(S, T) = S’

  • S is the old, valid state.
  • T is a set of new, valid transactions.
  • Y is the state transition function: the EVM applying those transactions.
  • S’ is the new state.

Every node runs the same transactions through the same function and should reach the same new state. That’s how the network agrees on balances, token ownership and contract data without a central server.

Deterministic by design

For that agreement to work, the EVM has to be deterministic: ethereum.org says that given specific inputs, it produces a deterministic output. The same transaction applied to the same state gives the same result, on any machine, anywhere.

This is also why smart contracts can’t simply call a website for a price: nodes have to reach the same result, so outside data has to be brought onto the blockchain first, through services called oracles. See blockchain oracles explained.

From code to opcodes

Developers write smart contracts in high-level languages. ethereum.org highlights two:

  • Solidity, an object-oriented language with syntax influenced by C++;
  • Vyper, a Pythonic language that deliberately has fewer features than Solidity, to make contracts more secure and easier to audit.

That code is compiled into EVM bytecode, the format the EVM runs. Bytecode is a sequence of opcodes: low-level instructions such as ADD (addition), SSTORE (save to storage) and CALL (call another contract). ethereum.org’s opcode reference lists them from 00 (STOP) to FF (SELFDESTRUCT), each with its gas cost.

Inside the machine

ethereum.org describes the EVM as a stack machine:

Part What it holds
Stack Up to 1,024 items, each a 256-bit word, used for calculations
Memory Temporary data, wiped after each transaction
Storage Each contract’s permanent data, kept in a Merkle Patricia trie
Transient storage Data that lasts only for one transaction, through the TSTORE and TLOAD opcodes

The 256-bit word size suits the cryptography Ethereum relies on. Storage is what persists between transactions: a token contract’s record of balances, for example.

Why gas exists

Running code on thousands of computers costs real resources, and a program could in principle run forever. Gas solves both problems. ethereum.org explains that gas measures the computational effort needed for operations, and each opcode has a gas cost: simple arithmetic such as ADD costs 3 gas, while operations such as SSTORE have dynamic costs that depend on the situation.

When you send a transaction, you pay for the gas it uses. If a transaction runs out of gas while executing, its changes are reverted, but the gas used is still paid, because the network did the work. That’s why interacting with a complex contract costs more than a simple transfer. See Ethereum gas fees explained.

Many implementations, one set of rules

The EVM is a set of rules, not a single program. ethereum.org lists implementations in several programming languages, including Py-EVM (Python), evmone (C++), ethereumjs-vm (JavaScript) and revm (Rust). Because the EVM is deterministic, every correct implementation has to produce exactly the same results. See what is a blockchain node?

What “EVM-compatible” means

You’ll often see networks described as EVM-compatible. In plain terms, they can run code written for the EVM, so developers can reuse the same languages, tools and contracts.

ethereum.org gives an example from Ethereum’s own scaling roadmap. ZK-rollups weren’t readily compatible with the EVM at first; a zkEVM recreates EVM opcodes so that smart contracts can run inside a rollup and be proven with zero-knowledge proofs. ethereum.org explains that compatibility means developers can use familiar and battle-tested tools and languages. See layer 2 rollups explained.

Compatibility is about code, not safety: a network that runs EVM code can still have very different security from Ethereum itself.

A transaction, step by step

Here’s what happens, in simplified form, when you swap tokens on a decentralized exchange:

  1. Your wallet builds a transaction that calls the exchange’s contract with your swap details, and you sign it.
  2. The transaction is shared with the network and included in a block.
  3. Every node runs it through the EVM: the contract’s bytecode executes opcode by opcode, reading balances from storage, doing the arithmetic on the stack, and calling the token contracts involved.
  4. If everything succeeds, the new balances are written to storage, and the state moves from S to S’. If anything fails, or the gas runs out, the changes are reverted.
  5. You pay for the gas used either way.

Every node that processes the block reaches the same new state, which is why your new balance shows up the same in any wallet or block explorer.

Why it matters to users

  • Your tokens are EVM data. An ERC-20 token balance is an entry in a contract’s storage. See what is ERC-20?
  • The right network matters. The same token can exist on several blockchains, and ethereum.org warns that you must make sure the recipient is using the same network. See how to send crypto safely.
  • Code does what it says, not what you hope. The EVM runs contract code exactly. A malicious approval or a buggy contract executes just as faithfully as a good one. See token approvals and how to revoke them.

Frequently asked questions

Is the EVM a physical computer?
No. It's a virtual environment defined by Ethereum's rules. Every Ethereum node runs software that implements it, so the same code produces the same result everywhere.
What does EVM-compatible mean?
That a network can run code written for the EVM, so developers can reuse familiar languages and tools. ethereum.org explains that some layer 2 networks, such as those using a zkEVM, recreate EVM behavior so existing smart contracts can run on them.
Why do smart contracts cost gas?
Because each EVM operation uses computing resources on every node. Gas measures that computational effort, and each opcode has a gas cost, so heavier contracts cost more to run.
What languages are used to write EVM smart contracts?
ethereum.org lists Solidity, an object-oriented language influenced by C++, and Vyper, a Pythonic language designed with fewer features to make contracts easier to audit. Both compile to EVM bytecode.
Does bitcoin have an EVM?
No. The EVM is part of Ethereum. ethereum.org contrasts Ethereum, which it describes as a distributed state machine, with distributed ledgers such as bitcoin.

Sources

  1. Ethereum Virtual Machine (EVM) — ethereum.org
  2. Opcodes for the EVM — ethereum.org
  3. Smart contract languages — ethereum.org
  4. Gas and fees — ethereum.org
  5. Zero-knowledge rollups — ethereum.org

First published . Spotted an error or an outdated figure? Tell us and we will check it against the source.