Lesson 6 - Transport Layer


In this lesson we're going to learn how data is directed to the correct application and how error recovery is performed.

Transport Layer Addresses

In lesson 05 we learned how applications talk to each other using application layer protocols. When a web browser talks to a web server it sends commands like HTTP GET. The data from the application layer gets sent to the transport layer. The transport layer splits the data into easy to transport chunks. Each chunk is encapsulated with a header creating a segment.

In the image above we see a TCP header. The type of header depends on the protocol used. The two common transport layer protocols are TCP (Transmission Control Protocol) and UDP (User Datagram Protocol). UDP is used to stream data when you don't need every segment to make it, for example, if you're streaming a video. TCP focuses on error recovery to ensure all segments arrive at their destination properly. We're going to focus on the TCP header in this lesson.

The transport layer makes sure the data gets to the correct application on the destination device. Each application layer protocol uses an address called a port. The port address is used to deliver the data to the correct application. If we have a server running both a web server and FTP server it's the port addresses that make sure the data gets to the correct application.

The TCP header contains source and destination port addresses. The destination port address makes sure the data is delivered to the correct application on the server. The source port makes sure the reply is sent to the correct application on the client. When browsing the web you may have multiple tabs running. Multiple web connections are arriving to your computer, and they are being sent to the correct tab in your web browser. Ephemeral ports are the addresses of your client side applications. Each tab in your web browser has a unique random port above 1024.

Error Recovery

After the source and destination ports in the TCP header we find the sequence and acknowledgement numbers. These fields are used to perform error recovery. The sequence number is the number of the first byte of information sent using a random number as a starting point. The acknowledgement number is sent by the receiving computer to acknowledge it's received all the data and identifies what sequence number it expects next. In the image below we see this when sending a 78 byte file.

We learned in lesson 04 how the data link layer performs error detection. When a frame fails the FCS check it's discarded. At the transport layer the sequence number and acknowledgement numbers are used to perform error recovery. If data is lost, the receiving device will send an acknowledgement number for the last byte of data it received plus one. This tells the sending device to resend the data starting at that byte. In the image below we can see an example of error recovery.

TCP Header

We've covered the major parts of the TCP header, in this section we're going to look at the remaining fields. The offset field defines the length of the TCP header so it knows where the data starts. The reserved bits are in case they're needed for additional TCP flags in the future. In the past the TCP flags field was only 6 bits, but 3 bits were added from the reserve section to add capabilities.

The TCP Flags section contains 9 bits, and based on which bits are turned on describe the segment type. We aren't going to cover all the bits but we will cover some of the important ones. The second bit is the SYN bit, and the fifth bit is the ACK bit. These two bits are used when two devices initialize their first connection. The SYN segment is sent to the destination device which will include the random number to be used for the sequence number. The device with will reply with the SYN and ACK bits turned on saying it acknowledges the connection and agrees on the starting sequence number. The sender then replies with the ACK bit turned on completing the three way handshake.

The first bit is the FIN bit and it's used to terminate the connection. We saw the FIN bit in use in the communications above.

The window defines how much data should be sent before an acknowledgment is sent. The checksum field makes sure the header is correct. The urgent field works with the URG TCP flag and defines the how much of the data is considered urgent.


At the transport layer we learned two new terms related to our TCP/IP model. The addresses used at the transport layer are called ports, and the chunks of data are called segments.

1 | 2 | 3 | 4 | 5 | 6 | 7 | 8