<blockquote>
<p><strong>What protocol do bitcoin nodes use to talk to each other?</strong></p>
</blockquote>
<p>Most Bitcoin nodes will primarily use:</p>
<div class="s-table-container">
<table class="s-table">
<thead>
<tr>
<th>Layer</th>
<th>Protocol</th>
</tr>
</thead>
<tbody>
<tr>
<td>Application Layer</td>
<td><a href="https://en.bitcoin.it/wiki/Protocol_documentation" rel="noreferrer">Bitcoin Protocol</a></td>
</tr>
<tr>
<td>Transport Layer</td>
<td>Transport Control Protocol (TCP)</td>
</tr>
<tr>
<td>Inter-Network Layer</td>
<td>Internet Protocol (IPV4 and/or IPV6), Internet Control Message Protocol (ICMP)</td>
</tr>
<tr>
<td>Network Access Layer</td>
<td>1000BASE-T / IEEE 802.3ab Ethernet</td>
</tr>
</tbody>
</table>
</div>
<p>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 &quot;sockets&quot; API.</p>
<p>Here's an example network packet</p>
<p><a href="https://i.sstatic.net/WM8Mw.png" rel="noreferrer"><img src="https://i.sstatic.net/WM8Mw.png" alt="Wireshark decode of Bitcoin message packet" /></a><br />
<sup><a href="https://www.mecs-press.org/ijcnis/ijcnis-v10-n7/IJCNIS-V10-N7-4.pdf" rel="noreferrer">Source</a></sup></p>
<hr />
<blockquote>
<p><strong>how would I program a very simple C++ program that sends a test message to a node?</strong></p>
</blockquote>
<p>Although the protocol isn't especially complicated, I personally wouldn't characterise writing a client as &quot;very simple&quot;. That is, I wouldn't choose it as my first network protocol to write a client for.</p>

CC BY-SA 4.0
2023-08-07T09:18:12.433Z
2023-08-07T09:48:15.230Z
2023-08-07T09:48:15.230Z
RedGrittyBrick
<p>Bitcoin nodes use a <a href="https://en.bitcoin.it/wiki/Protocol_documentation" rel="nofollow noreferrer">custom tcp-based protocol</a> to communicate with each other. There's a work in progress to deploy a <a href="https://github.com/bitcoin/bips/blob/master/bip-0324.mediawiki" rel="nofollow noreferrer">new one</a> with some privacy enhancements.</p>

CC BY-SA 4.0
2023-08-06T21:44:34.617Z
2023-08-06T21:44:34.617Z
Davidson Souza
<p>Bitcoin uses TCP-IP protocol. The structure of data follows 2 parts:</p>
<ul>
<li>Header</li>
<li>Payload</li>
</ul>
<h3>Header part</h3>
<ul>
<li>Magic Bytes (4 bytes) which indicates the selected network by nodes.</li>
<li>Command (12 bytes). You can see the command list here: <a href="https://github.com/bitcoin/bitcoin/blob/master/src/protocol.cpp#L14" rel="nofollow noreferrer">https://github.com/bitcoin/bitcoin/blob/master/src/protocol.cpp#L14</a>. Command field must be 12 bytes. So you can add null bytes to fullfill this field.</li>
<li>Payload size (4 bytes)</li>
<li>Checksum payload data (4 bytes). It is a double SHA256 of the payload data.</li>
</ul>
<h3>Payload part</h3>
<p>The payload depends on the command type. You can have an overview of it from <a href="https://developer.bitcoin.org/devguide/p2p_network.html" rel="nofollow noreferrer">https://developer.bitcoin.org/devguide/p2p_network.html</a>.</p>

CC BY-SA 4.0
2023-08-16T07:42:55.607Z
2023-08-16T07:42:55.607Z
Loopite
<p>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?</p>

<full-node><protocol><p2p><c++><tcp>
What protocol do bitcoin nodes use to talk to each other?
apchrkey
# What protocol do bitcoin nodes use to talk to each other?

(Asked by: username_0 on 2023-08-06)

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?

**Tags:** full-node, protocol, p2p, c++, tcp


---

## 3 answers

### Answer by username_1 on 2023-08-07. Score: 5

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

Most Bitcoin nodes will primarily use:

| Layer | Protocol |
| --- | --- |
| Application Layer | [Bitcoin Protocol](https://en.bitcoin.it/wiki/Protocol_documentation) |
| 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](https://i.sstatic.net/WM8Mw.png)](https://i.sstatic.net/WM8Mw.png)  
[Source](https://www.mecs-press.org/ijcnis/ijcnis-v10-n7/IJCNIS-V10-N7-4.pdf)

---

> **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.


---

### Answer by username_2 on 2023-08-06. Score: 2

Bitcoin nodes use a [custom tcp-based protocol](https://en.bitcoin.it/wiki/Protocol_documentation) to communicate with each other. There's a work in progress to deploy a [new one](https://github.com/bitcoin/bips/blob/master/bip-0324.mediawiki) with some privacy enhancements.


---

### Answer by username_3 on 2023-08-16. Score: 1

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>.


---

