DEV Community

Samyak Jain
Samyak Jain

Posted on • Updated on

What is the Internet?

The Internet is something that everyone knows about these days from any adult to any 2nd grader, it's such a common thing that we use every day, and yet know so less about it at least I was unaware of a lot of things regarding the internet

  • What are its origins?
  • Where does it come from?
  • Is it Tangible?
  • How does my phone send data wirelessly using the Internet?
  • How is it traveling through thin air?
  • How does the Internet reach me?
  • How does my ISP help me in that?

These are some questions out of a long list of questions I had regarding the internet. So, through this blog, I will try to answer those questions and hope to clear at least some common doubts people have regarding it.

This is going to be a long blog because I am going to try to explain every aspect of it in detail.

Here is a list of topics covered in this blog:

  1. Origins of Internet
  2. NCP
  3. Transition to TCP/IP architecture
  4. IP Addressing
  5. Classful addressing scheme
  6. Local Host
  7. Subnetting

Origins of Internet

I think the origin of the internet is the best topic to start with when understanding what the internet is.
So, the origins of the Internet can be traced back to the 1960s when the United States Department of Defense initiated a research project called ARPANET. So yeah earlier, the first name of the Internet as we know it today was ARPANET

So What was Used before ARPANET was introduced? What problem did ARPANET Solve?

So Before ARPANET, communication networks were often centralized, meaning there was a single point of control or a small number of central hubs.
In a centralized system, if a central point failed or was targeted, then the entire network could become disrupted.

ARPANET laid the foundation for the development of a decentralized and distributed network architecture.

ARPANET adopted a decentralized architecture where communication was distributed across multiple nodes (computers) rather than relying on a single central authority. Each node had a level of autonomy, and data could take multiple paths to reach its destination. This decentralized approach made the network more resilient and adaptable to failures.

ARPANET implemented packet-switching, a method in which data is broken down into smaller packets before transmission. Each packet could take different routes to reach its destination, where it would be reassembled.

During the time of ARPANET, the protocol which was used for transferring data was 'NCP'

If I have to explain how NCP and ARPANET used to work together then I'll say Imagine ARPANET as a large postal system designed to connect different regions and facilitate the exchange of letters between individuals and organizations.

Now, imagine that NCP is like a standardized letter format and a set of protocols that ensure proper formatting, addressing, and delivery of letters within the postal system.

NCP provides the rules and conventions for how letters (data) should be packaged, addressed, and transmitted over the ARPANET. It specifies how to break down a long letter into manageable pieces (packets) and how to reassemble them at the destination.

NCP (Network control protocol)

The primary purpose of NCP was to facilitate communication between computers on the ARPANET. It provided a basic mechanism for sending and receiving messages between different hosts connected to the network.
Sounds something like another protocol that we use these days right? TCP/IP?

So if we already had a protocol that was used for communication then why did we transition to the TCP/IP architecture?

Transition to TCP/IP architecture

Although NCP was working at that time there were many flaws in it.
I will explain one problem at a time and then the solution introduced by the TCP/IP architecture of that problem.

1. Scalability Issues in Uniquely Identifying Devices
So NCP was also uniquely identifying devices but it used a flat addressing structure. Let's try to understand this with an analogy.

Imagine a city without a well-organized addressing system. In this city, each building has a unique address, but there's no logical or hierarchical structure to how the addresses are assigned. For instance:

Building 1 might be on Elm Street.
Building 2 could be on Maple Avenue.
Building 3 might be on Oak Lane.

Now, think of these addresses as the host addresses in the context of NCP. Each host on the ARPANET had a unique identifier, but these identifiers didn't follow a structured or hierarchical pattern.

As the city grows, new buildings and streets are added. Allocating addresses becomes a challenge because there's no efficient way to organize them. With no hierarchy, the city's post office has to maintain an exhaustive list of every address, and it becomes increasingly difficult to manage as the city expands.

IP Addressing

IP (Internet Protocol) suggested a Hierarchical structure instead of Flat Structure

Let's see an Analogy of that too -

Imagine that the city adopts a new addressing system inspired by ZIP codes. In this system:

ZIP Code 10000 represents a large district or neighborhood.
ZIP Code 10010 might represent a smaller area within that district.
ZIP Code 10011 could pinpoint an even more specific location.

In the world of IP, think of the ZIP codes as the network portion of the IP address. The hierarchy allows for efficient allocation and routing

Currently, there are two versions of IP i.e IPv4 and IPv6 we will talk about IPv4 for now and will later come back to talk about IPv6

The idea was initially as we discussed to remove the need for a flat structure and have a hierarchal structure so the addresses are well organized. But it was not achieved instantly IP address also evolved.

So When IP was first introduced it was a 32-bit addressing scheme,
In this scheme, the 32-bit IP address was divided into two parts
Network Portion and the Host Portion, in this division the Network Portion had 1 Octet (8 Bits) and the rest were for hosts.

Now because only 8 Bits were reserved for the Network Portion, it meant that only 256 networks were possible (2 raise to the power 8)

