<blockquote>
<p>I have no idea what a &quot;network&quot; really is. I googled and read about LAN/WAN. Are these the types of network we're talking about?</p>
</blockquote>
<p>No. A network is really just &quot;a group of connected things&quot;. One example is indeed a LAN network through which multiple computers that are physically close to each other (a home, an office, ...) are connected to each other. The Internet is also an example of a network - one built up of smaller and very distinct networks like LANs.</p>
<p>But networks can be many more things than that. The group of people you know and hang out with is considered a network too. An electrical circuit inside a machine is sometimes called a network. I bring up these examples, because the word &quot;network&quot; in a computer setting often evokes the mental image of physical interconnections between computers - and while that is one example, the Bitcoin network is something fundamentally different.</p>
<p>The Bitcoin peer-to-peer network consists of Bitcoin nodes - pieces of <strong>software</strong>, not hardware. I could be running two nodes on my own computer, and they could be connected to each other - or not; they could also both just be connected to far away nodes elsewhere in the world. In fact, these connections don't even need to be established over the Internet. There have been projects to connect Bitcoin nodes over mesh networks, and you could arguably also consider the Blockstream <a href="https://blockstream.com/satellite/" rel="noreferrer">satellite service</a> to be part of this network.</p>
<p>So bottom line, the Bitcoin network consists of pieces of software talking to each other. How they talk to each other can differ, though most commonly, it is <strong>TCP/IP connections</strong> over the public Internet or <strong>over <a href="https://www.torproject.org/" rel="noreferrer">Tor</a></strong>. These connections are somewhat similar to the connection your browser makes to <a href="https://bitcoin.stackexchange.com">stackexchange.com</a> to show you this answer, but instead of it just being many clients (browsers) talking to one server (stackexchange), it is all nodes that are equal - they are <strong>peers</strong>. No servers and clients; there are just nodes, and they each connect to one or multiple other nodes. Certainly some are more powerful or better connected than others, but none have a privileged position w.r.t. other nodes.</p>
<blockquote>
<p>How do these &quot;networks&quot; work, how are they distinct?</p>
</blockquote>
<p>This is where it gets interesting. Bitcoin, and similar things, follow a trust-minimized design. At least if you run a fully-validating node (like Bitcoin Core), your node will generally not trust anything other nodes tell it. They will exchange blocks, and transactions, and other things, but whatever your node receives it will validate independently to the extent possible. This includes very strict validity rules for blocks. Your node will only accept blocks that follow the exact rules implemented in the software.</p>
<p>The simple answer to your question is that Bitcoin and altcoin nodes have different rules, and simply <strong>won't accept each others blocks</strong>. If a node were to be <em>only</em> connected to nodes with different rules, it would be isolated, and not be able to learn about new Bitcoin blocks; it needs at least one connection to an honest like-minded node. To make sure that doesn't happen, nodes will detect the situation where their peers give them blocks they consider invalid, and when that happens, more aggressively look for more nodes to connect to, and possibly disconnect existing ones if they really seem to have a different idea. In practice, this quickly teaches nodes on both sides after a fork to shun the other side.</p>
<blockquote>
<p>Certainly if I download bitcoin core and start running a full node it will start connecting me to other nodes in the bitcoin network. How does that process actually go down?</p>
</blockquote>
<p>Bitcoin Core specifically has a number of mechanisms that control connections:</p>
<ul>
<li>It maintains a database (called &quot;addrman&quot;) with IP addresses (and Tor addresses, if that's in use) of known other Bitcoin nodes, together with some statistics and whether or not it has made a connection to it. New peers to connect to are drawn from this database. At most 10 connections are made, in order not to overload the network. This database is fed new information through:
<ul>
<li>Nodes gossip IP addresses of other nodes (the  <a href="https://developer.bitcoin.org/reference/p2p_networking.html#addr" rel="noreferrer"><code>addr</code></a> P2P message) to each other.</li>
<li>A few <a href="https://stackoverflow.com/a/41708702/8342274">DNS seeds</a> are hardcoded that can be asked for more IP addresses if needed. This is only when not enough connections can be established after some time, and typically only needed the first time the client runs. After that, nodes autonomously find more peers to connect to.</li>
<li>As a very last resort, if DNS querying doesn't result in decent network connections, Bitcoin Core also has a list of hardcoded IP addresses to connect to.</li>
</ul>
</li>
<li>The user can manually specify peers to connect to, using the <code>connect=</code> or <code>addnode=</code> configuration file options, or the <code>addnode</code> RPC command.</li>
<li>Nodes can accept incoming connections from other nodes too (there is a limit on this too; by default 125 connections, and when it's full some rules will prioritize peers from others).</li>
</ul>
<blockquote>
<p>how would nodes connect to the network without running bitcoin core?</p>
</blockquote>
<p>Other implementations have their own mechanisms, but there is a wide spectrum - all the way from just connecting to the wallet provider's server, to learning about peers and connecting to them like Bitcoin Core does.</p>
<blockquote>
<p>Supposed I wanted to write some code to develop my own bitcoin client. What was that code look like?</p>
</blockquote>
<p>That really depends on what you want to do. There are libraries in many languages that implement the P2P protocol that lets you talk to other nodes, or you could start from scratch just following existing <a href="https://developer.bitcoin.org/reference/p2p_networking.html" rel="noreferrer">protocol documentation</a> and Bitcoin Improvement Proposals (<a href="https://github.com/bitcoin/bips" rel="noreferrer">BIPs</a>) that affect the P2P protocol. Remember, there is no authority in Bitcoin that can tell you exactly what &quot;the&quot; protocol is; proposals are made, and software dedvelopers implement them or don't. You'll want to test things, by not immediately dealing with the Bitcoin mainnet, but first try on the <a href="https://en.bitcoin.it/wiki/Testnet" rel="noreferrer">Bitcoin testnet</a> or the newer &quot;<a href="https://en.bitcoin.it/wiki/Signet" rel="noreferrer">signet</a>&quot; test network.</p>

CC BY-SA 4.0
2021-03-12T17:22:01.677Z
I really appreciate the length you went to answering my question. I think you were ability to correctly identify my ability level with this topic.
Prince M
CC BY-SA 4.0
2021-03-12T05:54:26.270Z
2021-03-12T09:54:26.087Z
2021-03-12T09:54:26.087Z
Pieter Wuille
<p>I have little background in computing, have been studying bitcoin for intellectual stimulation. I have learned a lot and I understand quite a bit regarding the function of nodes, the validations they perform, and their importance to bitcoin functionality - but I want to understand more about how nodes in the network &quot;connect&quot;. I read <a href="https://bitcoin.stackexchange.com/questions/53938/how-does-one-node-connect-to-other-nodes">this</a> question and it didn't help.</p>
<p>I have no idea what a &quot;network&quot; really is. I googled and read about LAN/WAN. Are these the types of network we're talking about?</p>
<p>For example - if I owned bitcoin before the bitcoin cash fork, it is my understanding that I could choose to send my coin as bitcoin, or send it as bitcoin cash, it just depends which network I send the transaction to (kind of, over simplyfing here). So if I send it from a bitcoin wallet it will get broadcasted to the bitcoin network and stay on the bitcoin blockchain, or if I send it from a bcash wallet it will get formatted however bcash formats tx messages and get broadcast to the bcash network. How do these &quot;networks&quot; work, how are they distinct? Where could I look to read more about this.</p>
<p>Certainly if I download bitcoin core and start running a full node it will start connecting me to other nodes in the bitcoin network. How does that process actually go down? How do distinct networks stay separate? I have read about things &quot;dishonest nodes&quot; can do, so without downloading something like bitcoin core (which I assume automatically implements standard protocol for node behavior) how would nodes connect to the network without running bitcoin core?</p>
<p>Hopefully someone can make sense of my question, I understand it may not be very clear but that is because I don't even know enough to form a good question. I don't have any terminology here.</p>
<p>Edit: maybe this will help understand. Supposed I wanted to write some code to develop my own bitcoin client. What was that code look like?</p>

<network>
How do network nodes "connect" - amateur level
Prince M
# How do network nodes "connect" - amateur level

(Asked by: username_0 on 2021-03-12)

I have little background in computing, have been studying bitcoin for intellectual stimulation. I have learned a lot and I understand quite a bit regarding the function of nodes, the validations they perform, and their importance to bitcoin functionality - but I want to understand more about how nodes in the network "connect". I read [this](https://bitcoin.stackexchange.com/questions/53938/how-does-one-node-connect-to-other-nodes) question and it didn't help.

I have no idea what a "network" really is. I googled and read about LAN/WAN. Are these the types of network we're talking about?

For example - if I owned bitcoin before the bitcoin cash fork, it is my understanding that I could choose to send my coin as bitcoin, or send it as bitcoin cash, it just depends which network I send the transaction to (kind of, over simplyfing here). So if I send it from a bitcoin wallet it will get broadcasted to the bitcoin network and stay on the bitcoin blockchain, or if I send it from a bcash wallet it will get formatted however bcash formats tx messages and get broadcast to the bcash network. How do these "networks" work, how are they distinct? Where could I look to read more about this.

Certainly if I download bitcoin core and start running a full node it will start connecting me to other nodes in the bitcoin network. How does that process actually go down? How do distinct networks stay separate? I have read about things "dishonest nodes" can do, so without downloading something like bitcoin core (which I assume automatically implements standard protocol for node behavior) how would nodes connect to the network without running bitcoin core?

Hopefully someone can make sense of my question, I understand it may not be very clear but that is because I don't even know enough to form a good question. I don't have any terminology here.

Edit: maybe this will help understand. Supposed I wanted to write some code to develop my own bitcoin client. What was that code look like?

**Tags:** network


---

## 1 answers

### Answer by username_1 on 2021-03-12. Score: 8 | Accepted answer

> I have no idea what a "network" really is. I googled and read about LAN/WAN. Are these the types of network we're talking about?

No. A network is really just "a group of connected things". One example is indeed a LAN network through which multiple computers that are physically close to each other (a home, an office, ...) are connected to each other. The Internet is also an example of a network - one built up of smaller and very distinct networks like LANs.

But networks can be many more things than that. The group of people you know and hang out with is considered a network too. An electrical circuit inside a machine is sometimes called a network. I bring up these examples, because the word "network" in a computer setting often evokes the mental image of physical interconnections between computers - and while that is one example, the Bitcoin network is something fundamentally different.

The Bitcoin peer-to-peer network consists of Bitcoin nodes - pieces of **software**, not hardware. I could be running two nodes on my own computer, and they could be connected to each other - or not; they could also both just be connected to far away nodes elsewhere in the world. In fact, these connections don't even need to be established over the Internet. There have been projects to connect Bitcoin nodes over mesh networks, and you could arguably also consider the Blockstream [satellite service](https://blockstream.com/satellite/) to be part of this network.

So bottom line, the Bitcoin network consists of pieces of software talking to each other. How they talk to each other can differ, though most commonly, it is **TCP/IP connections** over the public Internet or **over [Tor](https://www.torproject.org/)**. These connections are somewhat similar to the connection your browser makes to [stackexchange.com](https://bitcoin.stackexchange.com) to show you this answer, but instead of it just being many clients (browsers) talking to one server (stackexchange), it is all nodes that are equal - they are **peers**. No servers and clients; there are just nodes, and they each connect to one or multiple other nodes. Certainly some are more powerful or better connected than others, but none have a privileged position w.r.t. other nodes.

> How do these "networks" work, how are they distinct?

This is where it gets interesting. Bitcoin, and similar things, follow a trust-minimized design. At least if you run a fully-validating node (like Bitcoin Core), your node will generally not trust anything other nodes tell it. They will exchange blocks, and transactions, and other things, but whatever your node receives it will validate independently to the extent possible. This includes very strict validity rules for blocks. Your node will only accept blocks that follow the exact rules implemented in the software.

The simple answer to your question is that Bitcoin and altcoin nodes have different rules, and simply **won't accept each others blocks**. If a node were to be *only* connected to nodes with different rules, it would be isolated, and not be able to learn about new Bitcoin blocks; it needs at least one connection to an honest like-minded node. To make sure that doesn't happen, nodes will detect the situation where their peers give them blocks they consider invalid, and when that happens, more aggressively look for more nodes to connect to, and possibly disconnect existing ones if they really seem to have a different idea. In practice, this quickly teaches nodes on both sides after a fork to shun the other side.

> Certainly if I download bitcoin core and start running a full node it will start connecting me to other nodes in the bitcoin network. How does that process actually go down?

Bitcoin Core specifically has a number of mechanisms that control connections:

* It maintains a database (called "addrman") with IP addresses (and Tor addresses, if that's in use) of known other Bitcoin nodes, together with some statistics and whether or not it has made a connection to it. New peers to connect to are drawn from this database. At most 10 connections are made, in order not to overload the network. This database is fed new information through:
  + Nodes gossip IP addresses of other nodes (the [`addr`](https://developer.bitcoin.org/reference/p2p_networking.html#addr) P2P message) to each other.
  + A few [DNS seeds](https://stackoverflow.com/a/41708702/8342274) are hardcoded that can be asked for more IP addresses if needed. This is only when not enough connections can be established after some time, and typically only needed the first time the client runs. After that, nodes autonomously find more peers to connect to.
  + As a very last resort, if DNS querying doesn't result in decent network connections, Bitcoin Core also has a list of hardcoded IP addresses to connect to.
* The user can manually specify peers to connect to, using the `connect=` or `addnode=` configuration file options, or the `addnode` RPC command.
* Nodes can accept incoming connections from other nodes too (there is a limit on this too; by default 125 connections, and when it's full some rules will prioritize peers from others).

> how would nodes connect to the network without running bitcoin core?

Other implementations have their own mechanisms, but there is a wide spectrum - all the way from just connecting to the wallet provider's server, to learning about peers and connecting to them like Bitcoin Core does.

> Supposed I wanted to write some code to develop my own bitcoin client. What was that code look like?

That really depends on what you want to do. There are libraries in many languages that implement the P2P protocol that lets you talk to other nodes, or you could start from scratch just following existing [protocol documentation](https://developer.bitcoin.org/reference/p2p_networking.html) and Bitcoin Improvement Proposals ([BIPs](https://github.com/bitcoin/bips)) that affect the P2P protocol. Remember, there is no authority in Bitcoin that can tell you exactly what "the" protocol is; proposals are made, and software dedvelopers implement them or don't. You'll want to test things, by not immediately dealing with the Bitcoin mainnet, but first try on the [Bitcoin testnet](https://en.bitcoin.it/wiki/Testnet) or the newer "[signet](https://en.bitcoin.it/wiki/Signet)" test network.

> **Comments:**
> **username_0**: I really appreciate the length you went to answering my question. I think you were ability to correctly identify my ability level with this topic.  

---

