DEV Community

Cover image for Understanding the TCP/IP Model: How Do Machines Communicate Over a Network?
HEAVYLOCK
HEAVYLOCK

Posted on

Understanding the TCP/IP Model: How Do Machines Communicate Over a Network?

HEAVYLOCK — NETWORKING FUNDAMENTALS

Understanding the mechanisms that allow machines to communicate across networks.


Why Learn the TCP/IP Model?

Whenever you visit a website, use an application, or connect to a remote server, your computer exchanges data with other machines.

But how does this data reach its destination? How does it travel across multiple networks? And how does it reach the correct program on the destination machine?

To understand this, you need to learn the TCP/IP model.

💡 Key Concept

The TCP/IP model describes how data is prepared, transported, and received across a network.

It provides an essential foundation for understanding networking, Linux, server administration, and DevOps.


🟢 LEVEL 1 — UNDERSTANDING THE BASICS

01. The Four Layers of the TCP/IP Model

The TCP/IP model is organized into four layers. Each layer has a specific responsibility in network communication.

  • Layer 4 — Application: Defines the communication rules used by applications.
  • Layer 3 — Transport: Handles data transport between programs.
  • Layer 2 — Internet: Allows data to be routed across different networks.
  • Layer 1 — Network Access: Handles data transmission over a local network.

⚠️ About the Numbering

The layer numbers used in this article (1 to 4, from bottom to top) are a teaching convention. The TCP/IP specifications do not assign official numbers to the layers, so other courses may number them differently.

To understand how these layers work, imagine that you want to visit a website.

Layer 4 — Application

This is where applications use protocols to communicate.

A protocol is a set of rules that defines how machines exchange information.

Here are some examples:

  • HTTP: Allows a browser to request resources from a web server.
  • HTTPS: Provides the same communication with TLS encryption.
  • DNS: Resolves domain names to their associated IP addresses.
  • SSH: Allows remote connections to a server.

These protocols define the rules applications must follow to communicate.

Layer 3 — Transport

This layer transports data between programs running on communicating machines.

It mainly uses two protocols:

  • TCP: Provides reliable and ordered data delivery.
  • UDP: Transports data without guaranteeing delivery or ordering.

It also uses ports to identify destination applications or services.

🔎 Example

Port 443 is commonly used for HTTPS.

Layer 2 — Internet

This layer allows data to reach its destination across different networks.

It mainly uses the IP (Internet Protocol).

Each packet contains information such as:

  • Source IP address: The sender's address.
  • Destination IP address: The recipient's address.

Routers use these addresses to determine where packets should be forwarded.

This layer also includes ICMP (Internet Control Message Protocol).

ICMP does not carry application data. It is used to send error messages and diagnostic information, for example when a destination cannot be reached.

🔎 Example

The ping command relies on ICMP to check whether a machine responds.

Layer 1 — Network Access

This layer handles data transmission over the network to which an interface is connected.

It is particularly involved in local network communication.

Some technologies and concepts found here include:

  • Ethernet: A technology used for wired connections.
  • Wi-Fi: A technology used for wireless connections.
  • MAC addresses: Addresses used to identify network interfaces at the local network level.

🟡 LEVEL 2 — UNDERSTANDING HOW DATA TRAVELS

Now that you understand the four layers, let's see how they work together.

02. How Does Data Travel Through the Four Layers?

Imagine that you want to visit a website hosted on a remote server.

Your browser needs to send an HTTP or HTTPS request to that server.

To do this, data travels through the four layers of the TCP/IP model.

It starts at the Application layer and moves progressively down to the Network Access layer.

This process is called encapsulation.

At each stage, the corresponding layer adds information required for communication.

Here's how it works:

  1. Application: Prepares the data that the browser wants to send.
  2. Transport: Adds information such as source and destination ports.
  3. Internet: Adds source and destination IP addresses.
  4. Network Access: Adds the information required for transmission over the local network link, including MAC addresses in an Ethernet frame.

The data is now ready to be transmitted over the network.

When the server receives it, the reverse process takes place: decapsulation.

