OSI Model Layer 4 – The Transport Layer Explained (TCP vs UDP)

 When learning about networking, one of the most critical layers to understand in the OSI Model is the Transport Layer (Layer 4). This layer acts as a bridge between the applications you use daily (Layer 7) and the network infrastructure that actually delivers data (Layers 1–3).

Two major protocols dominate this layer:

  • TCP (Transmission Control Protocol) – reliable, connection-oriented.

  • UDP (User Datagram Protocol) – fast, connectionless.


The Transport Layer
The Transport Layer.


In this guide, we’ll explore the Transport Layer in the OSI model, break down the TCP and UDP headers, and explain why this layer is so important for both network engineers (CCNA, CCNP, CCIE prep) and everyday internet users.


🔹 What is the Transport Layer (Layer 4 of the OSI Model)?

The Transport Layer is responsible for end-to-end communication between applications running on different devices across a network.

It ensures that:

  • Data gets delivered to the correct application using port numbers.

  • Data can be reliable (via TCP) or fast and lightweight (via UDP).

👉 Think of the Transport Layer as the delivery manager of a shipping company:

  • The Network Layer (IP) delivers packages to the right house (IP address).

  • The Transport Layer ensures the package is handed to the correct person inside (application/port).

🔹 TCP Header (Connection-Oriented)

TCP is the backbone of reliable internet communication. Its header contains several fields that ensure data arrives accurately and in order.

Key Fields in the TCP Header:

  • Source & Destination Ports → Identify sending and receiving applications.

  • Sequence & Acknowledgment Numbers → Keep track of data and confirm receipt.

  • Flags (SYN, ACK, FIN, RST, PSH, URG) → Control connection states and data flow.

  • Window Size → Enables flow control.

  • Checksum → Detects errors in data.

📌 The minimum TCP header is 20 bytes, but it can grow up to 60 bytes with optional fields.

👉 Because of these features, TCP is called a connection-oriented protocol — it sets up a session before sending data and ensures error recovery.


TCP Header
TCP Header


🔹 UDP Header (Connectionless)

Unlike TCP, UDP is lightweight and faster. Its header is only 8 bytes, containing just four fields:

  • Source & Destination Ports

  • Length (size of header + data)

  • Checksum (basic error detection)

👉 UDP does not guarantee delivery or order, making it ideal for real-time applications like:

  • Online gaming

  • Live video streaming

  • Voice-over-IP (VoIP)




UDP Header
UDP Header


🔹 Primary Functions of the Transport Layer

1. Multiplexing with Port Numbers

The most important job of the Transport Layer is to ensure data reaches the correct application. This is done with source and destination ports:

  • Source Port → The application on the sender’s device.

  • Destination Port → The application on the receiver’s device.

📌 Example:

  • Web server listens on port 80 (HTTP) or 443 (HTTPS).

  • FTP server listens on port 21.

So, even if packets have the same MAC (Layer 2) and IP (Layer 3) addresses, the Transport Layer (Layer 4) ensures delivery to the correct application.



Multiplexing based on ports
Multiplexing based on ports


specific TCP/UDP port




2. End-to-End Connectivity (TCP Sessions)

TCP provides end-to-end connectivity by establishing sessions using the Three-Way Handshake:

  1. SYN → Client says “I want to connect.”

  2. SYN-ACK → Server replies “I’m ready.”

  3. ACK → Client confirms.

📌 Once established, both sides communicate via sockets (IP address + port number).

Example:

  • Client socket: 10.1.1.1:53000

  • Server socket: 1.2.3.4:80

This ensures unique connections, even when multiple applications run simultaneously.


Establishing a TCP session
Establishing a TCP session




3. Reliability & Error Recovery (TCP Only)

TCP ensures reliable data delivery using:

  • Sequence Numbers (SEQ) → Track data order.

  • Acknowledgments (ACKs) → Confirm received data.

  • Retransmission → Resend missing segments.

📌 Example:
If a webpage is sent in 3 segments (SEQ 1, 2, 3) and segment 2 is lost, TCP requests a retransmission, ensuring the browser gets the complete page.

CP Sequence Numbers



🔹 Transport Layer vs Network Layer

It’s easy to confuse these two, but their roles are different:

  • Network Layer (IP) → Finds the correct destination host (like a house address).

  • Transport Layer (TCP/UDP) → Finds the correct application inside that host (like the recipient’s name).

👉 Together, they ensure both delivery and accuracy.

Transport and Network layers working together.


🔹 Key Differences Between TCP and UDP

