Until very recently (a few weeks ago, before I started LaunchSchool’s course on networking), I used to take the Internet for granted. I knew very little about this fascinating system that gives us access to so much information and gives us the superpower to communicate across any distance almost instantaneously. In the following paragraphs I will try to explain to the best of my ability how the Internet works, what happens when you open a web page on your browser and how information is sent from your device to far distant lands. Let’s get started!
The first thing we have to understand is that at a basic level, the Internet we all use on a day-to-day basis is a network of networks. In its most simple form, a network is represented by two devices that can communicate with each other and exchange data. For example, two computers connected to each other with the aid of a LAN cable form a network.
You can think of it as a string phone. I’m sure some of you did this when you were kids. The LAN cable is the string and the two cups are the two computers. This forms a basic network in which two people or devices can communicate with each other (as long as they speak a language they both understand).
Great, we have a basic network setup, but there are quite a few limitations. Right now we only have two participants in the conversation (transmission of data). What if we want to have more people join in on our conversation? The obvious solution would be to add more string phones. However simple this solution is, it will create a mess of strings and plastic cups. Just imagine that we have four participants. That would mean that each one of the participants would need a string phone for each other person joining in on the conversation. That quickly becomes out of hand if we want to have a lot of people joining in on our network.
Devices connected on a network have the same problem. Each device would need to have a separate LAN cable for each other device that it wants to communicate with. If we want to create efficient means of communication in a local area we need to implement what is known as a Local Area Network (LAN). In a LAN, instead of having each device connected to each other, we connect all of them to some kind of central device. This central device (usually a switch) will forward the information sent by one device to the designated receiver.
Now we can communicate with multiple devices, but we are still limited to those devices that are connected to our local network; we have a limited reach in terms of who we can communicate with. We want to be able to send and receive information from places far more distant than our home or office. How do we do that?
In order to fully achieve the ability to send information world wide we must find a way for our local network to communicate with other networks. This is achieved with the aid of routers, which are devices that can send information from our local network to other networks. Further building on our mental image of the Internet, all of the networks that form the Internet are connected by systems of routers that direct the traffic of information.
The underlying systems and processes are quite a bit more complex that what I have presented here, but the overall concept of networks connected to each other still applies.
Speaking the same language (Protocols)
Going back to the example given in the first part of the article, where the most simple form of a network can be thought of as two persons speaking over a string phone, we need to make sure that both participants speak the same language and follow the same rules of conversation. Devices connected on the Internet are the same, in order to understand each other, they must ‘speak’ the same language and follow the same communication rules, or more commonly known as Protocols.
Protocols are a set of rules regarding the exchange or transmission of data. During the transmission of data, more than one protocol is used due to the fact that each protocol handles different aspects of network communication or specific use-cases within a certain aspect. In the string phone example we can think of protocols as different sets of rules dictating the language spoken, the order in which participants will speak, the subject of the conversation etc.
Protocols can be grouped together based on what aspect of communication they seek to address. These groups are structured in layers that form the overall rules of communication.
The two most common models used for structuring protocols are the OSI model and the Internet Protocol Suite(TCP/IP).
The data that we want to send is structured with the aid of Protocols into Protocol Data Units (PDU). Each PDU further consists of a Header where protocol specific metadata is stored, a Data Payload where the actual data is stored and an optional Trailer or Footer.
The entire PDU from a layer is stored as the Data Payload in the layer below, thus providing the benefit of encapsulation. The process of encapsulating the PDU from a layer above as the Data Payload of the layer underneath can be thought of in the following way:
You have a message that you want to send. You are a very traditional kind of person so you decide to send that message in the form of a letter. In the context of the layered protocol system, the letter and its message will form the topmost layer. In order to send it to a particular person you have to put it in an envelope. On the envelope you will write your address and the recipient’s address. The envelope represents the second layer from top to bottom. We are taking the letter and encapsulating it within the envelope (Protocol Data Unit) a layer below. The letter is now the Data Payload of the envelope since it holds the information that we want to send. The address written on the envelope is our Header which holds the information needed for the letter to reach its destination. To recap:
- The letter is the Protocol Data Unit at the topmost layer.
- The letter is then encapsulated within the envelope which represents the Protocol Data Unit situated a layer below.
- The envelope now consists of a letter (the Data Payload) and the address written on it (the Header).
This process continues a few more times depending on the case. You can think of it as the envelope being further encapsulated in a box with additional details written on it. I hope this analogy has at least formed a basic mental model of how data is encapsulated when it is sent over the Internet.
However, there is one difference between the letter analogy and how information is actually sent over the Internet. Most of the time, the data that we want to send is too big to be sent in one package, thus it is transformed into very small pieces. So what would actually happen is that our letter would be cut up in very small pieces, packaged as mentioned above and sent over to the recipient, who will have to piece them back together in order to read the message that you’ve sent. On the Internet, the pieces of our letter are represented as bits which can be sent in the form of signals (electric, radio, light etc.)
As you can probably see by now, there is quite a lot of complexity happening in the background for even the most trivial task carried out on the Internet.
Accessing a webpage
Now that we have a surface level understanding of networks and protocols we can examine what exactly happens when we access a website. A most often found scenario of someone using the Internet is the following:
You open your web browser of choice, you type in the desired web address, hit enter and almost magically the website is displayed in your web browser. Let’s dive a little bit deeper and explore how the magic works. When you browse a website, it is the result of your web browser communicating with a server that holds the resources that will show up on your device’s screen. We can think of it as a request from your browser (the client) to the server. When we type in the web address and hit enter we are actually sending a request to the server to provide us with the resources necessary to visualize the website. Let’s break it down further. The address you type in is actually a URL (Uniform Resource Locator). URL’s are used to specify the location of the resources we are trying to access. Let’s analyze a URL and see what its components are and how they are used.
- The first part “http:” is the scheme which tells the browser how to access the resource.
- The second part “mywebsite.com” is the host and shows where the resource is located.
- The third (optional) part “:88” is the port number.
- The fourth (optional) part “/home” shows which resource on the host is being requested.
- The final part (optional) “?search=item” is a query string which is used to send data to the server.
URL’s are great for humans since they are very readable and quite easy to remember, but devices cannot actually find what you are looking for just by using the URL’s. Devices on the Internet are identified by an IP addresses, and with the aid of DNS (Distributed Name System), a URL is translated to an IP address that can be used to identify the particular server that holds the information we need.
That’s great, we now know that we can identify a server with the aid of an IP address, but there can be many applications running on that server, how do we know exactly which part of the server holds our desired resource or application? The answer is ports. Every application on your device or on a server has an associated port number which is used as a form of identification. The exact ‘address’ of an application over the Internet consists of an IP address and a port number. These two together form what is called a socket or a communication endpoint.
Continuing with the letter analogy, think of an IP address as the street address and the port number as the apartment number.
Now that the request has been sent, the server will process that request and send back a response. The response is always accompanied by a status code which signifies the status of the request. You have probably seen the big and bold ‘404’ number displayed when you cannot access a specific website. That message is basically saying that the resource you requested is no longer available. A successful request would be accompanied by the ‘200’ status code.
Upon receiving the response, your web browser processes and displays the information in a nice visual manner.
This is quite a simplified explanation of how the Internet works which I think will help create a mental model of the overall structure and process by which the Internet works.