But it was soon realized that 256 networks alone won't be enough, many small networks would be willing to join the ARPANET and it will be a waste to allocate such a big number of hosts in just 256 unique networks

Classful addressing scheme

To Overcome this issue Classful addressing scheme was introduced.
In the scheme, IP addresses were divided into classes to allocate address space based on the size of the network.

Basically, all we have is a 32-bit IP address in IPv4, which makes approximately 4.3 billion, now it's up to us how we use it efficiently. (In the Ipv4 version)

That's where Classful addressing came in, Classful addressing suggested that instead of just making 256 networks because of the previous architecture, let's divide the IP address according to use cases this way, we can allocate an approximate amount to the people according to their need

There were three primary classes:

Class A (1.0.0.0 to 126.0.0.0):

In Class A first octet or the first 8 bits were allocated for the network and the rest were allocated for hosts. Out of the first Octet, the first bit was fixed as 0, which was an Identifier for Class A addresses.
The remaining 7 Bits were used to create networks so there were 128 networks available and each network had approximately 16 million hosts.

There are 2 fewer networks available overall since IP Address 0.0.0.0 is set aside for broadcasting needs.

For usage as a loopback address while testing software, the IP address 127.0.0.1 is set aside. (Our good old LocalHost)

Let's talk a bit about this special use case of LocalHost

Local Host 127.0.0.1

So the loopback address 127.0.0.1 (localhost) is a reserved IP address used for testing and development.

So when a request is sent using the localhost address, it is sent to your own device as if it came from somewhere else.

The operating system's network stack recognizes the loopback address as a special case and ensures that the data doesn't leave the device's network interface.

While 127.0.0.1 is the most commonly used loopback address, the entire range 127.0.0.0 to 127.255.255.255 is reserved for loopback purposes. Other addresses within this range (e.g., 127.0.0.2, 127.0.0.3) can also be used for testing multiple loopback interfaces.

So when you write localhost:3000 you are actually hitting 127.0.0.1:3000, the term localhost actually works as a domain name to map 127.0.0.1, we will talk more about this mapping when we talk about DNS (Domain Name System).

While talking about localhosts there is one more component that is added in the localhost which is a port number like 3000, why is this port number added?

This port number is added to an IP address to identify multiple services going on, on one machine which is identified by an IP address.

If you have worked with both the backend and frontend, you must have seen that your frontend may run on localhost:5173 and your backend may run on localhost:3000, this helps the network to understand where exactly to send the information.

Now back to the discussion of classful addressing

Class B (128.0.0.0 to 191.255.0.0):
The first two octets identify the network, and the remaining two octets represent hosts.

If we talk about the first two octets, the first two bits are reserved to identify class B which is 10. The remaining are used for networks. So in class B, there are approximately 16,384
where each network can accommodate 165,534 hosts.

If you are not clear how I got the number 165,534 , then here is the math.
We used the first two bits to reserve the identifier of class B and we were left with 14 bits which makes up for 16,384 networks (2 raised to the power 14)

Now we are left with 2 more octets which were left for hosts allotment, so 2^16 - 2 = 165, 534

Here 2 are reserved addresses
Suited for medium-sized networks.

Class C (192.0.0.0 to 223.255.255.0):
The first three octets identify the network, and the last octet represents the hosts.
In this, the first 3 bits represent Class C which is 110 and the rest represents the networks so approximately 2,097,152 networks and hosts (254)
Designed for smaller networks.

Seems interesting right? But many problems arose over time in this scheming.

  1. Inefficient Use of Address Space - If you are a company and am assuming a very large company and you got assigned a Class A network, will you actually need 16 million hosts? This resulted in a lot of wastage of this exhaustible resource of IP addresses.

  2. The allocation of entire Class B address blocks to medium-sized organizations, even if they didn't need a large number of addresses, contributed to a phenomenon known as the "Class B explosion." This led to a significant increase in the number of entries in the global routing table of the routers.

  3. Management - Another problem was that it was not easy to administer such a big network even if I talk about a class B network it still has like 65 thousand networks.

To solve the management problem, people thought to divide those networks into sub-networks so that they are easy to maintain this is what we call subnetting.

Subnetting

Now before we go and understand subnet let's first again understand how it actually helps in maintaining IP addresses.

  1. Customized Configurations - Let's say your company has multiple departments like finance, development, sales, etc. Now, consider a scenario where the finance team should have access to a private database containing financial information about the company, which is hosted in the company's private network. However, the company does not want every department to have access to that database. This is where subnetting comes into play. Using subnetting, you divide your company's IP address space into multiple sub-networks or subnets. In the configuration of your private database, you set up access controls to allow only the specific subnet associated with the finance department to access that database.

  2. Decentralized System - With subnetting the network is somewhat decentralized, so if there is some problem in one subnet, it won't affect the whole system, and hence helps you to easily pinpoint where the error or bug has originated from.

  3. Easy Monitoring - Subnets make the monitoring more organized and easy to track, if I want to know how much traffic is there in one department (subnet) or how much data is being shared in one subnet I can easily filter.

Now that we know the why let's talk about the What and how.