FeatureTCPUDP
ReliabilityReliable (error recovery)Unreliable (no error checking beyond checksum)
ConnectionConnection-oriented (3-way handshake)Connectionless
SpeedSlower (overhead due to reliability)Faster (lightweight header)
Use CasesWeb browsing, email, file transferGaming, VoIP, video streaming
Header Size20–60 bytes8 bytes

✅ Key Takeaways – Transport Layer (Layer 4 of OSI Model)

  • Transport Layer = Layer 4 of OSI model.

  • Adds source & destination port numbers to identify applications.

  • TCP → reliable, uses handshake, sequence & acknowledgment numbers, and flags.

  • UDP → lightweight, fast, but unreliable.

  • Sockets (IP + Port) uniquely identify each connection.

  • Supports the Client-Server model:

    • Client → dynamic/random port.

    • Server → well-known IANA port.


#Networking #OSImodel #TransportLayer #Layer4 #TCP #UDP #NetworkEngineering #CCNA #CCNP #NetworkingBasics #CyberSecurity

Understanding the OSI model

 In this lesson, we explain what the OSI model is in an easy and understandable language. It is one of the most important concepts in networking, so we break it down into pieces to help you understand exactly what its purpose is.

What is data encapsulation?

To understand the OSI model, you must first understand what data encapsulation is. Let's explore the following example. Imagine you want to send a letter to a friend who lives in another city to invite him to your wedding. What if you send the letter without an envelope, with any information, such as the sender's and recipient's names, addresses, and postcodes? What if you simply write the letter and drop it in the mailbox at the post office? 





Most readers of this CCNA course are so young that they've never sent a physical letter in their lives. They live in the digital age and have grown up with emails and instant text messages. However, surprisingly, everyone understands the concept of the post service and sending mail.

Let's examine the following two examples: a letter without an envelope (on the left) and one placed inside an envelope with all required information written on top (on the right). If you put those two into your mailbox, which one will reach its intended recipient and which one won't?



#cisco #networking #OSI #model

It is pretty obvious, right? If you send a letter with no envelope and no additional information, such as sender and recipient details, the postal service won't know where to deliver it. The letter won't reach anyone. Your friend won't show up at your wedding.

To ensure that the information (the letter) is delivered to the correct recipient, we must include additional information alongside the letter, so that the postal service knows how to handle it (we encapsulate the data).



The envelope that encapsulates the letter contains the following information, which helps the postal service deliver the letter correctly:

  • Stamp and postcard
  • Sender's name
  • Sender's address
  • Sender's postcode
  • Recipient's name
  • Recipient's address
  • Recipient's postcode

Optionally, the envelope may include:

  • Return address (if different from the sender’s address)
  • Date and time stamp
  • Subject or reference line inside the letter (in formal letters)

The main idea is that sending letters equals sending information by utilizing the postal service as the medium. Sending emails is the same—it’s still a process of sending information, but through a computer network. The key point is that in both cases, you can’t send just the information alone; you need to include extra details that tell the transporting medium how to deliver the information.



Data Encapsulation in Networking

Computer networks function similarly to the postal service. The difference is that they move digital information instead of paper letters. However, you can’t just send raw data onto the network and expect it to reach the destination, just like you can’t drop a plain letter into a mailbox and expect it to be delivered. The data must be encapsulated with additional information first, as shown in the diagram below.







Imagine a device (like your laptop) wants to send data onto the network. Let's say you're sending a Facebook message to a friend. As you type the message and hit enter, the data goes from the web browser (where you have Facebook opened), to the Operating System (OS), to the NIC, and out to the network. Many processes add their own additional information called headers. These headers contain important details, like:

  • Who the data is for.
  • Where did it come from?
  • How it should be delivered.
  • What type of data is it?

In the end, the simple Facebook message "Hey! What's up?" looks like a network packet encapsulated with multiple headers, as shown in the diagram below.



At the destination, the data undergoes the reverse process of removing headers before the it is presented to the correct application.

Why do we need the OSI model?

The process of data encapsulation is not simple. It involves many different protocols, headers, and steps. Each part of a network—like applications, network devices, and physical mediums—needs to know what to do with the data and how to handle it correctly.

In the early days of networking, different companies built their own systems, using their own encapsulation methods. These systems often couldn’t work together because they didn’t follow the same rules. For example, one vendor might add certain headers in a unique order that another vendor's device couldn't understand. This made it hard to send data between different networks or even between devices from the same company.

Additionally, to achieve the ultra-high speeds of today's networks, network devices must precisely locate the information they need, without examining headers that are irrelevant, as shown in the diagram below.

.

To fix this, engineers realized that the industry needed a standard framework. They needed a common way to describe how data should be prepared, sent, and received. That’s where the OSI model comes in.

