Transport Layer Complete Study Guide – Data Communication Chapter 3
What is the Transport Layer?
My dear students, welcome to Chapter 3! Today we are going to learn about the Transport Layer, which is the 4th layer in the OSI model. Now, let me ask you a simple question before we start. Have you ever wondered how, when you open your browser and also a messaging app at the same time, the right data goes to the right application? The transport layer does exactly that job.
The transport layer is responsible for process-to-process delivery of the entire message. Notice the words carefully — it says process-to-process, not just computer-to-computer. A process is simply an application program running on a host, like your web browser, your email client, or your messaging app.
Now, here is an important difference. The network layer (layer 3) handles source-to-destination delivery of individual packets. But here is the problem: the network layer does not recognize any relationship between those packets. It treats each packet independently, as if each piece belonged to a separate message. The transport layer, on the other hand, ensures that the whole message arrives intact and in order. It handles both error control and flow control at the source-to-destination level.
Transport layer = delivers the complete message from process to process (process-to-process).
Major Functions of the Transport Layer
Let me list the major functions for you in a simple way:
1. It enables multiple applications to communicate over the network at the same time on a single device.
2. It ensures all the data is received reliably and in order by the correct application (if required).
3. It employs error handling mechanisms to detect and correct problems.
Five Responsibilities of the Transport Layer
Now, let us look at each responsibility one by one. These are very important for your exam, so please pay close attention.
1. Service-Point Addressing (Port Addressing)
Think about this: your computer runs several programs at the same time. You might have a browser open, an email client running, and maybe a file transfer application. When data arrives at your computer, how does the system know which program should receive which data?
The answer is service-point addressing. The transport layer header includes a type of address called a service-point address, which is also known as a port address.
The network layer gets each packet to the correct computer; the transport layer gets the entire message to the correct process on that computer. This is a very common exam sentence, so remember it well!
Q1. Which layer is responsible for process-to-process delivery?
- a) Data Link Layer
- b) Network Layer
- c) Transport Layer
- d) Physical Layer
Q2. What type of address does the transport layer use to identify the correct process?
- a) MAC address
- b) IP address
- c) Port address
- d) Physical address
Q3. True or False: The network layer recognizes the relationship between packets belonging to the same message.
Q1 Answer: (c) Transport Layer. The transport layer handles process-to-process delivery. The data link layer handles node-to-node delivery, and the network layer handles host-to-host delivery.
Q2 Answer: (c) Port address. The transport layer uses port numbers (service-point addresses) to identify the correct process. MAC addresses are used at the data link layer, and IP addresses at the network layer.
Q3 Answer: False. The network layer treats each packet independently. It does not recognize any relationship between packets. The transport layer is the one that ensures the complete message is reassembled correctly.
2. Segmentation and Reassembly
A message from the application layer can be very large. The transport layer divides the message into transmittable segments. Each segment is given a sequence number. These sequence numbers are very important because they allow the transport layer at the receiving end to reassemble the message correctly, even if the segments arrive out of order. They also help to identify and replace packets that were lost during transmission.
Reassembly = putting the segments back together in the correct order at the destination.
Each segment gets a sequence number for proper reassembly.
Q1. Why does the transport layer divide a message into segments?
- a) To make the message smaller for storage
- b) To enable reassembly and identify lost packets using sequence numbers
- c) To compress the data
- d) To encrypt the data
Q2. Each segment contains a ________ number that helps in reassembling the message at the destination.
Q3. What happens if a segment is lost during transmission? How does the transport layer handle it?
Q1 Answer: (b). Segments are given sequence numbers that allow the receiver to reassemble them in order and to identify which specific segment was lost so it can be retransmitted.
Q2 Answer: Sequence. The sequence number is added to each segment by the transport layer.
Q3 Answer: If a segment is lost, the transport layer at the receiver notices a gap in the sequence numbers. It then asks the sender to retransmit the missing segment. The sequence numbers make it possible to identify exactly which segment is missing.
3. Flow Control
Flow control at the transport layer works similarly to flow control at the data link layer, but there is an important difference. Flow control at the transport layer is performed end to end, not across a single link. This means the sender and receiver adjust the rate of data transfer based on the receiver’s ability to handle data, even though the data may travel through many intermediate links.
Transport Layer flow control = end to end (between source process and destination process).
4. Error Control
Just like flow control, error control at the transport layer is also different from the data link layer. Error control at the transport layer is performed process-to-process, not across a single link. The sending transport layer makes sure that the entire message arrives at the receiving transport layer without error — no damage, no loss, and no duplication. Error correction is usually achieved through retransmission.
5. Connection Control
The transport layer can operate in two modes:
A. Connectionless: Each segment is treated as an independent packet. There is no connection establishment before sending, and no connection release after. Think of it like sending a postcard — you just drop it in the mailbox without checking if the receiver is ready.
B. Connection-oriented: A connection is first established with the transport layer at the destination machine. Then data is transferred. After all data is transferred, the connection is terminated. Think of it like making a phone call — you first establish the call, talk, and then hang up.
Process-to-Process Delivery
Now let me explain this concept very clearly because students often get confused here. Let us revise the delivery types at each layer:
| Layer | Delivery Type | What It Delivers |
|---|---|---|
| Data Link Layer | Node-to-Node | Frames between two neighboring nodes over a single link |
| Network Layer | Host-to-Host | Datagrams between two hosts (computers) |
| Transport Layer | Process-to-Process | Entire message between specific processes (applications) |
Real communication on the Internet is not between two nodes or two hosts. Real communication takes place between two processes (application programs). At any moment, several processes may be running on the source host and several on the destination host. The transport layer uses port numbers to deliver data from the correct process on the source to the correct process on the destination. Two processes communicate in a client/server relationship.
Q1. The data link layer handles ________ delivery, the network layer handles ________ delivery, and the transport layer handles ________ delivery.
Q2. Real communication on the Internet takes place between:
- a) Two nodes
- b) Two hosts
- c) Two processes
- d) Two routers
Q3. Why is process-to-process delivery needed instead of just host-to-host delivery?
Q1 Answer: Node-to-Node, Host-to-Host, Process-to-Process.
Q2 Answer: (c) Two processes. Although data travels between hosts, the actual meaningful communication happens between application programs (processes) running on those hosts.
Q3 Answer: Because a single host can run multiple applications (processes) at the same time. For example, you might be browsing a website and downloading a file simultaneously. Host-to-host delivery only gets the data to the right computer. Process-to-process delivery ensures the data reaches the correct application on that computer.
TCP Segment Format – Detailed Breakdown
A packet in TCP is called a segment. The segment consists of a 20 to 60 byte header, followed by data from the application. The header is 20 bytes if there are no options, and up to 60 bytes if options are included. Let me walk you through each field one by one.
Source Port Address (16 bits)
This field defines the port number of the application program on the host that is sending the segment. It tells the receiver which process sent the data.
Destination Port Address (16 bits)
This field defines the port number of the application program on the host that is receiving the segment. It tells the receiver which process should get the data.
Sequence Number (32 bits)
This is a very important field. It defines the number assigned to the first byte of data in this segment. TCP numbers every single byte that it transmits. The sequence number tells the destination which byte in the overall stream is the first byte in this segment. During connection establishment, each party uses a random number generator to create an Initial Sequence Number (ISN).
Acknowledgment Number (32 bits)
This field defines the byte number that the receiver is expecting to receive next. If the receiver has successfully received all bytes up to byte number x, it sets the acknowledgment number to x + 1. This is called cumulative acknowledgment. Acknowledgment and data can also be sent together in the same segment — this is called piggybacking.
Header Length (4 bits)
This field indicates the number of 4-byte words in the TCP header. Since the header can be between 20 and 60 bytes, the value of this field ranges from 5 (5 × 4 = 20 bytes) to 15 (15 × 4 = 60 bytes).
Where Data Offset is the 4-bit header length field value (5 to 15).
Control Flags (6 bits)
These are six individual bits, each with a specific purpose:
| Flag | Full Name | Purpose |
|---|---|---|
| URG | Urgent | Urgent pointer field is valid |
| ACK | Acknowledgment | Acknowledgment number field is valid |
| PSH | Push | Deliver data to application immediately |
| RST | Reset | Reset the connection |
| SYN | Synchronize | Used during connection establishment |
| FIN | Finish | Used during connection termination |
Window Size (16 bits)
This field defines the size of the sliding window, in bytes, that the other party must maintain. The maximum window size is 65,535 bytes (because 16 bits = 2^16 = 65,536 values). This value is called the receiving window (rwnd) and is determined by the receiver. The sender must follow this limit for flow control.
Checksum (16 bits)
This field contains the checksum for error detection. Unlike UDP where the checksum is optional, in TCP the checksum is mandatory. For the TCP pseudo header, the protocol field value is 6.
Urgent Pointer (16 bits)
This field is valid only when the URG flag is set. It defines a number that must be added to the sequence number to find the last urgent byte in the data section.
Options (0 to 40 bytes)
Optional information can be included in the TCP header, up to 40 bytes.
- Minimum header size = 20 bytes, Maximum = 60 bytes
- Header length field value range = 5 to 15 (in 4-byte units)
- Sequence number = number of the first byte in the segment
- Acknowledgment number = next expected byte (cumulative)
- Checksum in TCP is mandatory (optional in UDP)
- TCP pseudo header protocol field value = 6
- Maximum window size = 65,535 bytes
Solved Example: Reading a TCP Header from Hexadecimal
This type of question comes very often in exams. Let me teach you step by step how to solve it.
Problem: The following is a dump of a TCP header in hexadecimal format:
0532 0017 00000001 00000000 5002 07FF 00000000
Find: (a) Source port number, (b) Destination port number, (c) Sequence number, (d) Acknowledgment number, (e) Length of the header.
(a) Source Port Number:
The first 16 bits (4 hexadecimal digits) = 0532
Converting from hexadecimal to decimal:
\[0 \times 16^3 + 5 \times 16^2 + 3 \times 16^1 + 2 \times 16^0 = 0 + 1280 + 48 + 2 = \boxed{1330}\]
(b) Destination Port Number:
The next 4 hexadecimal digits = 0017
\[0 \times 16^3 + 0 \times 16^2 + 1 \times 16^1 + 7 \times 16^0 = 0 + 0 + 16 + 7 = \boxed{23}\]
Note: Port 23 is the well-known port for Telnet! This tells us the destination application is Telnet.
(c) Sequence Number:
The next 8 hexadecimal digits = 00000001
\[0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 = \boxed{1}\]
(d) Acknowledgment Number:
The next 8 hexadecimal digits = 00000000
\[\boxed{0}\]
Note: The ACK number is 0, which means this is likely a SYN segment (connection establishment), where the acknowledgment number is not yet valid.
(e) Length of the Header:
Look at the 13th byte onward: 5002. The first hex digit 5 is the data offset (header length field).
\[\text{Header Length} = 5 \times 4 = \boxed{20 \text{ bytes}}\]
This means there are no options in this header (minimum size).
Problem: A TCP header dump in hexadecimal is given as:
10A0 0050 00001000 00001001 5018 FFFF 00000000
Find: (a) Source port, (b) Destination port, (c) Sequence number, (d) Acknowledgment number, (e) Header length.
(a) Source Port: 10A0 = \(1 \times 4096 + 0 \times 256 + 10 \times 16 + 0 = 4096 + 160 = \boxed{4256}\)
(b) Destination Port: 0050 = \(0 + 0 + 5 \times 16 + 0 = \boxed{80}\) (HTTP!)
(c) Sequence Number: 00001000 = \(\boxed{4096}\)
(d) Acknowledgment Number: 00001001 = \(\boxed{4097}\)
(e) Header Length: Data offset = 5, so \(5 \times 4 = \boxed{20 \text{ bytes}}\)
Transport Layer Addressing – Port Numbers
Now, let me explain port numbers very clearly. At every layer, we need an address to deliver data to the correct destination:
| Layer | Address Type | Purpose |
|---|---|---|
| Data Link Layer | MAC Address | Choose one node among several on a network |
| Network Layer | IP Address | Choose one host among millions on the Internet |
| Transport Layer | Port Number | Choose one process among several running on a host |
Port numbers are 16-bit integers, ranging from 0 to 65,535. The client program uses a randomly chosen port number (called an ephemeral port). The server process must use a specific, well-known port number so that clients can find it.
IANA Port Number Ranges
The Internet Assigned Numbers Authority (IANA) divides port numbers into three ranges:
| Range | Name | Description |
|---|---|---|
| 0 to 1,023 | Well-Known Ports | Assigned and controlled by IANA. Used by server processes. Examples: 21 (FTP), 23 (Telnet), 25 (SMTP), 80 (HTTP) |
| 1,024 to 49,151 | Registered Ports | Not assigned by IANA but can be registered to prevent duplication |
| 49,152 to 65,535 | Dynamic/Ephemeral Ports | Not controlled or registered. Used by client processes as temporary ports |
These are the most commonly asked port numbers in exams!
Port Numbers in Client-Server Communication
Let me explain this with a simple real-life example. Imagine you go to a large office building (the host). You want to meet a specific person (the process). The building address is the IP address, and the person’s office room number is the port number.
When a client sends a message:
- The destination port is the well-known port of the server service (e.g., 80 for HTTP)
- The source port is a randomly generated ephemeral port to track this specific conversation
- This allows multiple simultaneous conversations — for example, many clients can request web pages from the same server at the same time, and each conversation is tracked by different source ports
Socket Addresses
A socket address is the combination of an IP address and a port number. Process-to-process delivery needs a pair of socket addresses:
A complete connection needs: Client Socket Address + Server Socket Address
That is: Source IP + Source Port + Destination IP + Destination Port
Q1. What is the range of well-known port numbers?
- a) 0 to 255
- b) 0 to 1,023
- c) 1,024 to 49,151
- d) 49,152 to 65,535
Q2. Which port number is used by HTTP?
- a) 21
- b) 23
- c) 25
- d) 80
Q3. The combination of an IP address and a port number is called a ________ address.
Q4. Port numbers ranging from 49,152 to 65,535 are called ________ ports.
Q5. Why can a server process not use a randomly chosen port number?
Q1 Answer: (b) 0 to 1,023. These are the well-known ports controlled by IANA and used by server processes.
Q2 Answer: (d) 80. HTTP uses port 80. FTP uses 21, Telnet uses 23, and SMTP uses 25.
Q3 Answer: Socket. A socket address uniquely identifies a process on a host.
Q4 Answer: Dynamic (or Ephemeral). These ports are used temporarily by client processes.
Q5 Answer: If a server used a random port number, the client would not know which port to connect to. Well-known port numbers are standardized so that clients always know exactly which port to use for a specific service (e.g., port 80 for web services).
Multiplexing and Demultiplexing
Now, class, let me ask you a question. What happens when multiple applications on your computer want to send data at the same time, but there is only one network connection? The transport layer solves this using multiplexing and demultiplexing.
Multiplexing (At the Sender)
At the sender side, several processes may need to send packets. But there is only one transport layer. This is a many-to-one relationship. The transport layer accepts messages from different processes (identified by their port numbers), adds headers, and passes them to the network layer through a single connection.
Demultiplexing (At the Receiver)
At the receiver side, the relationship is one-to-many. The transport layer receives datagrams from the network layer, removes the header, and delivers each message to the appropriate process based on the port number in the header.
Q1. Multiplexing at the transport layer is a ________ relationship.
- a) One-to-one
- b) Many-to-one
- c) One-to-many
- d) Many-to-many
Q2. Demultiplexing uses which field to deliver data to the correct process?
- a) IP address
- b) MAC address
- c) Port number
- d) Sequence number
Q3. True or False: Demultiplexing happens at the sender side.
Q1 Answer: (b) Many-to-one. Multiple processes send data to a single transport layer — that is multiplexing.
Q2 Answer: (c) Port number. The port number in the transport layer header identifies which process should receive the data.
Q3 Answer: False. Demultiplexing happens at the receiver side (one-to-many). Multiplexing happens at the sender side (many-to-one).
Connectionless vs Connection-Oriented Services
Connectionless Service
In a connectionless service, packets are sent with no need for connection establishment or connection release. The packets are not numbered. They may be delayed, lost, or arrive out of sequence. There is no acknowledgment. UDP is connectionless.
Connection-Oriented Service
In a connection-oriented service, a connection is first established between sender and receiver. Then data is transferred. At the end, the connection is released. TCP is connection-oriented.
Reliable vs Unreliable Services
A reliable transport layer protocol implements flow and error control. It is slower but ensures all data arrives correctly. A unreliable protocol is faster but does not guarantee delivery. It is suitable for real-time applications.
| Protocol | Connection Type | Reliability |
|---|---|---|
| UDP | Connectionless | Unreliable |
| TCP | Connection-oriented | Reliable |
| SCTP | Connection-oriented | Reliable |
Q1. Which of the following is a connectionless and unreliable protocol?
- a) TCP
- b) SCTP
- c) UDP
- d) IP
Q2. TCP is a ________-oriented and ________ transport protocol.
Q3. True or False: In a connectionless service, packets are numbered and acknowledged.
Q1 Answer: (c) UDP. UDP is connectionless and unreliable. TCP and SCTP are connection-oriented and reliable. IP is a network layer protocol, not a transport layer protocol.
Q2 Answer: Connection, reliable. TCP = Connection-oriented, Reliable.
Q3 Answer: False. In connectionless service, packets are NOT numbered and there is NO acknowledgment. These features exist in connection-oriented services.
Transport Layer Protocols
Simple Protocol
This is the most basic protocol — connectionless with no flow control and no error control. It assumes the receiver can immediately handle any packet. There is no acknowledgment, no sequencing, and no retransmission.
Stop-and-Wait Protocol
This is a connection-oriented protocol that uses both flow and error control. The sender and receiver both use a sliding window of size 1. Here is how it works:
- The sender sends one packet at a time
- The sender waits for an acknowledgment before sending the next one
- A checksum is added to detect corrupted packets
- The sender keeps a copy of the packet until the acknowledgment arrives
Go-Back-N (GBN) Protocol
The Go-Back-N protocol is more efficient than Stop-and-Wait. The key idea is that the sender can send several packets before receiving acknowledgments, but the receiver can only buffer one packet. Important points:
- The sender keeps copies of sent packets until acknowledgments arrive
- The receiver keeps track of only one variable (the next expected packet)
- There is no need to buffer out-of-order packets — they are simply discarded
- If a packet is lost or corrupted, the receiver discards all subsequent packets and the sender must go back and retransmit all packets from the lost one onward
- This protocol is inefficient if the network loses many packets
Selective-Repeat (SR) Protocol
The Selective-Repeat protocol solves the inefficiency of Go-Back-N. Instead of retransmitting everything, it resends only the packets that were actually lost. Important points:
- The receiver can buffer out-of-order packets
- Only the lost or corrupted packets are retransmitted
- The receiver forwards packets to the transport layer only when they arrive in order and acknowledgments arrive on time
- More efficient than Go-Back-N, but more complex at the receiver side
Stop-and-Wait: Window size = 1, connection-oriented, flow + error control
Go-Back-N: Sender sends multiple, receiver buffers only 1, discards out-of-order
Selective-Repeat: Sender sends multiple, receiver buffers multiple, retransmits only lost packets
Q1. In the Stop-and-Wait protocol, what is the window size?
- a) 0
- b) 1
- c) N
- d) Unlimited
Q2. What happens to out-of-order packets in Go-Back-N protocol?
- a) They are buffered
- b) They are delivered to the application
- c) They are discarded
- d) They are retransmitted immediately
Q3. Which protocol retransmits only the lost packets, not all subsequent ones?
- a) Stop-and-Wait
- b) Go-Back-N
- c) Selective-Repeat
- d) Simple Protocol
Q4. True or False: Go-Back-N is efficient when the network loses many packets.
Q1 Answer: (b) 1. In Stop-and-Wait, both sender and receiver use a sliding window of size 1.
Q2 Answer: (c) They are discarded. In Go-Back-N, the receiver can only buffer one packet. Any out-of-order packet is simply discarded.
Q3 Answer: (c) Selective-Repeat. Selective-Repeat only retransmits the packets that were actually lost. Go-Back-N retransmits the lost packet and all packets sent after it.
Q4 Answer: False. Go-Back-N is inefficient when the network loses many packets because it retransmits all packets from the lost one onward, even if some of them were received correctly.
User Datagram Protocol (UDP) – Complete Details
UDP stands for User Datagram Protocol. It is called a connectionless, unreliable transport protocol. It does not add much to the services of IP except to provide process-to-process communication using port numbers. It performs very limited error checking.
Now you might wonder: if UDP is so basic, why would anyone use it? Here is the answer: UDP has very low overhead, which makes it fast. If a process wants to send a small message and does not care much about reliability, UDP is a great choice.
UDP Header Format
UDP packets are called user datagrams. They have a fixed-size header of 8 bytes:
Source Port (16 bits): Port number of the sending process.
Destination Port (16 bits): Port number of the receiving process.
Length (16 bits): Total length of the user datagram (header + data).
Checksum (16 bits): Used for error detection. Optional in UDP!
What UDP Does NOT Do
- No flow control
- No error control (beyond optional checksum)
- No connection control
- No segmentation and reassembly
- No sequence numbers
All these functions must be handled by the application layer programs if needed. Because UDP cannot segment and reassemble, it can only transmit small portions of data that fit into a single datagram.
What UDP DOES Do
- Service-point addressing (using port numbers)
- Process-to-process delivery
When is UDP Used?
- Simple request-response communication — when you need a quick exchange with little concern for reliability
- Applications with internal flow and error control — for example, TFTP (Trivial File Transfer Protocol) has its own error control
- Multicasting — UDP supports multicasting, TCP does not
- Management protocols — like SNMP (Simple Network Management Protocol)
- Route updating protocols — like RIP (Routing Information Protocol)
- UDP header size = 8 bytes (fixed)
- UDP is connectionless and unreliable
- Checksum in UDP is optional (mandatory in TCP)
- UDP does NOT do: flow control, error control, connection control, segmentation, sequencing
- UDP does: process-to-process delivery via port numbers
- UDP pseudo header protocol field value = 17
Solved Example: Reading a UDP Header from Hexadecimal
Problem: The following is a dump of a UDP header in hexadecimal format:
0632 000D 001C E217
Find: (a) Source port, (b) Destination port, (c) Total length, (d) Length of data.
(a) Source Port: First 4 hex digits = 0632
\[0 \times 16^3 + 6 \times 16^2 + 3 \times 16^1 + 2 \times 16^0 = 0 + 1536 + 48 + 2 = \boxed{1586}\]
(b) Destination Port: Next 4 hex digits = 000D
\[0 + 0 + 0 + 13 = \boxed{13}\]
(c) Total Length: Next 4 hex digits = 001C
\[0 + 0 + 1 \times 16 + 12 = 16 + 12 = \boxed{28 \text{ bytes}}\]
(d) Length of Data:
Remember: UDP header is always 8 bytes (no options, no variable length).
Q1. What is the size of the UDP header?
- a) 8 bytes
- b) 20 bytes
- c) 16 bytes
- d) 60 bytes
Q2. Which of the following is NOT a feature of UDP?
- a) Process-to-process delivery
- b) Flow control
- c) Port addressing
- d) Connectionless delivery
Q3. True or False: The checksum field in UDP is mandatory.
Q4. UDP is suitable for ________ because it supports multicasting.
Q5. Why can UDP only transmit small amounts of data at a time?
Q1 Answer: (a) 8 bytes. UDP has a fixed 8-byte header with no options.
Q2 Answer: (b) Flow control. UDP does NOT perform flow control. It does perform process-to-process delivery and port addressing.
Q3 Answer: False. The checksum in UDP is optional. In TCP, it is mandatory.
Q4 Answer: Multicasting. UDP supports multicasting; TCP does not have this capability built in.
Q5 Answer: Because UDP cannot perform segmentation and reassembly. It does not use sequence numbers. Therefore, all data must fit into a single user datagram.
TCP (Transmission Control Protocol) – Complete Details
Now we come to the most important protocol in the transport layer. TCP is a connection-oriented, reliable transport protocol. Unlike UDP, TCP provides many services that ensure data is delivered correctly and in order.
TCP Services
- Process-to-Process Communication — using port numbers, just like UDP
- Stream Delivery Service — data is sent as a continuous stream of bytes
- Full-Duplex Communication — data can flow in both directions at the same time
- Connection-Oriented Service — connection is established before data transfer
- Reliable Service — error control and flow control ensure reliable delivery
Stream Delivery Service
This is a very important concept. In UDP, a process sends messages with predefined boundaries. Each message becomes one datagram. But in TCP, there are no boundaries. TCP allows the sending process to deliver data as a stream of bytes, and the receiving process reads it as a stream of bytes. Think of it like water flowing through a pipe — there is no concept of where one “piece” of water ends and the next begins.
Sending and Receiving Buffers
Because the sending and receiving processes may not write or read data at the same speed, TCP uses buffers for storage. There are two buffers: a sending buffer and a receiving buffer, one for each direction. These are usually implemented as circular arrays of byte locations. The buffers can be hundreds or thousands of bytes in size.
How TCP Creates Segments
The sending process writes bytes into the sending buffer. TCP then groups a number of bytes together, adds a header, and creates a segment. The segment is then given to the IP layer for transmission. All of this is transparent to the receiving process.
TCP Segment Numbering System
Byte Numbering: TCP numbers every single byte in a connection. Numbering is independent in each direction. The numbering does not start from 0. Instead, TCP generates a random number between 0 and 2^32 – 1 as the number of the first byte. This random starting number is called the Initial Sequence Number (ISN).
Sequence Number: The sequence number of a segment is simply the byte number of the first byte carried in that segment.
Problem: A TCP connection is transferring a file of 8,000 bytes. The first byte is numbered 10,001. What are the sequence numbers for each segment if data is sent in four segments, each carrying 2,000 bytes?
Each segment carries 2,000 bytes. The sequence number of each segment is the number of its first byte:
Segment 1: Sequence Number = 10,001 (covers bytes 10,001 to 12,000)
Segment 2: Sequence Number = 12,001 (covers bytes 12,001 to 14,000)
Segment 3: Sequence Number = 14,001 (covers bytes 14,001 to 16,000)
Segment 4: Sequence Number = 16,001 (covers bytes 16,001 to 18,000)
Pattern to remember: Next sequence number = Previous sequence number + Number of bytes in previous segment
\[12,001 = 10,001 + 2,000\]
\[14,001 = 12,001 + 2,000\]
And so on. This pattern works every time!
Acknowledgment Number
Since TCP is full-duplex, both parties send and receive data at the same time. Each party uses an acknowledgment number to confirm the bytes it has received. The acknowledgment number defines the number of the next byte expected. It is cumulative, meaning if a party uses 5643 as an acknowledgment number, it has received all bytes up to 5642.
It does NOT mean 5,643 bytes have been received (because byte numbering may not start from 0).
Full-Duplex Communication
TCP allows data to flow in both directions at the same time. Each TCP connection has a sending buffer and a receiving buffer, and segments move in both directions simultaneously.
Connection-Oriented Service
TCP creates a virtual connection (not physical). The process is: establish connection → exchange data → terminate connection. Even though the segments travel through IP datagrams that may take different paths, TCP creates the illusion of a dedicated connection.
Flow Control in TCP
The receiver controls the amount of data the sender can transmit. This prevents the receiver from being overwhelmed. TCP uses a byte-oriented flow control with the window size field in the header. The maximum window size is 65,535 bytes.
Error Control in TCP
TCP provides reliability through error control. It handles:
- Corrupted segments — detected using checksum
- Lost segments — detected using timeouts and acknowledgments
- Out-of-order segments — stored temporarily but not delivered to the process until in order
- Duplicated segments — detected using sequence numbers
Error detection and correction uses three tools:
- Checksum — mandatory 16-bit checksum in every segment. If corrupted, the segment is discarded and treated as lost.
- Acknowledgment — confirms receipt of data segments. ACK segments are never acknowledged themselves.
- Timeout — if an acknowledgment is not received within a certain time, the segment is retransmitted.
Congestion Control
TCP also considers congestion in the network. The amount of data sent is not only controlled by the receiver (flow control) but also by the level of congestion in the network. If the network is congested, TCP reduces its sending rate.
- TCP is connection-oriented, reliable, stream-oriented
- TCP header size = 20 to 60 bytes (20 minimum, 60 maximum)
- Checksum is mandatory in TCP
- Sequence number = byte number of the first byte in the segment
- Acknowledgment number = next expected byte (cumulative)
- ISN is a random number between 0 and 2^32 – 1
- Three error control tools: Checksum, Acknowledgment, Timeout
- Maximum window size = 65,535 bytes
- TCP provides: flow control, error control, congestion control
Q1. The sequence number in a TCP segment refers to:
- a) The number of the segment
- b) The number of the first byte in the segment
- c) The total number of bytes sent
- d) The number of the last byte in the segment
Q2. If the acknowledgment number in a TCP segment is 5001, what does it mean?
- a) 5001 bytes have been received
- b) All bytes up to 5000 have been received safely
- c) The next segment should carry 5001 bytes
- d) The connection is using byte 5001
Q3. Which of the following is NOT a tool used by TCP for error control?
- a) Checksum
- b) Acknowledgment
- c) Timeout
- d) Encryption
Q4. TCP numbers bytes starting from a random number called the ________.
Q5. True or False: TCP delivers out-of-order segments to the receiving process.
Q6. Explain the difference between flow control and congestion control in TCP.
Q1 Answer: (b). The sequence number is the byte number of the first byte carried in that segment, not the segment number itself.
Q2 Answer: (b). An acknowledgment number of 5001 means all bytes from the beginning up to byte 5000 have been received safely. The receiver now expects byte 5001 next. This is the cumulative nature of TCP acknowledgments.
Q3 Answer: (d) Encryption. TCP uses checksum, acknowledgment, and timeout for error control. Encryption is not an error control tool.
Q4 Answer: Initial Sequence Number (ISN). TCP generates a random ISN between 0 and 2^32 – 1.
Q5 Answer: False. TCP stores out-of-order segments temporarily but NEVER delivers them to the process. It guarantees that the process receives data in order.
Q6 Answer: Flow control is controlled by the receiver — it tells the sender how much data it can handle using the window size. Congestion control is controlled by the network conditions — TCP reduces its sending rate when it detects congestion in the network, regardless of what the receiver’s window allows.
Quick Comparison: UDP vs TCP
| Feature | UDP | TCP |
|---|---|---|
| Connection | Connectionless | Connection-oriented |
| Reliability | Unreliable | Reliable |
| Header Size | 8 bytes (fixed) | 20–60 bytes (variable) |
| Flow Control | No | Yes |
| Error Control | Optional checksum only | Checksum + ACK + Retransmission |
| Sequencing | No | Yes (byte numbering) |
| Segmentation | No | Yes |
| Checksum | Optional | Mandatory |
| Delivery | Message-oriented | Stream-oriented |
| Multicasting | Yes | No |
| Speed | Faster (less overhead) | Slower (more overhead) |
| Window Size | N/A | Up to 65,535 bytes |
Q1. A TCP segment has a data offset field value of 7. What is the header length?
- a) 7 bytes
- b) 28 bytes
- c) 35 bytes
- d) 14 bytes
Q2. The maximum window size in TCP is:
- a) 32,767 bytes
- b) 65,535 bytes
- c) 1,024 bytes
- d) 65,536 bytes
Q3. The protocol field value in the TCP pseudo header is ________.
Q4. In Go-Back-N, the receiver discards out-of-order packets because it can buffer only ________ packet(s).
Q5. True or False: ACK segments in TCP consume sequence numbers and are acknowledged.
Q6. List three applications where UDP is preferred over TCP and explain why.
Q1 Answer: (b) 28 bytes. Header Length = Data Offset × 4 = 7 × 4 = 28 bytes.
Q2 Answer: (b) 65,535 bytes. The window size field is 16 bits, so maximum = 2^16 – 1 = 65,535 bytes.
Q3 Answer: 6. The TCP pseudo header uses protocol value 6. (UDP uses 17.)
Q4 Answer: One (1). The Go-Back-N receiver can buffer only one packet at a time.
Q5 Answer: False. ACK segments do NOT consume sequence numbers and are NOT acknowledged. Only data segments and control segments that consume a sequence number are acknowledged.
Q6 Answer: (1) DNS — needs fast queries, small data, can retry if lost. (2) SNMP — network management needs quick, simple exchanges. (3) Video streaming/VoIP — real-time applications where speed matters more than perfect reliability; a lost packet is better than a delayed one. (Other valid answers: TFTP, RIP, DHCP.)
Challenge Exam Questions – Transport Layer
Dear students, these questions are designed to test your deep understanding. Try each one before checking the answer!
Q1. A TCP connection has an Initial Sequence Number (ISN) of 1059. If the first segment carries 1,500 bytes of data, what is the sequence number of the second segment?
- a) 1059
- b) 1500
- c) 2559
- d) 2560
Answer: (c) 2559.
The sequence number of the second segment = ISN + bytes in first segment = 1059 + 1500 = 2559. Remember: the sequence number is the byte number of the first byte in the segment, so the next segment starts at byte 2559.
Q2. In the TCP header, the data offset field has a value of 10 (in decimal). What is the size of the TCP header?
- a) 10 bytes
- b) 40 bytes
- c) 20 bytes
- d) 50 bytes
Answer: (b) 40 bytes.
Header Length = Data Offset × 4 = 10 × 4 = 40 bytes. The data offset field value 10 means 10 four-byte words = 40 bytes. This also tells us there are 20 bytes of options (40 – 20 = 20).
Q3. Which of the following statements about TCP and UDP is CORRECT?
- a) Both TCP and UDP provide flow control
- b) Both TCP and UDP have mandatory checksums
- c) TCP provides reliable delivery; UDP does not
- d) Both TCP and UDP support segmentation and reassembly
Answer: (c).
TCP provides reliable delivery through error control mechanisms. UDP does not. Option (a) is wrong because UDP does not provide flow control. Option (b) is wrong because UDP’s checksum is optional. Option (d) is wrong because UDP cannot segment or reassemble data.
Q4. A receiver sends an acknowledgment number of 3001. Which of the following is true?
- a) The receiver has received exactly 3001 bytes
- b) The receiver has received all bytes up to byte 3000
- c) The receiver has received byte 3001 but not byte 3000
- d) The receiver wants to receive 3001 more bytes
Answer: (b).
The acknowledgment number is cumulative. ACK = 3001 means the receiver has safely received all bytes from the beginning up to byte 3000, and it now expects byte 3001 next. It does NOT mean 3001 bytes total were received, because numbering may not start from 0.
Q5. In the Go-Back-N protocol with a window size of 5, the sender has sent frames 0, 1, 2, 3, and 4. Frame 2 is lost. What does the sender retransmit?
- a) Only frame 2
- b) Frames 2, 3, and 4
- c) Frames 0 through 4
- d) Only frame 3
Answer: (b) Frames 2, 3, and 4.
In Go-Back-N, when frame 2 is lost, the receiver discards frame 3 and frame 4 (out-of-order packets are discarded). The sender must “go back” to frame 2 and retransmit frame 2 and all frames sent after it (frames 3 and 4). Frames 0 and 1 were already acknowledged, so they are not retransmitted.
Q6. A client wants to access a web server. Which port numbers will be used?
- a) Source: 80, Destination: ephemeral port
- b) Source: ephemeral port, Destination: 80
- c) Source: 80, Destination: 80
- d) Source: ephemeral port, Destination: 443
Answer: (b).
The client uses a randomly generated ephemeral port as the source port. The destination port is the well-known port of the service being requested — port 80 for HTTP. Option (d) would be correct for HTTPS, but the question says “web server” without specifying HTTPS.
Q7. The transport layer header must include a ________ address to ensure process-to-process delivery.
Answer: Service-point (or Port). The service-point address, also called a port address or port number, identifies the specific process on a host.
Q8. In TCP, the ISN is generated using a ________ number generator, and it is a number between 0 and ________.
Answer: Random, 2^32 – 1 (or 4,294,967,295). TCP uses a random number generator to create the Initial Sequence Number, which can be any value from 0 to 2^32 – 1. This is for security and to avoid confusion with old connections.
Q9. The combination of an IP address and a port number is called a ________ address, and a pair of these (client + server) is needed for a complete TCP connection.
Answer: Socket. A socket address = IP address + port number. A complete connection requires four pieces of information: source IP, source port, destination IP, destination port — forming a pair of socket addresses.
Q10. ________ is a relationship at the sender side (many-to-one), while ________ is a relationship at the receiver side (one-to-many).
Answer: Multiplexing, Demultiplexing. Multiple processes feed into one transport layer (multiplexing = many-to-one). One transport layer delivers to multiple processes (demultiplexing = one-to-many).
Q11. Port numbers from ________ to ________ are the ephemeral (dynamic) ports used by client processes.
Answer: 49,152 to 65,535. These are the dynamic/ephemeral ports. They are not controlled or registered by IANA and can be used by any client process as temporary ports.
Q12. True or False: TCP is a message-oriented protocol that preserves message boundaries.
Answer: False. TCP is a stream-oriented protocol, NOT message-oriented. It does NOT preserve message boundaries. Data is sent as a continuous stream of bytes. UDP is message-oriented.
Q13. True or False: Flow control at the transport layer is performed across a single link between two adjacent nodes.
Answer: False. Flow control at the transport layer is performed end to end (between the source process and destination process). Flow control across a single link is done at the data link layer.
Q14. True or False: Error control at the transport layer is performed process-to-process, and error correction is usually achieved through retransmission.
Answer: True. Unlike the data link layer where error control is across a single link, transport layer error control is process-to-process. The main method of error correction is retransmission of lost or corrupted segments.
Q15. True or False: A server process can use any random port number because the client will discover it automatically.
Answer: False. A server process MUST use a well-known port number so that clients know which port to connect to. If servers used random ports, clients would not know how to reach the service. Well-known ports are standardized by IANA.
Q16. True or False: The Selective-Repeat protocol is less efficient than Go-Back-N when the network frequently loses packets.
Answer: False. Selective-Repeat is MORE efficient than Go-Back-N when packets are frequently lost. Go-Back-N retransmits the lost packet AND all subsequent packets, wasting bandwidth. Selective-Repeat retransmits ONLY the lost packets.
Q17. Explain the difference between node-to-node delivery, host-to-host delivery, and process-to-process delivery. Which layer handles each type?
Answer:
Node-to-node delivery: Delivery of frames between two directly connected neighboring nodes over a single link. Handled by the Data Link Layer using MAC addresses.
Host-to-host delivery: Delivery of datagrams between two hosts (computers) that may be far apart, possibly through multiple intermediate routers. Handled by the Network Layer using IP addresses.
Process-to-process delivery: Delivery of the complete message from a specific application (process) on the source host to the correct application (process) on the destination host. Handled by the Transport Layer using port numbers.
Q18. What is a socket address? What four pieces of information are needed for a complete TCP connection?
Answer: A socket address is the combination of an IP address and a port number. It uniquely identifies a process running on a specific host. For a complete TCP connection, four pieces of information are needed: (1) Source IP address, (2) Source port number, (3) Destination IP address, (4) Destination port number. These form a pair of socket addresses — the client socket address and the server socket address.
Q19. Why does the transport layer need segmentation and reassembly, but UDP does not provide this feature? What limitation does this place on UDP?
Answer: Segmentation is needed when the message from the application is too large to fit into a single packet. TCP handles this by dividing the message into segments, numbering each byte, and reassembling them at the destination. UDP does NOT perform segmentation or reassembly because it has no sequence numbers. This means UDP can only transmit small amounts of data that fit into a single user datagram. If the application has a large message, it must handle segmentation itself or use TCP instead.
Q20. List and explain the three tools TCP uses for error detection and correction.
Answer:
1. Checksum: A mandatory 16-bit value in every TCP segment. The receiver calculates the checksum and compares it with the value in the header. If they do not match, the segment is corrupted and is discarded (treated as lost).
2. Acknowledgment: The receiver sends an acknowledgment number to confirm which bytes have been received. This lets the sender know which data has arrived safely and which may be missing.
3. Timeout: The sender starts a timer when it sends a segment. If the acknowledgment does not arrive before the timer expires, the sender assumes the segment was lost and retransmits it.
Q21. A TCP header dump is given in hexadecimal as: 1F40 0050 00002000 00002001 6002 FFF0 00000000
Find: (a) Source port number, (b) Destination port number, (c) Sequence number, (d) Acknowledgment number, (e) Header length in bytes, (f) Window size in decimal.
Detailed Solution:
(a) Source Port: 1F40 = \(1 \times 4096 + 15 \times 256 + 4 \times 16 + 0 = 4096 + 3840 + 64 + 0 = \boxed{8000}\)
(b) Destination Port: 0050 = \(0 + 0 + 5 \times 16 + 0 = \boxed{80}\) (HTTP)
(c) Sequence Number: 00002000 = \(2 \times 16^3 = 2 \times 4096 = \boxed{8192}\)
(d) Acknowledgment Number: 00002001 = \(8192 + 1 = \boxed{8193}\)
(e) Header Length: Looking at 6002, the data offset (first hex digit) = 6. So \(6 \times 4 = \boxed{24 \text{ bytes}}\). This means there are 4 bytes of options (24 – 20 = 4).
(f) Window Size: FFF0 = \(15 \times 4096 + 15 \times 256 + 15 \times 16 + 0 = 61440 + 3840 + 240 + 0 = \boxed{65,520 \text{ bytes}}\)
Q22. A UDP header dump is: 001E 0035 0024 1A2B
Find: (a) Source port, (b) Destination port, (c) Total length, (d) Data length.
Detailed Solution:
(a) Source Port: 001E = \(1 \times 16 + 14 = \boxed{30}\)
(b) Destination Port: 0035 = \(3 \times 16 + 5 = \boxed{53}\) (DNS!)
(c) Total Length: 0024 = \(2 \times 16 + 4 = \boxed{36 \text{ bytes}}\)
(d) Data Length: Total length – UDP header = \(36 – 8 = \boxed{28 \text{ bytes}}\)
Q23. A TCP connection starts with ISN = 20,000 at the sender. The sender transmits 5 segments of 1,000 bytes each. Write the sequence number for each segment and the acknowledgment number the receiver will send after receiving all 5 segments.
Solution:
Segment 1: Sequence Number = 20,000 (bytes 20,000 to 20,999)
Segment 2: Sequence Number = 21,000 (bytes 21,000 to 21,999)
Segment 3: Sequence Number = 22,000 (bytes 22,000 to 22,999)
Segment 4: Sequence Number = 23,000 (bytes 23,000 to 23,999)
Segment 5: Sequence Number = 24,000 (bytes 24,000 to 24,999)
Acknowledgment after all 5: Last byte received = 24,999. ACK = 24,999 + 1 = 25,000
Pattern: Each sequence number increases by 1,000 (the segment size). The final ACK = ISN + total bytes = 20,000 + 5,000 = 25,000.
Q24. A TCP segment has a header length field (data offset) of 12. Calculate: (a) The header length in bytes, (b) The size of the options field.
Solution:
(a) Header Length: \(12 \times 4 = \boxed{48 \text{ bytes}}\)
(b) Options Size: Total header (48) – Minimum header (20) = \(\boxed{28 \text{ bytes}}\)
The maximum possible options size is 40 bytes (when header = 60 bytes). Here, 28 bytes of options are present, which is within the limit.
Q25. Which of the following correctly describes the relationship between TCP segmentation and IP fragmentation?
- a) TCP segments messages; IP fragments segments
- b) TCP and IP both segment messages at the same layer
- c) TCP segments messages into segments; IP may further fragment these segments into smaller packets
- d) IP segments messages; TCP does not
Answer: (c). TCP segments the application’s message into TCP segments. These segments are then passed to IP. If a TCP segment is still too large for the underlying network, IP may fragment it further into smaller IP datagrams. They work at different layers and perform different (but related) functions.
Q26. A student says: “UDP is useless because it does not provide reliability.” Do you agree? Give three reasons why UDP is still useful.
Answer: No, I disagree. UDP is very useful in many situations:
1. Speed: UDP has minimal overhead (only 8-byte header, no connection setup), making it much faster than TCP. For applications where speed is more important than perfect reliability, UDP is better.
2. Applications with built-in error control: Some applications like TFTP have their own flow and error control mechanisms. They do not need TCP’s reliability features.
3. Multicasting and broadcasting: UDP supports multicasting, which TCP does not. Applications like video conferencing, live streaming, and route updating protocols (RIP) need this capability.
4. Simple request-response: For small queries like DNS lookups, the overhead of TCP’s connection setup is unnecessary.
Q27. In TCP, what does the term “piggybacking” mean?
- a) Sending data without a header
- b) Including an acknowledgment in a data segment
- c) Using multiple connections simultaneously
- d) Sending the same segment twice
Answer: (b). Piggybacking means the receiver includes an acknowledgment number in a data segment that it is sending in the opposite direction. This saves bandwidth because a separate ACK segment is not needed. Since TCP is full-duplex, both sides can send data and acknowledgments at the same time.
Q28. True or False: The network layer treats each packet independently and does not recognize any relationship between packets belonging to the same message.
Answer: True. This is a fundamental characteristic of the network layer. It handles each packet as an independent unit. The transport layer is responsible for recognizing the relationship between packets and reassembling them into the original message.
Q29. TCP provides ________ communication, which means data can flow in both directions at the same time, with each direction having its own sending and receiving ________.
Answer: Full-duplex, buffers. TCP’s full-duplex service allows simultaneous two-way communication. Each direction has its own sending buffer (at the sender) and receiving buffer (at the receiver).
Q30. Compare the Go-Back-N and Selective-Repeat protocols in terms of: (a) Receiver buffering capability, (b) Retransmission strategy, (c) Efficiency in error-prone networks.
Answer:
(a) Receiver buffering: Go-Back-N can buffer only 1 packet. Selective-Repeat can buffer multiple packets (up to the window size).
(b) Retransmission strategy: Go-Back-N retransmits the lost packet AND all packets sent after it. Selective-Repeat retransmits ONLY the lost packets.
(c) Efficiency in error-prone networks: Selective-Repeat is much more efficient when the network frequently loses packets because it avoids unnecessary retransmissions. Go-Back-N wastes bandwidth by retransmitting correctly received packets that arrived after the lost one.