What is a Subnet
Let's extend our city analogy to incorporate subnetting:

Original City Blocks (Networks):
Downtown (Network Portion): Addresses starting with "100" represent the Downtown area.

Uptown (Network Portion): Addresses starting with "200" represent the Uptown area.

Suburbs (Network Portion): Addresses starting with "300" represent the suburbs.

Subnetting within Neighborhoods:
Now, imagine that each neighborhood decides to further organize itself into smaller blocks or zones for specific purposes.

Downtown (Network Portion 100):

Block A (Subnet): Addresses within the range "100.1" to "100.50" are designated for residential use.
Block B (Subnet): Addresses within the range "100.51" to "100.100" are allocated for businesses.
Uptown (Network Portion 200):

Block X (Subnet): Addresses within the range "200.1" to "200.30" are for schools.
Block Y (Subnet): Addresses within the range "200.31" to "200.60" are for parks.

So what does a subnet look like? Well, the subnet is a 32-bit address that is present alongside an IP address, It is used to identify the devices that are present on the same subnet (I know a little confusing, but bear with me), So how a subnet is identified?

So a subnet is divided between the network portion and the host portion, The network portion is uneditable, but on the other side host portion tells us how many hosts are available in that subnet.

So again, what does a subnet look like? Here is an example of a subnet - 255.255.255.0 (Subnet of a Class C network).

Now why the number 255? Why not any other number?

So in a subnet mask, continuous 1 bits represent the network portion and the continuous 0 bits represent the host portion, so if you convert the 255.255.255.0 to a binary representation, it will look something like this 11111111.11111111.11111111.00000000

So if you look at the first octet (The first 8 bits) you will see its 11111111, and if you convert it to decimal representation it will be 255. So that's it, that's why a 255 represents a full octet or the network portion, I like to think of it like this because the octet contains all 1s then there are no more possible combinations left and that's the best way to show that it's uneditable.

Now 255 in an octet alone won't make sense, for example, 0.255.255.0 can't be called a subnet mask. Why? Because the subnet needs to be a contiguous stream of 0s and 1s you can't start 0s and then suddenly 1s and then back to 0s.

let me show this in binary representation -

  1. Given Subnet Mask - 255.255.255.0 Binary - 11111111.11111111.11111111.00000000

This will be a subnet because first there are continuous, 1s, and then 0s, and yes on the left side , it should always be 1s and on the right side 0s.

  1. Given Subent Mask - 255.207.255.0 Binary - 11111111.11001111.11111111.00000000

This can't be called a subnet, why? because it's not contiguous, we did start with continuous 1s but then in the middle, it started to have 0s and then again 1s.

Now that we have understood the What let's understand the how.

How does subnetting work in a network of subnets?

Let's say I have a Class C Network and because in Classful addressing you get the whole network then I'll assume my IP address is 192.168.1.0 so the range will be 192.168.1.0 to 192.168.1.255.

Now in classful addressing you have to keep the same size for all of your subnets, so if your finance team has more people than the sales team, you will have to make the same host size subnet for the sales team as well because the finance team has more people.

So let's say I want to make 4 subnets of my network.

Now am using a Class C network whose default subnet mask is 255.255.255.0, so if I want to have subnets in my network then my subnet will look like this - 255.255.255.192.
Why?

Let's look at the binary representation of 255.255.255.0
Binary - 11111111.11111111.11111111.00000000

Here I can see that I have 8 bits in the network portion so if I want to make space for 4 subnets then I'll have to reserve 2 bits in the given 8bits of 0s, which gives us (2 raise to the power of 2) 4 subnets, and hence our subnet mask will look like 11111111.11111111.11111111.11000000 - 255.255.255.192

This left us with 6 bits, so 2 raises to the power 6 gives us 64 hosts per subnet.

So this gives us the following range of addresses taking 192.168.1.0 as the base address-

Subnet 1: 192.168.1.0 to 192.168.1.63
Subnet 2: 192.168.1.64 to 192.168.1.127
Subnet 3: 192.168.1.128 to 192.168.1.191
Subnet 4: 192.168.1.192 to 192.168.1.255

Now how does communication work between these subnets?
So a router works as a gateway between subnets, it contains the subnet mask and the reserved gateway IP address, so when a request is made from a device of a subnet, let's say device A makes a request to device B on the same subnet, so the request will go through router first.

The router will see hmmm, this request came from Device A who wants to send this to some Device B. The router checks the IP Address of Device B which is sent by Device A, and checks if it in the same subnet. How does a router do that? Because it already has the subnet mask of that subnet. If it is in the same subnet it routes the information to that device otherwise routes the information to another router. Now how does the router find which router it needs to send it to? That is another big topic and should be kept seperately I suppose.

Now we have only covered Classful addressing in this blog, in the next blog we will talk about Classless Inter-Domain Routing, remember this is only 1 reason why we shifted from NCP to TCP/IP architecture, once this is completed we will go to the next reason.

Thanks for reading this far 😁

Top comments (1)

Collapse
 
thecatfix profile image
John Shelburne

Thank you