In this track: Gas and execution fees
intermediate · 3 MIN READ

Storage writes and gas

Persistent updates have costs that depend on the state transition.

LET’S PICTURE IT

Writing a new entry, overwriting an existing entry and clearing an entry can have different bookkeeping requirements.

SEE IT FOR YOURSELF
Pack small values into Solidity storage slotsStep 1 / 4
Pack small values into Solidity storage slotsFirstuint128 A16 bytesSeconduint128 B16 bytesThirduint256 C32 bytesSimple elementary types only; not a complete compiler layoutSlot 0 · 32 bytesUnused · 16 BA · 16 BHigh-order bytes ← → low-order bytesSlot 0 · fullB · 16 BA · 16 BDeclaration order and sizes determine this packingSlot 0BASlot 1C · 32 bytesTry different sequences in the storage-layout tool

In this simple default-layout example, two uint128 values come before one uint256. Each slot holds thirty-two bytes.

Animated local teaching model. No wallet, RPC or live blockchain data. Some labels and hashes are abbreviated for readability.

Persistence is a network resource

Contract storage survives across calls and must be maintained by the system. Writing it uses gas under rules that distinguish relevant previous and new values and access context.

Not every SSTORE has the same cost

The original value, current value, new value and warm/cold status can affect metering and refunds. Counting source lines or storage assignments alone is not a complete gas calculation.

Packing changes layout, not every trade-off

Smaller adjacent values can share slots in Solidity. That can reduce slot usage, while reading or updating packed parts may require additional operations. “Smaller type” is not automatically a universal gas win.

Inspect layout and execution separately

The storage visualizer teaches slot packing for simple elementary types. It deliberately does not calculate full transaction gas or certify an upgrade layout. Use compiler output and execution evidence for production analysis.

TURN UNDERSTANDING INTO PRACTICEOpen the Storage layout →
QUICK CHECK · NO PRESSURE

Can every storage write be priced correctly by counting assignments alone?

Your progress stays in this browser.
Keep exploring the original referenceEthereum Improvement Proposals ↗

Original explanations by EtherTools. Examples are educational and source-linked; this site is independent of the Ethereum Foundation. Our approach.