Node Connections & Ports
Bitcoin P2P Handshake: Core Connection and Port Layouts
Establishing connection with peers is the prerequisite for joining the decentralized Bitcoin network. Nodes connect to each other at the transport layer (TCP) to gossip transactions, synchronize block headers, and download raw block payloads.
This guide details the TCP socket layers, the DNS bootstrapping seed protocol, and standard port layouts across all active Bitcoin networks.
π 1. The Transport Layer (TCP Sockets)
Bitcoin operates strictly on top of TCP (Transmission Control Protocol). TCP ensures that packets are delivered reliably, in order, and error-free, which is essential for transporting cryptographic transaction and block data.
PEER-TO-PEER SOCKET CONNECTION ESTABLISHMENT
Local Node (Initiator) Remote Peer Node
βββββββββββββββββββββββ βββββββββββββββββββββββ
β 1. Performs DNS β β β
β Seed Lookup β β β
ββββββββββββ¬βββββββββββ βββββββββββββββββββββββ
β (resolves peer IPs)
βΌ
βββββββββββββββββββββββ βββββββββββββββββββββββ
β 2. Initiates TCP β SYN packet β β
β Connection ββββββββββββββββββββΊβ β
β β SYN-ACK packet β β
β βββββββββββββββββββββ€ β
β β ACK packet β β
β ββββββββββββββββββββΊβ β
ββββββββββββ¬βββββββββββ ββββββββββββ¬βββββββββββ
β β
βΌ [TCP Connection ESTABLISHED] βΌ [TCP Socket OPEN]
Why TCP and Not UDP?
- Packet Re-ordering: UDP does not guarantee packet arrival order. A stream of block chunks or transactions would arrive fragmented, forcing applications to implement complex state sorting logic.
- Loss Prevention: If a single byte of a transaction or block is lost during transfer, the cryptographic hash will fail. TCP automatically detects packet drops and triggers re-transmissions.
ποΈ 2. Bootstrapping and DNS Seed Nodes
When a node starts for the first time (a "cold start"), it has no active peer IP addresses stored in its local database (peers.dat). To locate active nodes on the network, it uses a mechanism called DNS Seed Nodes.
- DNS Queries: The node queries hardcoded DNS seed addresses operated by community volunteers (e.g.,
seed.bitcoin.sipa.be,dnsseed.bluematt.me). - IP Resolving: These DNS seeds act as dynamic resolvers, returning a list of active IP addresses of nodes currently running on standard port
8333. - Peer Ingestion: The bootstrapping node stores these resolved IPs in its local state database and attempts to open standard TCP connections to them.
πΊοΈ 3. Default Network Port Layouts
To prevent cross-network peer pollution, different environments bind their listening sockets to different default ports:
| Network | Default TCP Port | Purpose |
|---|---|---|
| Mainnet | 8333 |
Production environment with real financial value. |
| Testnet3 | 18333 |
Deprecated developer playground with zero-value test coins. |
| Testnet4 | 48333 |
BIP 94 testnet with robust validation rule updates. |
| Signet | 38333 |
Controlled signature-based test network (BIP 325). |
| Regtest | 18444 |
Local private developer regression testing environment. |
- Configuring Custom Ports: Node operators can override these defaults in their
bitcoin.confusing theport=<n>configuration setting.
TeachMeBitcoin is an ad-free, open-source educational repository curated by a passionate team of Bitcoin researchers and educators for public benefit. If you found our articles helpful, please consider supporting our hosting and ongoing content updates with a clean donation: