TCP (Transmission Control Protocol): Services, Byte-Stream Model, Segment Header, Flags, MSS, Options and Window Fields
A complete illustrated tutorial for APPSC Assistant Professor, RGUKT Lecturer, UGC NET and GATE. Based on Tanenbaum & Wetherall and Behrouz A. Forouzan, with compact diagrams, animations, formulas, step-by-step numericals and original practice MCQs.
TCP (Transmission Control Protocol) is a connection-oriented transport protocol that supplies a reliable, ordered byte stream between two application processes. TCP uses ports to identify processes, sequence and acknowledgement numbers to track data, a sliding window for flow control and congestion-control mechanisms to regulate traffic.
1. TCP Fundamentals and Services
Tanenbaum introduces TCP as a protocol built to deliver a dependable end-to-end byte stream even when IP datagrams are lost, delayed, duplicated or delivered out of order. Forouzan calls it a reliable, connection-oriented process-to-process transport protocol.
Reliable
Detects loss and recovers through acknowledgements and retransmissions.
Ordered
Returns application bytes in sequence, even when segments arrive out of order.
Full duplex
Two endpoints can send and receive at the same time.
Connection-oriented
Establishes a logical connection, transfers data, then releases it.
Flow controlled
Uses the receiver-advertised window to avoid overrunning the destination buffer.
Congestion controlled
Adapts its outstanding data to network conditions via the congestion window.
TCP socket address: IP address + port number. A TCP connection is distinguished by the combination of protocol, source IP/port and destination IP/port (the five-tuple). TCP is point-to-point: it does not itself provide IP multicast or broadcast connections.
2. TCP Byte-Stream Model and Animated Example
TCP is stream-oriented, not message-oriented. If an application makes four writes of 512 bytes, a receiver may obtain the same 2048 bytes in one read or in several reads. The original write boundaries do not survive automatically. This is illustrated in Tanenbaum Figure 6-35 and Forouzan Figure 23.13.
Write bytes
Read bytes
2.1 Sending and receiving buffers
Forouzan Figure 23.14 illustrates circular buffers: the sender retains bytes already sent but not yet acknowledged, alongside data waiting to be sent. The receiver stores accepted bytes until the application reads them. Buffers allow application and network rates to differ.
send() does not guarantee a single matching recv().3. TCP Segmentation and Encapsulation
The application supplies a continuous byte stream. TCP takes groups of bytes, adds a TCP header, and hands each segment to IP. IP encapsulates it in an IP packet; a data-link technology such as Ethernet wraps the packet in a frame.
Byte stream
Segment
Packet
Frame
The number of TCP data bytes in a segment is influenced by the Maximum Segment Size (MSS), the receiver's advertised capabilities, path MTU, buffering and other implementation considerations. The transport-layer unit is called a TCP segment.
4. TCP Segment Header Format — Complete Diagram
The fixed TCP header is 20 bytes (five rows of 32 bits). Options and padding may extend the header to 60 bytes. The diagram below follows Tanenbaum Figure 6-36 (eight control flags), rather than Forouzan's six-flag rendering.
Minimum header
20 bytes = 160 bits
Maximum header
60 bytes = 480 bits
Data Offset
4 bits, measured in 32-bit words
For Data Offset = 8, header length = 8 × 4 = 32 bytes, leaving 32 − 20 = 12 bytes for options and padding.
5. TCP Header Fields — Field-by-Field Explanation
| Field | Size | Meaning / exam point |
|---|---|---|
| Source Port | 16 bits | Sender's application endpoint; part of the connection five-tuple. |
| Destination Port | 16 bits | Recipient application endpoint, for example HTTP typically uses TCP 80. |
| Sequence Number | 32 bits | Number of the first application-data byte in the segment; SYN and FIN consume one sequence number. |
| Acknowledgement Number | 32 bits | Next in-order byte expected from peer; valid when ACK flag = 1; cumulative. |
| Data Offset | 4 bits | Length of TCP header in 32-bit words; usually 5–15. |
| Reserved + Flags | 4 + 8 bits in Tanenbaum | Reserved bits and control bits for connection management, urgent data, and congestion feedback. |
| Window Size | 16 bits | Receiver-advertised receive window, subject to negotiated scaling. |
| Checksum | 16 bits | Mandatory error-detection checksum over TCP header, payload, and conceptual IP pseudoheader. |
| Urgent Pointer | 16 bits | Meaningful when URG=1; seldom used. |
| Options + Padding | 0–40 bytes | MSS, Window Scale, Timestamp, SACK, etc.; header aligned to a 32-bit boundary. |
5.1 Sequence number and cumulative acknowledgement
TCP assigns sequence numbers to bytes, not packets. Forouzan Example 23.3 divides 5000 bytes into five segments of 1000 bytes, with the first data byte numbered 10,001. Segment sequence numbers are 10,001; 11,001; 12,001; 13,001; 14,001. The cumulative acknowledgement after all five segments is 15,001, provided the bytes arrive in order.
If bytes 3000–3499 are missing, receiving bytes 3500–3999 does not advance the cumulative ACK beyond 3000. Optional SACK information can separately report out-of-order data.
5.2 TCP checksum
Both textbooks identify the TCP checksum as mandatory. It uses one's-complement arithmetic over the TCP segment and a conceptual IP pseudoheader containing information such as IP source/destination addresses and IP protocol number 6. The pseudoheader is used in the checksum calculation; it is not a separate wire-level TCP field.
6. TCP Control Flags — URG, ACK, PSH, RST, SYN, FIN, ECE and CWR
| Flag | What it signals | Exam memory cue |
|---|---|---|
| SYN | Synchronization of sequence numbers for connection establishment. | Open a TCP connection |
| ACK | Acknowledgement-number field is valid. | Next expected byte |
| FIN | Sender has no more data to send in that direction. | Close one direction |
| RST | Abrupt reset or rejection of a connection attempt. | Reset/refuse |
| PSH | Requests prompt handoff of received data to the application. | Push |
| URG | Urgent pointer is relevant to urgent-data handling. | Urgent |
| ECE | Echoes an Explicit Congestion Notification in the ECN mechanism. | ECN Echo |
| CWR | Indicates congestion window was reduced in response to congestion feedback. | Congestion Window Reduced |
6.1 Control flags and sequence numbers
A SYN or FIN consumes one sequence number even without ordinary application data. A pure ACK with no SYN/FIN and no payload consumes no data-sequence space. A FIN+ACK can both acknowledge previous bytes and consume one sequence number in its sender's direction.
7. Maximum Segment Size (MSS) versus MTU
MTU (Maximum Transmission Unit) limits an IP packet's size over a link. MSS (Maximum Segment Size) counts only the TCP data bytes per segment, not TCP or IP headers. The textbook uses an Ethernet MTU of 1500 bytes and a common TCP MSS of 1460 bytes for IPv4 when both headers have no options.
IPv4 example
1500 − 20 − 20 = 1460 bytes
IPv6 example
1500 − 40 − 20 = 1440 bytes, assuming no extension headers and no TCP options.
MSS normally indicates the maximum TCP data payload a peer can accept, and can be advertised using a TCP option during connection setup. Unlike MTU, it does not include headers. Actual packetization can be constrained further by path MTU, TCP options and implementation behavior.
8. TCP Options — MSS, Window Scale, Timestamp and SACK
TCP options extend the fixed 20-byte header. The Data Offset field still counts the entire header, so options and padding are included in the header-length calculation. Both textbooks cover optional TCP header space, and Tanenbaum discusses several important examples.
| Option | Purpose | Exam point |
|---|---|---|
| MSS | Advertises the maximum TCP data size the endpoint is willing to receive. | Concerned with payload, not total frame length. |
| Window Scale | Extends effective receive-window capability beyond the 16-bit unscaled field. | Scaled advertised window = field value × 2shift. |
| Timestamp | Supports RTT measurements and protection against old wrapped sequence numbers (PAWS). | Timestamp value and echoed timestamp. |
| SACK | Reports selected out-of-order received byte ranges. | Complements cumulative ACK for more targeted recovery. |
8.1 TCP Window Scale
Example: Window field = 20,000, negotiated scale factor = 3. The effective advertised receive window is 20,000 × 8 = 160,000 bytes.
9. TCP Window Fields: rwnd versus cwnd
The TCP header contains the receiver's advertised Window Size field (rwnd). The sender also maintains a congestion window (cwnd), which is a local control variable rather than a field carried in every TCP header.
The following example assumes: rwnd = 8 KB, cwnd = 6 KB, and bytes already sent but unacknowledged = 2 KB. Then the effective cap is 6 KB and the sender may transmit 4 KB more, subject to other constraints.
9.1 What if rwnd = 0?
TCP must stop sending ordinary new application data when the receive window is closed. As explained in Tanenbaum, TCP's persistence timer and window probes help handle cases where a later nonzero window advertisement is lost. A zero receive window is a flow-control condition, not proof that the network is congested.
10. Solved TCP Numerical Problems
Example 1 — Header length and option space
Question: TCP Data Offset = 11. Find header size, options/padding size and maximum TCP payload in a 1500-byte MTU IPv4 packet with a 20-byte IPv4 header.
Header = 11 × 4 = 44 bytes.
Options and padding = 44 − 20 = 24 bytes.
Payload = 1500 − 20 − 44 = 1436 bytes.
Example 2 — Forouzan-style byte sequencing
Question: 5000 bytes start with TCP data sequence 10,001 and are divided into five 1000-byte data segments. Find their sequence numbers and cumulative ACK when all bytes arrive correctly.
Sequence numbers = 10,001; 11,001; 12,001; 13,001; 14,001.
Final byte = 15,000. Next expected byte = ACK 15,001.
Example 3 — SYN sequence consumption
Question: Client sends SYN with seq = 7,000. Server sends SYN with seq = 24,000. Determine ACKs for the normal three-way handshake (no payload).
Server SYN+ACK has ACK = 7,001. Client's final ACK has seq = 7,001 and ACK = 24,001.
Example 4 — Effective window and new data
Question: rwnd = 10 KB, cwnd = 7 KB and bytes in flight = 3 KB. How much additional data can the sender transmit?
Effective cap = min(10,7) = 7 KB. New allowance = 7 − 3 = 4 KB.
Example 5 — TCP window scale
Question: Advertised Window field = 30,000, negotiated scale = 4. Find scaled rwnd.
rwnd = 30,000 × 24 = 30,000 × 16 = 480,000 bytes.
Example 6 — Bandwidth-delay product
Question: A path offers 20 Mbps and has an RTT of 80 ms. How many bytes must be in flight to fill the path, ignoring overhead?
BDP = 20,000,000 bits/s × 0.080 s = 1,600,000 bits = 200,000 bytes.
A default unscaled maximum advertised window of 65,535 bytes would be smaller than that required amount; window scaling may be necessary.
Example 7 — Lost data and cumulative ACK
Question: Data segment A contains bytes 2000–2499, segment B contains 2500–2999 (lost), segment C contains 3000–3499 (received out of order). What cumulative ACK remains after C arrives?
The receiver is still waiting for byte 2500, so cumulative ACK = 2500. After B is recovered, it can advance to 3500 if all listed bytes are present.
10.1 Formula Revision Table
| Formula | Use |
|---|---|
| TCP header = Data Offset × 4 | Header-length and options questions |
| TCP payload = MTU − IP header − TCP header | Unfragmented-packet example under stated assumptions |
| ACK = first data sequence + contiguous bytes | In-order byte acknowledgement |
| rwnd (scaled) = window field × 2shift | When window scaling negotiated |
| Effective cap = min(rwnd, cwnd) | Flow/congestion limits |
| BDP = bandwidth × RTT | Bits in flight to fill a path |
11. APPSC / UGC NET / GATE-Style MCQs (20 Questions)
These are original practice MCQs inspired by the two textbook chapters. They are not represented as verbatim previous-year questions. Open the answer below each question to verify your reasoning.
Q1. TCP provides which type of application service?
- Unreliable message delivery
- Reliable ordered byte stream
- Host-to-host routing only
- Unordered broadcast
Show correct answer and explanation
Answer: B — Reliable ordered byte stream. TCP offers reliable, ordered byte-stream delivery between processes.
Q2. The minimum TCP segment header length is:
- 8 bytes
- 12 bytes
- 20 bytes
- 32 bytes
Show correct answer and explanation
Answer: C — 20 bytes. The fixed header is five 32-bit words, or 20 bytes.
Q3. The maximum size of the TCP header is:
- 40 bytes
- 60 bytes
- 64 bytes
- 80 bytes
Show correct answer and explanation
Answer: B — 60 bytes. A 4-bit Data Offset of 15 gives 15 × 4 = 60 bytes.
Q4. The TCP header Data Offset field counts units of:
- Bytes
- Bits
- 32-bit words
- Segments
Show correct answer and explanation
Answer: C — 32-bit words. Each unit is a four-byte (32-bit) word.
Q5. If Data Offset = 9, the TCP header contains how many bytes?
- 18
- 24
- 36
- 40
Show correct answer and explanation
Answer: C — 36. 9 × 4 = 36 bytes.
Q6. Which field is 32 bits wide?
- Window Size
- Destination Port
- Urgent Pointer
- Sequence Number
Show correct answer and explanation
Answer: D — Sequence Number. TCP sequence and acknowledgement numbers are each 32 bits.
Q7. TCP sequence numbers refer primarily to:
- Segments
- Bytes
- Frames
- IP hops
Show correct answer and explanation
Answer: B — Bytes. TCP assigns sequence numbers to individual bytes in each direction.
Q8. A segment starts with data byte 5000 and carries 800 data bytes; without SYN/FIN the next ACK is:
- 5001
- 5799
- 5800
- 6000
Show correct answer and explanation
Answer: C — 5800. Bytes 5000–5799 are covered; the next expected byte is 5800.
Q9. Which flags consume one sequence number even if no application data are present?
- ACK and PSH
- SYN and FIN
- URG and ECE
- RST and CWR
Show correct answer and explanation
Answer: B — SYN and FIN. SYN and FIN each consume one sequence number.
Q10. A TCP connection is:
- Multicast and unreliable
- Connectionless datagram-oriented
- Point-to-point, full duplex
- A physical reserved circuit
Show correct answer and explanation
Answer: C — Point-to-point, full duplex. TCP connections are logical, point-to-point and full-duplex.
Q11. TCP 'message boundaries are not preserved' means:
- Data can never be segmented
- A receiver's read sizes can differ from send sizes
- TCP reorders application bytes
- TCP cannot send files
Show correct answer and explanation
Answer: B — A receiver's read sizes can differ from send sizes. Application write boundaries are not delivered as inherent messages.
Q12. What does the TCP Window Size field advertise?
- Router queue occupancy
- Receiver's available flow-control window
- Maximum Ethernet frame length
- The sender's congestion window
Show correct answer and explanation
Answer: B — Receiver's available flow-control window. The window field is receiver-advertised flow-control information.
Q13. When rwnd = 12 KB, cwnd = 9 KB and 5 KB is in flight, the new-data allowance is:
- 4 KB
- 5 KB
- 7 KB
- 9 KB
Show correct answer and explanation
Answer: A — 4 KB. min(12,9) − 5 = 4 KB.
Q14. Which TCP option is used to announce the maximum TCP data payload?
- SACK
- MSS
- Timestamp
- Urgent pointer
Show correct answer and explanation
Answer: B — MSS. MSS means Maximum Segment Size, measured in TCP data bytes.
Q15. For MTU = 1500 B, IPv4 header = 20 B, TCP header = 20 B, the payload limit is:
- 1460 B
- 1472 B
- 1480 B
- 1500 B
Show correct answer and explanation
Answer: A — 1460 B. 1500 − 20 − 20 = 1460 bytes.
Q16. Which option identifies ranges received beyond the cumulative ACK?
- SACK
- MSS
- ECN
- PSH
Show correct answer and explanation
Answer: A — SACK. SACK provides selective information for received noncontiguous byte ranges.
Q17. The IP protocol number used in a TCP checksum pseudoheader is:
- 1
- 6
- 17
- 89
Show correct answer and explanation
Answer: B — 6. TCP has IP protocol number 6; UDP has 17.
Q18. Which pair of congestion-control flags appears in Tanenbaum's eight-flag header?
- ECE and CWR
- RST and PSH
- SYN and ACK
- FIN and URG
Show correct answer and explanation
Answer: A — ECE and CWR. Tanenbaum includes ECN Echo and Congestion Window Reduced in addition to the classic six flags.
Q19. Forouzan Figure 23.17 displays how many classic TCP flags?
- Four
- Six
- Eight
- Ten
Show correct answer and explanation
Answer: B — Six. The Forouzan fourth-edition figure lists URG, ACK, PSH, RST, SYN and FIN.
Q20. If Window Size = 25,000 and scale = 3, the advertised rwnd is:
- 3,125 bytes
- 25,003 bytes
- 75,000 bytes
- 200,000 bytes
Show correct answer and explanation
Answer: D — 200,000 bytes. 25,000 × 2³ = 200,000 bytes, provided scaling was negotiated.
12. Frequently Asked Questions (SEO FAQs)
What is TCP in computer networks?
TCP is a connection-oriented transport protocol that supplies reliable, ordered byte-stream data transfer between application processes.
How many bytes are in the TCP header?
The fixed TCP header is 20 bytes. Options and padding may increase it up to 60 bytes.
Why is TCP byte-oriented?
Sequence and acknowledgement numbers track byte positions in a continuous stream; application write boundaries are not inherently preserved.
What is the difference between TCP MSS and MTU?
MSS is the maximum TCP data payload per segment; MTU limits the entire IP packet on a link. MSS excludes IP and TCP headers.
What does the TCP ACK number mean?
It indicates the next in-order byte expected by the receiver, not the last received segment number.
Does the TCP header contain the congestion window?
No. The Window Size field advertises receiver flow-control space. Congestion window (cwnd) is maintained locally by the sender.
Which TCP flags are most important for exams?
SYN and ACK for setup, FIN for orderly closing, RST for reset, PSH and URG for data handling, and ECE/CWR for ECN.
What are the major TCP options?
MSS, Window Scale, Timestamp and SACK are the prominent options discussed by Tanenbaum.
Why do textbooks show six or eight TCP flags?
Forouzan’s 4th edition presents the six classic flags; Tanenbaum’s 5th edition additionally labels ECE and CWR for congestion notification.
Is TCP's connection a dedicated physical path?
No. TCP provides a logical connection over the underlying IP network. Segments still travel inside IP datagrams.
13. Textbook References and Syllabus Alignment
| Book / syllabus | Reference |
|---|---|
| Tanenbaum & Wetherall, Computer Networks, 5th ed. | §6.5.1–6.5.4, pp. 552–560; Figure 6-35 (byte stream), Figure 6-36 (TCP header). Supporting TCP sliding window: §6.5.8, pp. 565–568. |
| Behrouz A. Forouzan, Data Communications and Networking, 4th ed. | §23.3 TCP, pp. 715–723; Figures 23.13–23.17 (stream, buffers, TCP segment and classic flags); Example 23.3 (TCP byte numbering). |
| APPSC Assistant Professor — CSE (Code 12) | Computer Networks includes TCP/IP model and congestion control; TCP details are supportive coverage, not separately enumerated in this syllabus. |
| APPSC Assistant Professor — ITE (Code 13) and RGUKT Lecturer IT (Code 92) | Both explicitly list TCP/UDP and sockets, flow/error control and congestion control; direct syllabus relevance. |
0 comments :
Post a Comment
Note: only a member of this blog may post a comment.