I assume it's TCP, but is there some other software used to send and receive data? So how would I program a very simple C++ program that sends a test message to a node?

3 Answers 3


What protocol do bitcoin nodes use to talk to each other?

Most Bitcoin nodes will primarily use:

Layer Protocol
Application Layer Bitcoin Protocol
Transport Layer Transport Control Protocol (TCP)
Inter-Network Layer Internet Protocol (IPV4 and/or IPV6), Internet Control Message Protocol (ICMP)
Network Access Layer 1000BASE-T / IEEE 802.3ab Ethernet

Obviously there are dependencies on other protocols which are not used directly by the Bitcoin node application itself (e.g. DNS via a name resolution service). The application will be using operating system libraries that manage the lower three layers. The principle APIs used will be those related to opening and closing TCP connections and writing to and reading from those connections. Perhaps using some variant of the Berkeley "sockets" API.

Here's an example network packet

Wireshark decode of Bitcoin message packet

how would I program a very simple C++ program that sends a test message to a node?

Although the protocol isn't especially complicated, I personally wouldn't characterise writing a client as "very simple". That is, I wouldn't choose it as my first network protocol to write a client for.


Bitcoin nodes use a custom tcp-based protocol to communicate with each other. There's a work in progress to deploy a new one with some privacy enhancements.


Bitcoin uses TCP-IP protocol. The structure of data follows 2 parts:

  • Header
  • Payload

Header part

  • Magic Bytes (4 bytes) which indicates the selected network by nodes.
  • Command (12 bytes). You can see the command list here: https://github.com/bitcoin/bitcoin/blob/master/src/protocol.cpp#L14. Command field must be 12 bytes. So you can add null bytes to fullfill this field.
  • Payload size (4 bytes)
  • Checksum payload data (4 bytes). It is a double SHA256 of the payload data.

Payload part

The payload depends on the command type. You can have an overview of it from https://developer.bitcoin.org/devguide/p2p_network.html.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.