In this track: Write and read Solidity
advanced · 4 MIN READ

Fixed bytes versus dynamic bytes

A fixed-size byte value differs from a variable-length byte sequence.

LET’S PICTURE IT

A four-slot tray and an expandable bag hold data under different size rules.

SEE IT FOR YOURSELF
Build a transfer call from typed fieldsStep 1 / 4
Build a transfer call from typed fieldstransfer(address,uint256)Recipient: 0x0000…0001Raw amount: 100Diagram labels abbreviate addresses; the lab shows full bytes4-byte selectora9059cbbEach box is one byte; this prefix is not a 32-byte wordWord 0 · recipient address12 zero bytes20 address bytes000…0001Left padding preserves the lower-order address valueSelector4 bytesa9059cbbAddress32 bytesword 0Amount32 bytesword 1 → 0x644 + 32 + 32 = 68 bytesThe integer does not contain token decimals or market price

The standard transfer interface takes an address and a raw integer amount. This diagram uses address one and amount one hundred.

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

Fixed bytes have a declared width

bytes1 through bytes32 represent fixed-size byte sequences. bytes4 is often used to describe a function selector. This differs from an integer that happens to contain similar bits.

Dynamic bytes carry variable length

bytes can contain an arbitrary-length sequence within execution and resource limits. Its ABI encoding uses dynamic layout, including length and padding, rather than behaving like every fixed bytes value.

Alignment differs in ABI encoding

A fixed bytes value is right-padded in its word, while an address or unsigned integer is left-padded. Treating all values as interchangeable 32-byte hex strings can therefore decode incorrectly.

Inspect exact byte content

Text encoding and hex display are additional layers. Use the hash tool’s explicit text or hex mode when testing bytes, and keep leading or trailing zeros when they are part of the actual input.

Read the example

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

contract LearningExample {
    function echo(bytes calldata data)
        external pure returns (bytes memory)
    {
        return data;
    }
}

The input and output use dynamic bytes encoding.

TURN UNDERSTANDING INTO PRACTICEOpen the ABI encoder →
QUICK CHECK · NO PRESSURE

Does ABI bytes4 use the same padding direction as uint32?

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.