Try it Live
Run Bytes examples in the interactive playground
Most Important Bytes Type - Bytes32 is THE fundamental 256-bit type in Ethereum. Used everywhere: storage slots, hashes, merkle trees, and generic 32-byte values.
Overview
Bytes32 is a brandedUint8Array specialization of the generic Bytes<N> type, representing exactly 32 bytes (256 bits). It’s the most common fixed-size type in Ethereum and provides strict type safety for 256-bit values through Symbol-based branding.
See the Bytes overview for generic Bytes<N> documentation and other size specializations.
Why Bytes32 is Critical
Ethereum’s fundamental 256-bit type:- Storage slots - EVM storage uses 32-byte slots
- Hashes - Keccak256 outputs 32 bytes
- Merkle trees - Node values are 32 bytes
- Generic values - Most fixed-size data is 32 bytes
- ABI encoding - Uint256, bytes32, etc. use 32 bytes
Difference from Keccak256Hash
Both are 32 bytes, but semantic meaning differs:- Keccak256Hash - Cryptographic hash outputs (keccak256 results)
- Bytes32 - Storage slots, generic 32-byte values, numeric conversions
Type Safety
Bytes32 is a specialization ofBytes<32> using Symbol-based branding for compile-time type safety with zero runtime overhead:
brand symbol is a unique TypeScript symbol that creates nominal typing - structurally identical types are incompatible if they have different brands:
- Compile-time safety - Cannot mix different sized Bytes types
- Zero runtime cost - Brand only exists in TypeScript, erased after compilation
- Hardcoded length - Type includes
{ readonly size: 32 }for static length checking
Hex String Representation
For hex string representations, use theHexBytes32 type which extends branded hex strings with size information:

