In this track: Storage, memory and layout
advanced · 4 MIN READ

Short bytes and short strings in storage

Up to thirty-one bytes can share a slot with their length marker.

LET’S PICTURE IT

A short note fits inside its index card instead of needing an attachment.

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.

Recognize the special layout

Storage bytes and string have special short-value rules. A payload of at most thirty-one bytes can fit in the main slot with its length information.

Place short content at the high end

The short payload is left-aligned in the slot, unlike the lower-order alignment of ordinary packed integers. Do not reuse the uint128 packing picture unchanged.

Read the low-byte marker

For a short payload of length n, the low byte stores twice n and has its lowest bit clear. The string hi therefore has a low-byte marker of four.

Keep storage and ABI distinct

ABI strings have offsets and length words. A short storage string’s compact slot representation is a different encoding and cannot be decoded as an ABI string tuple.

Inspect the layout

string value = "hi";
short slot: 0x6869000000000000000000000000000000000000000000000000000000000004

The two UTF-8 bytes are high-order aligned; the low byte is the short-length marker.

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

What low-byte marker represents a two-byte short payload?

Your progress stays in this browser.
Keep exploring the original referenceSolidity documentation ↗

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