How the Internet works? TCP/IP
Tags: webdev, beginners, computerscience, basics
Published: 2024-06-07 10:45:25

Understanding how the Internet works is a fundamental step for anyone diving into the world of web development. Whether you're a beginner starting out or an experienced developer refreshing your knowledge, knowing the basics of the Internet provides a strong foundation to build upon.

In this article, we'll explore the core concepts of how the Internet operates, from the role of servers and clients to the intricacies of protocols and data transmission.

## What is the Internet? 🌐
The Internet is a **large network of computers** that communicate with each other. The whole idea of the Internet is to ensure that computers stay connected, regardless of any disruption. This idea was implemented using **decentralized** network. If one part of the network fails, data can be rerouted through other paths.

Network is two or more computers connected either physically or wirelessly. The Internet consists of numerous smaller networks connected together. These networks communicate through a variety of **protocols** and **hardware**.

Note, that computers that are connected to network are called **host**. This term you can often see in tutorials and other posts. Network hosts that share or receive information are classified as **server** or **client**.

The internet provides a wide range of services that facilitate communication, information access, commerce, entertainment, and more. For example: Email, World Wide Web(WWW), File Transfer.

Note, that **WWW is not the Internet**. World Wide Web (WWW) is a system of interconnected public webpages accessible through the Internet.

## Infrastructure of the Internet 📡

How exactly computer from your home and any other computer can reach computers from all over the world? Here are some of components that make this possible:

- **Routers and switches** are intermediary devices that manage the flow of data between and inside the networks. They ensure data packets find the most efficient path from the source to the destination.
- **Modem** is a computer hardware that transforms data from digital format to a format suitable for wireless transmission.
- **Inernet Service Provider (ISP)** is a company that manages high-performance routers that are linked together and can also access other ISP's routers.
- **Submarine cables** are _fiber optic_ cables laid on the ocean floor to connect continents, enabling high-speed internet communication between regions.

Note, that fiber optic cables are used to transfer data over long distances, as they have much lower attenuation compared to copper cables. If you want to dive deeper in how the submarine cables transfer data between continents, I recommend to watch [this short video](https://www.youtube.com/watch?v=M7stcJ65_X4).


![Infractructure of network in the Internet](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gjgsxxsrx8xma1ou63pm.JPG)

**Interesting fact:** The data that is transferred through the Internet moves with speed that is close to speed of light, that is why you can download your videos so fast.

## Data transfering through the Internet 🗃️

**TCP/IP** - suite of protocols that defines how information moves from sender to receiver. It is commonly used in the Internet. The key component of TCP/IP is **IP adress** (unique numerical adress assigned to every device on the Internet).

TCP/IP can be understood in terms of layers:
1. Application Layer - defines how application uses the network (for example HTTP for communication between browser and web-server)
2. ﻿﻿﻿Transport Layer - creates and contains conversations between application processes on host (Can be either TCP or UDP)
3. ﻿﻿Network Layer - data is being broken into **packages** in order to be delivered fast (uses IP headers so data from one host can find it's way to another host)
4. Data Link Layer - delivery of traffic on a single portion of computer network
5. Physical Layer (transmitting data through physical network connection)

**Packages or packets**, are small units of data transmitted over a network. When large amounts of data need to be sent, they are broken down into smaller packets for efficient transmission.

**Example of communication between web browser and web server on the Internet using TCP/IP:**

1. Client prepares HTTP request. (HTTP is the underlying protocol used for communication on the World Wide Web)
2. **TCP Header** is added to the HTTP request, forming a _segment_.
3. Segment is broken into packages. **IP Header**(mostly IP adresses of client and server) is added to each of packets. (When the packets arrive, host strips off IP Headers and reassembles the packets into original data).
4. **Ethernet Header** (Mostly MAC-adresses of computers in subnetwork) and Ethernet trailer are added to every packet. This creates Ethernet _frame_
5. Data is transmitted through physical connections.

![Typical TCP/IP packet structure](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rejt11o7axzq3u2fi2dw.JPG)

## Summary 📝

Internet is a complex network of interconnected computers that communicate through TCP/IP protocol.

Thank you for reading, leave a comment if you want and never stop learning!💖