TechKnowSurge
CompTIA Network+ 1.1 CompTIA Network+ 1.4 CompTIA A+ Core 1 2.1 Cisco CCST Networking 1.1 Cisco CCNA 1.5 Cisco CCST Cybersecurity 2.1
VideoNetworkFree

Layer 4 Basics

Layer 4 of the OSI model, known as the Transport Layer, governs how data is segmented, addressed through ports, and delivered between devices using either TCP or UDP. TCP prioritizes reliability through connection establishment, sequencing, and error recovery, while UDP prioritizes speed with minimal overhead.

Complete this video to capture a CTF flag worth 1 point.

About this video

Layer 4 of the OSI model, called the Transport Layer, sits between the Network Layer and the Session Layer and is responsible for managing end-to-end communication between devices. Its core functions include segmentation, port-based addressing, connection management, error detection, sequencing, and flow control. Segmentation breaks large blocks of data into smaller units that can travel across a network independently, enabling multiple conversations to share the same connection simultaneously and allowing individual segments to take different paths to their destination. Each segment carries a header containing information such as the destination port and, in the case of TCP, sequence numbers that allow the receiving device to reassemble the data in the correct order. The two dominant Layer 4 protocols are TCP and UDP, and they represent opposing priorities. TCP is connection-oriented, meaning it performs a handshake to establish a session before any data is sent. It sequences segments, detects missing or corrupted data, requests retransmission when needed, and uses flow and congestion control to maximize throughput. This makes TCP the right choice for applications where data integrity is non-negotiable, such as downloading software or loading web pages. UDP is connectionless and carries a minimal header, sacrificing reliability mechanisms in favor of speed. It sends segments without establishing a session or tracking delivery, which suits real-time applications like voice over IP and video conferencing, where delayed or retransmitted data arrives too late to be useful. Ports are a foundational element of Layer 4 operation. Unlike physical ports on a device, these are virtual numeric identifiers that map incoming and outgoing traffic to specific services. Port 80 is conventionally associated with web traffic, port 25 with email, and port 22 with secure shell access, among many others. When a segment is sent, it includes both a source and destination port so the receiving device knows which service should handle the data. Understanding how TCP, UDP, ports, segmentation, and sequencing interact forms the basis for diagnosing network behavior and understanding how reliable communication is maintained across modern infrastructure.

What you'll learn

What's covered

Layer 4 Transport Layer

Aligned to

CompTIA Network+
1.1 Explain concepts related to the Open Systems Interconnection (OSI) reference model.
1.4 Explain common networking ports, protocols, services, and traffic types.
CompTIA A+ Core 1
2.1 Compare and contrast Transmission Control Protocol (TCP) and User Datagram Protocol (UDP) ports, protocols, and their purposes.
Cisco CCST Networking
1.1 Identify the fundamental conceptual building blocks of networks
Cisco CCNA
1.5 Compare TCP to UDP
Cisco CCST Cybersecurity
2.1 Describe TCP/IP protocol vulnerabilities

Key terms

Transport Layer
Layer 4 of the OSI model, responsible for end-to-end communication, flow control, and error recovery.
Transmission Control Protocol
TCP
A connection-oriented transport protocol that ensures reliable, ordered, and error-checked delivery of data.
User Datagram Protocol
UDP
A connectionless transport protocol that sends data without establishing a connection or guaranteeing delivery.
Port
A logical endpoint for communication in a network, identified by a number that specifies a particular service or application.
Segmentation
The process of dividing a large message or data stream into smaller pieces called segments before transmission across a network, allowing multiple devices to share the medium and enabling parallel transfer. TCP performs segmentation at Layer 4 and numbers the segments so the receiver can reassemble them in the correct order.
Sequencing
The numbering of data segments so the receiving device can reassemble them in the correct order, even if they arrive out of sequence.

Transcript

Let's get into an in-depth look at what layer 4 looks like.

Layer 4 in the OSI and TCP/IP models

Here's our OSI model chart. Once again, we see layer 4 snuggled right in between layer 3 and layer 5. Of course, layer 4 is called the transport layer. Some examples, as I already mentioned, are TCP and UDP, although there are other examples of it. Most of our common networks that we have right now, at least the ones that we're going to be talking about, have either TCP or UDP. So we'll take an in-depth look at both of those. Most of our chapter, because TCP is a little more complex — most of this module is going to be associated with, or what we're going to be talking about, is the TCP.

