How Ethereum Storage works

storage in Ethereum programming can mean 2 different things:

how Ethereum stores contract data on the blockchain, and how Solidity stores global and local variables.

In this post, we’re dive into how Ethereum stores data on the blockchain.

Storage on Ethereum blockchain is 2²⁵⁶ slots, and each slot is 32 bytes.

Each smart contract has its own storage to reflect the state of the contract. The values in storage persist across different function calls. And each storage is tethered to the smart contract’s address.

How data is physically stored

Data is stored sequentially in these slots, in order of declaration.

Storage is optimized to save byte space. So if sequential variables will fit in a single 32-byte slot, they will share the same slot, indexing from the least significant bits (from the right).

A visualisation of this Ethereum storage and space optimization: