The Bitcoin peer-to-peer (P2P) network protocol enables decentralized communication between nodes, ensuring secure and efficient transaction propagation and block synchronization. This guide covers the core aspects of the Bitcoin P2P protocol, including message formats, constants, and version history.
👉 Learn more about Bitcoin’s decentralized architecture
Constants and Defaults
The following constants and defaults are derived from Bitcoin Core’s chainparams.cpp
source file:
Network | Default Port | Start String | Max nBits |
---|---|---|---|
Mainnet | 8333 | 0xf9beb4d9 |
0x1d00ffff |
Testnet | 18333 | 0x0b110907 |
0x1d00ffff |
Regtest | 18444 | 0xfabfb5da |
0x207fffff |
Notes:
– Start strings appear at the beginning of all Bitcoin network messages.
– nBits are transmitted in little-endian order over the network.
– Testnet3 uses different parameters compared to the original testnet.
Protocol Versions
The table below highlights notable P2P protocol versions, with the most recent first.
Version | Initial Release | Major Changes |
---|---|---|
70015 | Bitcoin Core 0.13.2 (Jan 2017) | New banning behavior for invalid compact blocks |
70014 | Bitcoin Core 0.13.0 (Aug 2016) | BIP152: Added compact block messages (sendcmpct , cmpctblock , getblocktxn ) |
70013 | Bitcoin Core 0.13.0 (Aug 2016) | BIP133: Added feefilter message, removed alert system |
70012 | Bitcoin Core 0.12.0 (Feb 2016) | BIP130: Introduced sendheaders |
70011 | Bitcoin Core 0.12.0 (Feb 2016) | BIP111: Disabled filter* messages without NODE_BLOOM |
70002 | Bitcoin Core 0.9.0 (Mar 2014) | Added reject message (BIP61 ), multiple inv responses |
70001 | Bitcoin Core 0.8.0 (Feb 2013) | BIP37: Introduced Bloom filters (filterload , filteradd , merkleblock ) |
60002 | Bitcoin Core 0.7.0 (Sep 2012) | BIP35: Added mempool message |
60001 | Bitcoin Core 0.6.1 (May 2012) | BIP31: Added ping nonce and pong message |
60000 | Bitcoin Core 0.6.0 (Mar 2012) | Separated protocol version from Bitcoin Core version (BIP14 ) |
Data Messages
Bitcoin P2P communication relies on data messages for transactions, blocks, and synchronization.
1. Inventory (inv
) Messages
- Transmits hashes of known objects (transactions, blocks).
- Used for transaction/block announcements and synchronization.
Structure:
| Bytes | Field | Description |
|——-|——-|————|
| 4 | Type | MSG_TX
(1), MSG_BLOCK
(2), etc. |
| 32 | Hash | SHA256(SHA256(object)) |
👉 Discover how Bitcoin nodes exchange data efficiently
2. getblocks
Message
- Requests block hashes starting from a specified point in the chain.
- Used for chain synchronization after disconnections.
Structure:
| Bytes | Field | Description |
|——-|——-|————|
| 4 | Version | Protocol version |
| Varies | Hash Count | Number of block hashes |
| 32 | Stop Hash | Last hash requested (all zeroes for max 500 hashes) |
3. merkleblock
Message
- Provides filtered block data for SPV (Simplified Payment Verification) clients.
- Follows BIP37 (Bloom filters).
Structure:
| Bytes | Field | Description |
|——-|——-|————|
| 80 | Block Header | Block metadata |
| Varies | Transaction Hashes | Matched transactions |
Control Messages
1. version
Message
- First message exchanged between nodes.
- Contains node capabilities and network information.
Key Fields:
| Field | Description |
|——-|————|
| services
| Supported features (NODE_NETWORK
, NODE_BLOOM
) |
| user_agent
| Client identifier (e.g., /Satoshi:0.21.0/
) |
| start_height
| Best block height |
2. addr
Message
- Shares IP addresses of reachable peers.
- Used for decentralized peer discovery.
FAQs
1. What is the Bitcoin P2P network?
The Bitcoin P2P network is a decentralized system where nodes communicate directly, ensuring no single point of failure.
2. How do nodes discover each other?
Via DNS seeds, hardcoded IPs, and addr
messages from peers.
3. What is a Bloom filter?
A probabilistic data structure used by SPV clients to request relevant transactions without revealing full wallet addresses.
4. Why was the alert
system deprecated?
Replaced by a decentralized alert key system to prevent abuse.
5. What is the purpose of feefilter
?
Allows nodes to ignore low-fee transactions, improving network efficiency.
6. How does compact block relay work?
BIP152 enables nodes to send compressed block data, reducing bandwidth usage.