Each layer examines the information relevant to it and passes the remaining data to the layer above.

This process continues until the data reaches the destination application.

TCP/IP model diagram: encapsulation on the sender, transmission over the physical medium, decapsulation on the receiver

Figure 1 — Data travels down the four layers on the sender (encapsulation), crosses the physical medium, then goes back up on the receiver (decapsulation).

How to Read the Diagram

The diagram may look busy at first. Read it in five steps.

  1. Find the two machines. Sender is on the left and Receiver is on the right. The sender is the machine that sends the data, and the receiver is the machine that receives it.

  2. Read the central block from top to bottom. It lists the four layers of the TCP/IP model. The left side gives the layer number and name. The right side gives examples of protocols or technologies found in that layer.

  3. Follow the left arrow, labeled "Encapsulation". It points downward, from the Application layer to the Network Access layer. This is the path the data follows on the sender. At each layer, information is added around the data.

  4. Follow the arrows at the bottom, "Transmission over physical medium". Once the data has gone through all the layers, it is sent as signals over a cable or over radio waves. It then reaches the receiver.

  5. Follow the right arrow, labeled "Decapsulation". It points upward, from the Network Access layer back to the Application layer. On the receiver, each layer removes the information that was added by the same layer on the sender, until the original data is recovered.

🔎 Remember

The sender goes down through the layers, the receiver goes up. The same four layers exist on both machines: each layer on the sender communicates with the same layer on the receiver.

The data also changes name as it goes down the layers:

  • Application: data (message)
  • Transport: segment (TCP) or datagram (UDP)
  • Internet: packet
  • Network Access: frame (for example, an Ethernet frame)

⚠️ What the Diagram Simplifies

The diagram shows a direct path between the sender and the receiver. In reality, data usually crosses several routers on the way. This is explained in section 04.

💡 Key Concept

Encapsulation prepares data for transmission. Decapsulation allows the receiving machine to progressively recover the original data.

03. IP Addresses, MAC Addresses, and Ports: Why Do We Need Three Different Identifiers?

These three elements have different responsibilities.

IP Address

It identifies a network interface and allows a destination to be reached across different networks.

MAC Address

It identifies a network interface at the local network communication level.

Port

It identifies the destination service or program on a machine.

Consider this example:

203.0.113.10:443
Enter fullscreen mode Exit fullscreen mode
  • 203.0.113.10: Destination IP address.
  • 443: Destination port commonly used for HTTPS.

🔎 Remember

The IP address helps route data to the destination machine, while the port helps deliver it to the correct service.

04. How Does Data Travel Across Multiple Networks?

Imagine that your computer wants to communicate with a server that is not on your local network.

It needs to go through a router to reach other networks.

But how does the router know where to send the data?

When a packet arrives, the router examines its destination IP address.

It then checks its routing table to determine the appropriate destination or next hop.

The router prepares a new frame suitable for the next network link.

⚠️ Important Point

MAC addresses generally change at each router hop, while IP addresses normally remain the same from end to end.

However, there are exceptions, especially when a NAT mechanism modifies IP addresses.


🔴 LEVEL 3 — EXPLORING HOW IT WORKS

05. TCP vs UDP: Why Are There Two Transport Protocols?

TCP and UDP both transport data between applications.

However, they do not work in the same way.

TCP — Reliable Transport

Before transmitting data, TCP establishes a connection between the two endpoints.

To do this, it uses a mechanism called the Three-Way Handshake.

Here's how it works:

  1. SYN: The client requests a connection.
  2. SYN-ACK: The server accepts the request and responds.
  3. ACK: The client acknowledges the response.

The connection is now established.

TCP then uses several mechanisms to ensure reliable transmission:

  • Sequence numbers: Track the order of transmitted data.
  • Acknowledgments: Confirm that data has been received.
  • Retransmissions: Recover lost data.

TCP is used by SSH, and by HTTP and HTTPS in their most common versions.

UDP — Transport Without Delivery Guarantees

Unlike TCP, UDP does not establish a connection beforehand.

