Free online tools to generate, calculate,
convert, format, encode, and play.
 

Solidity Storage Layout

Visualize how Solidity state variables pack into 32-byte EVM storage slots. Paste variable declarations to analyze packing and find optimization opportunities.


Variable Declarations

Enter one Solidity variable declaration per line (type and name)
The layout updates as you type.

Presets


How It Works

The Ethereum Virtual Machine (EVM) organizes contract storage as a key-value store where each slot is 32 bytes (256 bits) wide. Solidity packs state variables into these slots sequentially, following specific rules that can significantly impact gas costs.

Packing Rules

  1. Sequential allocation — Variables are assigned to slots in declaration order, starting at slot 0.
  2. Tight packing — If the next variable fits in the remaining bytes of the current slot, it is packed into the same slot (right-aligned within the slot, lower-order bytes first).
  3. New slot on overflow — If the next variable does not fit, it starts a new slot. Variables never span across slot boundaries.
  4. Mappings and dynamic arrays — Always occupy a full slot (which stores metadata), with actual data stored at a computed location. They also force the next variable to a new slot.
  5. Structs — Start on a new slot, and their members follow the same packing rules internally.

Type Sizes

TypeSizeNotes
bool1 byteStored as uint8 (0 or 1)
uint8 / int81 byte
uint16 / int162 bytes
uint32 / int324 bytes
uint64 / int648 bytes
uint128 / int12816 bytes
uint256 / int25632 bytesFull slot
address20 bytes
bytes1 – bytes321 – 32 bytesFixed-size byte arrays
bytes / string32 bytes (slot)Dynamic, data stored elsewhere
mapping(...)32 bytes (slot)Data at keccak256 hash location
T[]32 bytes (slot)Length stored, data at keccak256
T[N]N × sizeof(T)Packed inline across slots
enum1 byteStored as smallest uint that fits

Gas Optimization Tips

  • Group small variables together — Place bool, uint8, address next to each other so they share a slot.
  • Order by size — Declaring smaller types consecutively maximizes packing efficiency.
  • Use smaller types when possible — A timestamp fits in uint64 (until year 584 billion), saving 24 bytes over uint256.
  • Cold vs warm reads — Accessing a storage slot costs 2100 gas the first time (cold) but only 100 gas for subsequent reads in the same transaction. Packing related variables in the same slot saves gas when they are read together.

Embed This Util

You can embed this util on your own site as a widget. Adding ?embed=1 to the URL loads a compact version with just the tool itself; no header, menu, or documentation. Paste this snippet into your HTML:


    

Copy snippet Adjust the height to taste.



Feedback

Help us improve this page by providing feedback, and include your name/email if you want us to reach back. Thank you in advance.


Share with