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

Byte offsets and low-order alignment

Offset zero refers to the low-order end of a packed word.

LET’S PICTURE IT

A drawer’s numbering can begin at the right side of a written diagram.

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.

Choose a display direction

Hexadecimal words are normally printed with higher-order bytes on the left. A lower-order-aligned first field therefore appears at the right end of that display.

Read compiler byte offsets

For two uint128 fields in a slot, offsets zero and sixteen refer to their distance from the lower-order end. They are byte offsets, not bit offsets.

Extract only the intended bits

To inspect the second field, shift right by 128 bits and apply its width mask. Keep the other packed field separate rather than treating the whole word as one value.

Preserve neighbors when writing

A partial-field update must retain unrelated bits. Manual assembly that overwrites the full slot can corrupt other fields sharing that word.

Inspect the layout

slot word = (b << 128) | a
a: byte offset 0
b: byte offset 16

This illustrates unsigned packed fields and is not a complete assembly implementation.

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

Which side of printed hex normally contains the low-order bytes?

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.