Now what we have within this model is our protocol data unit is called a segment. This is, if you recall, where we've taken data and we've broken it down into segments, or smaller packages. We have to put a header on the front of that to have some information in there. And part of our module will go into all of those components and talk about the details of those components.

Here's the TCP/IP model. I don't bring this up too often, but what's interesting about this is we see some similarities between the two models. But I just want to point out that the model is called TCP/IP because TCP is, I'd say, a little more prevalent over UDP. So even though we see TCP and UDP, we give this model the TCP/IP name, and so that just signifies that TCP is a little more prevalent out there. And we'll see kind of how common each of TCP and UDP are out there, but UDP also has a very specific role that it plays, so it is important as well.

The roles of layer 4

Layer 4 has several different roles. So first of all is segmentation. What it's designed to do is take data and break it down into smaller components to send it from one device to the next. And so it doesn't always need to do that, but there are many times when the data is too large and we need to break it into smaller sections and then send it over. So that's segmentation.

Then we also have addressing. When we're sending data to another device, somehow we have to access a certain service, and we do that through ports. And so this is where ports come in, is at this layer. So we're going to be sending some sort of port information back and forth between these two devices, and so that way we can address specific services.

And then another thing that happens, if you're talking about TCP — so UDP is meant for faster type of connections, versus TCP is meant for more reliability. So a TCP connection will actually establish a connection between two devices for the communication to happen. It essentially establishes a conversation between these devices, and then it does some sort of sequencing so that way it can reassemble it on the other side. UDP doesn't have the same mechanism to do that. Then it will also have some error detection components in it, on how to resend data if there is lost data. And then finally it does some flow control or congestion control, where it will manipulate some of the data to maximize the throughput between these two devices.

So those are some of the roles of layer 4, and we're going to go more in depth into this as we talk more about TCP and UDP and how the two function.

Contrasting TCP and UDP

Let's just do a quick contrast between TCP and UDP, because they function very differently, and how the packets as they're being sent across get treated has somewhat to do with whether it's TCP or UDP.

So UDP is designed for more speed. It's going to be chunking up the data, or segmenting the data, into these small little packets and sending it across for quick speed. It tries to limit how much overhead is with this, because it just wants to get it across to the other side. Versus TCP says, no, I want to make sure that I do this correctly and in the most expedient way that I can. So it does some sizing to make sure that it has the specific size segments, and it's trying to maximize how much data it's getting across from point A to point B. So UDP is more built for speed versus TCP is more built for reliability.

TCP has a larger header to facilitate some of that reliability and some of the flow control and congestion control that it has, where UDP is just meant to get the basic information across to the other side and do it in a more expedient manner.

So TCP, at this layer, will actually resend missing or bad data that gets over there. So as we're sending data, TCP — this is the layer that recognizes, oh, something's off, something has not been sent right, and so I need to re-get that data, or I need to ask for that data, and so then that data can be resent. Versus UDP does not have that mechanism. You would rely on upper layer protocols to either recognize that, or it just doesn't need it — the protocols that utilize UDP just don't need that as a function as part of that. So UDP doesn't have a mechanism to recognize that data is missing or corrupt.

TCP sequences the data so that way when it gets to the other side it can be reassembled in the proper order. UDP does not do that. So once again, it's either data that it doesn't matter what order that it's in, or on the other side there's some sort of upper layer protocol that senses that and can correct for that.

Then we also have a TCP will establish a connection. So there's a little back and forth that's sent to establish a connection and say, hey, I'm going to talk with you, is that okay? Yeah, let's do this thing. Let's talk. Okay, I'm talking to you now. So there's this little exchange that happens that sets up a conversation. UDP does not have that, so it's connectionless. It's just sending data, and the other side's going to have to accept it or not accept it.