It sends datagrams directly without built-in acknowledgment or retransmission mechanisms.

This makes it simpler and lighter.

UDP is commonly used for:

  • Traditional DNS queries.
  • Some online games.
  • Real-time audio and video communications.

UDP allows applications to avoid some of TCP's mechanisms and manage their own transmission requirements.

TCP vs UDP in short

TCP:

  • Establishes a connection.
  • Provides reliable delivery.
  • Guarantees ordered delivery.
  • Uses acknowledgments.

UDP:

  • Does not establish a connection beforehand.
  • Does not guarantee delivery.
  • Does not guarantee ordering.
  • Has no built-in acknowledgment mechanism.

The choice between TCP and UDP depends on the application's requirements.


Conclusion

The TCP/IP model helps us understand how applications communicate across a network.

Each layer has a specific responsibility:

  • Application: Defines communication rules.
  • Transport: Transports data between applications.
  • Internet: Handles routing using IP addresses.
  • Network Access: Handles transmission over the local network.

These layers work together to allow data to travel from one application to another, even when the two machines are connected to different networks.

Understanding this process is an essential first step toward learning how to administer and troubleshoot network infrastructure.


HEAVYLOCK LAB — FROM THEORY TO PRACTICE

THEORY IS NOT ENOUGH. UNDERSTAND HOW SYSTEMS WORK.

Understanding a mechanism does not necessarily mean knowing how it actually works on a machine.

To achieve that, you need to experiment.

That's why this article has an associated practical laboratory on GitHub.

In this Linux laboratory, you will be able to observe the mechanisms covered in this article, interact with networking tools, and examine how the different layers work.

But the objective goes further.

You will also deliberately introduce failures in a controlled environment.

Why?

Because a functioning system shows us what it can do.

A system we break helps us understand what makes it work.

What You Will Learn

  • Observe normal system behavior.
  • Modify specific parameters.
  • Deliberately introduce errors.
  • Identify their consequences.
  • Understand their causes.
  • Restore normal operation.

📖 Before You Start

Before practicing, read the README of my GitHub profile. It presents the HEAVYLOCK space: the topics covered, how the articles are structured in three levels (beginner, intermediate, advanced), and the kind of practical resources published on GitHub.

👉 Read the HEAVYLOCK README on my github

A few things to know before you open the lab:

  • Available now: the hands-on lab for this article, with commands to run, expected results, and deliberate failures to investigate.
  • Coming later: configuration scripts for Linux, networking, web servers and DevOps, and premium production-ready packs. They will be added as the project grows, so the README describes more than what is published today.
  • What you need: a Linux machine, virtual machine or VPS (Debian or Ubuntu unless the lab says otherwise). You don't need Linux on your personal computer: a VPS or a virtual machine is enough, whether you use Windows, macOS or Linux.
  • Use a test machine. The lab breaks things on purpose, so never run it on a production server.

Once you have read the README, come back and open the lab below.

🧪 Access the Laboratory

🇬🇧 English version | 🇫🇷 French version

HEAVYLOCK — Networking Labs

github.com/heavy-lock/networking-labs

🌍 Available in English and French

Are you a French-speaking reader?

Don't worry! Each laboratory is available in English and French. You can choose the version that suits you best directly from the GitHub repository.

🇬🇧 English version | 🇫🇷 French version


THE HEAVYLOCK METHOD

Every laboratory follows four fundamental steps.

01 — UNDERSTAND

Understand the mechanisms and how they work.

02 — EXPERIMENT

Interact with the system and observe its real behavior.

03 — BREAK

Deliberately introduce failures to understand system limitations.

04 — TROUBLESHOOT

Identify the root causes of problems and restore normal operation.


🔔 What's Next

This article is the first of the Networking Fundamentals series. Next up: IPv4 addressing and subnet calculations.

  • Follow me on Dev.to to get each new article as soon as it is published.
  • Star the repository on GitHub to find new labs when they are added.

HEAVYLOCK

Build locks. Learn how they break!

Top comments (0)