The OSI model gives a step-by-step structure for how data encapsulation should work:

  • Each layer has a specific job, like adding source and destination addresses or checking for errors.
  • Each layer uses specific protocols that follow agreed-upon rules.
  • Each layer adds its own header (and sometimes trailer) to the message, so the receiving system knows how to process it.

In short, the OSI model helps manage the complexity of data encapsulation by providing a clear, standard method that everyone in networking can use. This ensures interoperability, consistency, and easier troubleshooting.

The OSI model helps us understand and explain how data is wrapped up layer by layer (encapsulation), and how it's unwrapped at the other end (de-encapsulation).

What is the OSI model?

The OSI model, or Open Systems Interconnection model, is a framework that breaks down the encapsulation process into seven layers. Each layer has a specific role and handles a part of the encapsulation, such as data formatting, logical addressing, routing, physical addressing, or error checking.

The following example shows how data moves through the OSI layers and gets wrapped at each step before being sent over the network to the next device. Notice that each layer adds its own specific header with relevant information for the network function.




The primary goal of the OSI model is to establish a standard and vendor-agnostic data encapsulation framework. It helps different devices and systems work together by following the same set of rules and standards. 

The following diagram illustrates each layer, with a brief description and the protocols that operate at that layer. Notice that in general, different network devices operate at different layers of the OSI model. This means that a network device cares only for the headers up to a particular layer and doesn't care about the rest of the headers in the message. For example, a switch only cares about the data link (layer 2) header, which consists of the source and destination MAC addresses. A router cares only about the layer 2 and layer 3 headers, and so on.







Note also that we refer to the data at each layer of the OSI model with a different term. For example, at layer 4, we refer to a TCP message as a segment. At layer 3, we refer to it as a packet. At layer 2, we refer to it as a frame.

The OSI model vs. TCP/IP model

The OSI model, with its seven layers, is a well-structured and useful way to understand how data encapsulation works. However, network engineers quickly notice that layers 5, 6, and 7 are not directly related to most networking tasks. These layers focus more on how software applications handle data, which is usually outside the scope of networking.

As a result, network professionals, through practice and real-world experience, began using a simpler model that focuses on the aspects that matter most to networking—Layers 1 through 4. This led to the development of the TCP/IP model, which has fewer layers and is more aligned with how networks actually operate.

The following diagram shows a comparison of the OSI model (with 7 layers), the first version of TCP/IP (which had 4 layers), and the modern version of the TCP/IP model (with 5 layers).


The modern 5-layer TCP/IP model uses the same names as the OSI model for the lower layers, and their jobs are very similar. So, when reading about networks or talking to others in the field, you can think of the lower four layers as being the same in both models- OSI and TCP/IP.

For this course, make sure you understand how the 5-layer TCP/IP model maps to the 7-layer OSI model (as shown in both ends of the diagram above). Also, remember that when people refer to “Layer 7,” they typically mean the top layer in both models, which handles applications.

For example, you will often hear one of the following phrases that you must understand:

  •  "Do you need a layer 2 or a layer 3 port?"
  •  "Is this a layer 2 or layer 3 switch?"
  •  "The problem is at layer 2."

Although networks today use TCP/IP, many people still refer to OSI layer numbers. For example, people call an application protocol a “Layer 7 protocol,” even though TCP/IP combines some of those OSI layers (application, presentation, and session) into just one.



Key Takeaways on the OSI Model

  • The OSI model is a theoretical framework that breaks down the data encapsulation process into seven layers
  • Each layer describes the information included in the message as a header.
  • The OSI model remains widely used to teach networking and explain how protocols function. 
  • However, while Cisco includes the OSI model in the CCNA/CCNP exams, knowing more than the basics isn’t very useful in real-world networking today. 
  • It’s essential to know the first four layers as they are the ones that concern network engineers the most.

Featured Post

Day 41 — BGP Confederations: Sub-AS Design, External View and Migration

1. Opening Confederations are another way to scale BGP inside a large administrative domain. They divide the domain into member autonomous systems while presenting a single confederation identifier to external peers. They are powerful, but their operational model is more complex than simply 'using private ASNs inside.' The engineering goal is not to memorize another BGP command. It is to understand what information each speaker is allowed to propagate, what path information can be hidden, and what failure domain is created by the chosen control-plane architecture . 2. Concept and standards behavior RFC 5065 defines AS_CONFED_SEQUENCE and AS_CONFED_SET and how member-AS relationships are represented. Confederation external sessions have eBGP-like properties inside the confederation, while the confederation is presented externally as one AS. Modern guidance must also account for the fact that RFC 9774 prohibits new origination of AS_SET/AS_CONFED_SET in ordinary aggregation c...