Try it Live
Run RLP examples in the interactive playground
Conceptual Guide - For API reference and method documentation, see RLP API.
What is RLP?
RLP is a binary encoding scheme that serializes:- Byte strings - Raw binary data (addresses, hashes, numbers)
- Lists - Ordered collections of byte strings or nested lists
- Nested structures - Recursive lists containing other lists
Why Ethereum Uses RLP
Deterministic serialization - Same data always produces identical encoding, critical for:- Transaction signing (hash must be consistent)
- Merkle tree construction (state/transaction/receipt tries)
- Network protocol messages (devp2p)
- Single byte values encode as themselves (no prefix)
- Short strings use 1 byte prefix
- Only long data needs multi-byte length encoding
- Decode without knowing data structure
- Parse incrementally from byte stream
- Validate structure without semantic knowledge
RLP vs Other Formats
- RLP
- JSON
- Protocol Buffers
Encoding Algorithm
RLP encoding follows a simple recursive algorithm based on input type:Encoding Rules
RLP uses five encoding rules based on data type and length:Rule 1: Single Byte (0x00-0x7f)
Bytes with values less than 0x80 encode as themselves - no prefix needed.Rule 2: Short Strings (0-55 bytes)
Byte strings of 0-55 bytes:[0x80 + length, ...bytes]
Rule 3: Long Strings (56+ bytes)
Byte strings of 56+ bytes:[0xb7 + length_of_length, ...length_bytes, ...bytes]
Rule 4: Short Lists (0-55 bytes total payload)
Lists with total payload < 56 bytes:[0xc0 + length, ...encoded_items]
Rule 5: Long Lists (56+ bytes total payload)
Lists with total payload >= 56 bytes:[0xf7 + length_of_length, ...length_bytes, ...encoded_items]
Visual Encoding Examples
Example 1: Encoding “dog”
Example 2: Encoding [ “cat”, “dog” ]
Example 3: Nested Structure
Encoding Numbers
RLP treats numbers as byte strings - you must convert to bytes first:- Zero encodes as empty byte string:
[0x80] - No leading zeros (except for zero itself)
- Big-endian byte order
- Minimal byte representation
Decoding Process
Decoding reverses the encoding process by examining prefix bytes:Decoding Algorithm
Streaming Decoding
Process multiple RLP-encoded items from a byte stream:Complete Example: Transaction Encoding
Ethereum transactions use RLP encoding for signing and transmission:Transaction Encoding Breakdown
Use Cases in Ethereum
Transactions
All transaction types use RLP:- Legacy transactions (9 fields)
- EIP-2930 (access list transactions)
- EIP-1559 (fee market transactions)
Block Headers
Block headers are RLP-encoded lists of 15+ fields:Merkle Patricia Tries
State, transaction, and receipt tries use RLP for node encoding:Network Protocol (devp2p)
Ethereum’s peer-to-peer protocol messages use RLP:Validation
Ensure RLP encoding is valid before decoding:Canonical Encoding
RLP has canonical form requirements:- Numbers must not have leading zeros (except zero itself)
- Shortest encoding must be used
- Empty byte string is
[0x80], not[]
Common Patterns
Working with Addresses
Working with Hashes
Encoding Variable-Length Data
Resources
- Ethereum Yellow Paper - Formal RLP specification (Appendix B)
- Ethereum RLP Documentation - Official RLP guide
- EIP-2718 - Typed transaction envelope using RLP
- Merkle Patricia Trie - RLP in state tries

