What is Keccak-256?
Keccak-256 is the 256-bit sponge hash function that Ethereum uses everywhere: an address is the last 20 bytes of Keccak-256 of the public key, a function selector is the first 4 bytes of Keccak-256 of the canonical signature, and event topics, EIP-55 checksums and storage slots all derive from it. It is the original Keccak submission, which differs from NIST's finalised SHA3-256 only in the padding byte, so the two give different digests for the same input.
Typical uses
- Function selector: hash
transfer(address,uint256)as text and take the first 4 bytes:0xa9059cbb. The selector tool does this for many signatures at once and normalises Solidity declarations. - Event topic: the full Keccak-256 of
Transfer(address,address,uint256)is topic[0] of every ERC-20 transfer log. - Address from public key: hash the 64-byte uncompressed public key (without the 0x04 prefix) as hex and take the last 20 bytes.
- Mapping storage slot: hash
abi.encode(key, slot)as hex bytes to find wheremapping(address => uint)entries live. - Commit-reveal and content hashes: hash arbitrary text or files represented as hex.
Test vectors
| Input | Keccak-256 |
|---|---|
| (empty) | 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 |
abc | 0x4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45 |
Transfer(address,address,uint256) | 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef |
Paste any of these to confirm the implementation before relying on it.
Keccak-256 vs. SHA3-256 vs. SHA-256
| Function | Family | Padding / construction | Used by |
|---|---|---|---|
| Keccak-256 | Keccak sponge, rate 1088 bits | pad10*1 with 0x01 domain byte | Ethereum, Tron (TVM), all EVM chains |
| SHA3-256 | Keccak sponge, rate 1088 bits | pad10*1 with 0x06 domain byte (FIPS 202) | NIST applications, some non-EVM chains |
| SHA-256 | Merkle–Damgård (SHA-2) | length padding, 512-bit blocks | Bitcoin, Tron txID, TLS, Base58Check |
Worked example: SHA3-256 of abc in a FIPS 202 library returns 0x3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532, while Keccak-256 of the same three bytes is the 0x4e03657a… value in the table above. If a contract or explorer value does not match your library, the padding byte is the first thing to check.