Some examples of this would be TCP is used for downloading software, where you do need all of the components of the software. You can't just have a partial list of this software; that's not going to be acceptable. Or web browsing — you want the whole web page, you don't want just a partial part of that web page. Versus UDP is more to deal with like VoIP, or voice over IP, because when it's sending data to the other side, if data is delayed or missing, it's too late. Your part of the conversation, if it's waiting for a component of that conversation, it's going to get lost and it's too late to be delivered after the fact. And so VoIP just needs that speed to get over there.

Video conferencing is the same thing. If you're watching a video, if it's something that is like a movie, a lot of times it'll stream and download things ahead of time. But if you're on video conferencing where things are streaming live and that data doesn't get to you, then it's useless after a certain point, and so it's not going to try to resend that information. So those are some examples of TCP and examples of UDP and how they send that.

Ports

This layer has a lot to do with ports. Ports are connections into your computers. And you have physical ports, things like USB and VGA and serial. So there's different ways to connect into your computer, but there are also virtual ports.

And similarly, when you connect a printer, there's some sort of communication that's established between your computer and that printer. And that's all defined by those drivers that are installed, and all defined by the protocols that USB has, of how that communication is going to get established. Well, there's the same thing that happens in the virtual side of your computer. We have once again these things called ports, but they're virtual ports that are on your computer, and they're just a series of numbers, and you can assign these numbers to whatever service that you want. So you can specify some sort of access to those different services.

So we're going to put on here maybe port 22, maybe port 25, port 80. So we open up these different ports on here and they're associated with some sort of service. So let's say we have port 80 that's opened up to maybe a web page, and maybe port 25 is opened up to mail. And so these ports are now open, and there's some sort of rules that are set up so that way when we are communicating to one of these ports, we know what kind of language that we're speaking, so to speak — so we know what protocol is going to be communicating across these different ports. So we'll be talking quite a bit about these ports and how these virtual ports are set up on your PC.

Segmentation

So now let's say you go to the internet and you download a 5 gigabyte file. If you downloaded that 5 gigabyte file and it was all one stream of data, then what would happen is that no one else could communicate while you were downloading that file. And that file could download in the matter of minutes, or it could take hours. And then during that time, no one else could communicate. That obviously is a big, big problem. And if that stream of data stopped at any given point in time, then that interruption would cause you to have to go and completely download that 5 gigabyte file again. You can imagine the internet would look a lot different if we were dealing with that type of scenario, where you just took up the whole connection until it was completely downloaded.

And so what happens is that we break data down into smaller components, so that way it can facilitate multiple conversations, lots of conversations, to happen all at once. So that way, with one person that's downloading a file at your business or at your home, other devices can communicate at the same time, because this data can get intermixed as it's sending across there.

It also could take different paths. So there might be lots of different paths that these take to get it to its final destination. And so it allows this communication to self-heal as well. So if one of these paths goes down, it's just going to choose a new route to get over to that.

So segmentation is a crucial part to how the internet works, and this layer, layer 4, helps facilitate that segmentation. Layer 4 takes that data, breaks it into smaller pieces, and then puts some information on those pieces and sends it across.

Now we see once again TCP versus UDP. TCP does some sort of sequencing versus UDP doesn't. But essentially they both segment the data into small components and send it across to the other side.

Headers and sequencing

Now of course, as we're sending this data over to the other side, we have to include some information. So here is an example. We've got data right here and we need to break that down into smaller components. So we break that down into smaller bytes of data, and then to each one of those we add a header. So this is the data that we add a header to, each one of these, and this information could include how it's going to get reassembled on the other side. It's going to include what ports that it's going to address on the other side. So there's information that goes into this header, so that way when it gets to the other side it knows what to do with this data.

If we are talking about TCP, then that's where we're talking about reassembly on the other side. And so somehow within this header we need to include information on how it's going to get reassembled. Something like, this is going to be packet one, this is going to be packet two, this is going to be packet three. Now this is a little misleading, because our numbers look a little different than that, so we'll talk about sequencing and what sequences look like. But essentially this is the concept of it: that when it gets to the other side, then it will know how to reassemble that, and if there's data missing, how to retransmit that data, so that way we get reliable connectivity from one point to the other.

About TechKnowSurge

TechKnowSurge builds IT and cybersecurity professionals through hands-on, concept-first training built around real understanding — not memorization. Free interactive tools, structured programs, and 25+ years of real-world experience, all in one place.

Explore free tools and programs →