EVMTools

Bytes32 / String Converter

Convert between bytes32 hex, UTF-8 strings, numbers, and addresses. Visualize padding for Solidity bytes32 values.

About Bytes32 Encoding

  • Strings are right-padded with zeros (UTF-8 bytes followed by 0x00)
  • Numbers are left-padded with zeros (big-endian representation)
  • Addresses are left-padded with 12 zero bytes (20 bytes to 32 bytes)
  • Solidity uses bytes32 for storage slots, mapping keys, and fixed-size data
  • Strings longer than 32 bytes cannot be stored in a single bytes32 slot

How to Use This Bytes32 / String Converter

This free online converter helps you work with Solidity bytes32 values. Convert between hex, UTF-8 strings, numbers, and addresses while visualizing exactly how the data is padded in a 32-byte slot.

  1. Enter a hex value (with or without 0x prefix) to see it formatted as a full bytes32 value with padding visualized.
  2. Enter a UTF-8 string to see how it would be represented as a right-padded bytes32 value.
  3. Enter a number to see its left-padded bytes32 representation as used in the EVM.
  4. Enter an address to see how it is left-padded to fill a 32-byte slot.
  5. Copy the result for use in your Solidity code, tests, or calldata construction.

All conversions run locally in your browser. No data is transmitted to any server.

Common Use Cases

  • Storage slot inspection — Decode bytes32 values read from contract storage to understand what data they represent.
  • Short string encoding — Convert strings of 32 characters or fewer to bytes32 for gas-efficient on-chain storage.
  • Hash comparison — Format Keccak256 hashes and other 32-byte values for comparison and debugging.
  • ABI parameter preparation — Convert values to their padded bytes32 format to understand ABI encoding layout.
  • ENS namehash inspection — Inspect bytes32 node identifiers and label hashes used by the Ethereum Name Service.

Related Tools

Frequently Asked Questions

What is bytes32 in Solidity?

bytes32 is a fixed-size value type in Solidity that stores exactly 32 bytes (256 bits) of data. It is the most commonly used fixed-size byte type because it matches the EVM's native word size. bytes32 is used for storage keys, hashes, identifiers, and packed data in smart contracts.

How do I convert a string to bytes32 in Solidity?

In Solidity, you can convert a string to bytes32 using bytes32(bytes(myString)), but only if the string is 32 bytes or shorter. The string is left-padded (UTF-8 bytes start from the left, remaining bytes are zeros). For strings longer than 32 bytes, you need to use the dynamic bytes or string type instead.

What is the difference between left-padding and right-padding?

Left-padding adds zeros to the beginning of the value (used for numbers and addresses in the EVM), while right-padding adds zeros to the end (used for strings and fixed-size byte arrays). In Solidity, bytes32 values from strings are right-padded, while bytes32 values from numbers are left-padded.

Why is bytes32 more gas-efficient than string?

bytes32 fits in a single EVM storage slot (32 bytes) and is a value type, so operations are simple and cheap. The string type is dynamically-sized and can span multiple storage slots, requiring more complex (and expensive) storage operations. If your string is 32 characters or fewer, using bytes32 saves significant gas.

How are Ethereum addresses stored in bytes32?

Ethereum addresses are 20 bytes long. When stored in a bytes32 slot, they are left-padded with 12 zero bytes to fill the 32-byte slot. For example, address 0xAbC...123 becomes 0x000000000000000000000000AbC...123 in bytes32 format. This is the same padding used in ABI encoding.

Can I use bytes32 for ENS names?

ENS (Ethereum Name Service) uses bytes32 extensively. The namehash algorithm produces a bytes32 node identifier from domain names. Labels are stored as keccak256 hashes (also bytes32). This tool helps you inspect and convert between the hex representation and the readable form of these values.