Reviewed Aug 2026
DE
BA-09 · LESSON 10

Bitcoin P2P message bytes

KEY DEFINITIONS

Terms used in this lesson

P2P
Peer-to-peer: nodes communicate directly with other nodes rather than through one central server.
ASCII
A standard mapping between common text characters and byte values.
HASH256
Bitcoin's name for applying SHA-256 twice to the same byte sequence.

Parse network magic, command, payload length, checksum, and payload from a byte stream before applying command-specific limits and validation.

45 min Difficulty 3/5 Not started

Loading lesson visuals...

01

Learn the idea

A Bitcoin peer-to-peer message begins with a 24-byte header: four network-magic bytes, a 12-byte zero-padded ASCII command, a four-byte little-endian payload length, and four checksum bytes taken from HASH256 of the payload. The payload format and size limit depend on the command and negotiated protocol version.

GUIDED EXPLANATION1/5 ideas inspected
1

Match network magic

Mainnet magic serializes f9 be b4 d9. Other networks use different values. A stream reader searches or synchronizes carefully without treating coincidental bytes inside a malicious payload as a trusted frame.

Inspect each idea before the worked example.
The worked example follows the explanation

Inspect every idea above to open it.

Important distinctionThe message checksum proves a peer sent valid Bitcoin data.

It detects payload corruption or mismatch. The command payload remains untrusted and must pass its own parser, policy, and consensus checks.

02
FINISH LEARNING FIRST

The questions unlock after every required learning activity

Inspect every guided idea, open the worked example, rebuild its mechanism, and complete the deterministic lesson tool. Your progress is saved automatically.