2080 3

CSC263 ยท 2080 ยท 10 marks

Explain TCP header with a neat diagram. Highlight on its uses.

Explain TCP header with a neat diagram. Highlight on its uses.[10]

Computer NetworksChapter 5: Transport LayerTransport Protocols

Quick answer

TCP (Transmission Control Protocol) is a connection-oriented, reliable transport layer protocol defined in RFC 793. It provides end-to-end reliable data delivery, flow control, error control, and congestion control between two communicating hosts. The TCP header is attached to the data segment before passing it down to the network layer.

TCP Header - Explanation with Diagram

Introduction


TCP Header Diagram

 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|          Source Port          |       Destination Port        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                        Sequence Number                        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                    Acknowledgment Number                      |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| HLEN  |  Resv |U|A|P|R|S|F|        Window Size               |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|           Checksum            |         Urgent Pointer        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                    Options (if any)          | Padding        |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                          Data                                 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Flags: U=URG, A=ACK, P=PSH, R=RST, S=SYN, F=FIN
Minimum Header Size = 20 bytes

Detailed Explanation of Each Field

1. Source Port (16 bits)

  • Identifies the port number of the sending application on the source host.
  • Port numbers range from 0 to 65535.
  • Example: A web browser may use ephemeral port 49200 as source port.
  • Use: Helps the receiving end identify which application sent the data, enabling multiplexing.

2. Destination Port (16 bits)

  • Identifies the port number of the receiving application on the destination host.
  • Example: Port 80 for HTTP, Port 443 for HTTPS, Port 21 for FTP.
  • Use: Directs the incoming segment to the correct application process (demultiplexing).

3. Sequence Number (32 bits)

  • Indicates the byte number of the first byte of data in the current segment.
  • During connection establishment (SYN), it carries the Initial Sequence Number (ISN).
  • Use: Ensures ordered delivery of data. The receiver uses this to reassemble segments in the correct order.

4. Acknowledgment Number (32 bits)

  • Valid only when the ACK flag is set.
  • Contains the sequence number of the next byte the receiver expects to receive.
  • Use: Confirms receipt of data and provides reliable, error-free delivery. Supports cumulative acknowledgment.

5. Header Length / HLEN (4 bits)

  • Specifies the length of the TCP header in 32-bit words.
  • Minimum value = 5 (20 bytes), Maximum value = 15 (60 bytes).
  • Use: Tells the receiver where the header ends and the actual data begins, since the Options field makes the header variable in length.

6. Reserved (6 bits)

  • These bits are reserved for future use and must be set to zero.
  • Use: Ensures backward compatibility for future protocol extensions.

7. Control Flags (6 bits)

Each flag is 1 bit and serves a specific purpose:

FlagNameUse
URGUrgentIndicates urgent data is present; Urgent Pointer field is valid
ACKAcknowledgmentAcknowledgment Number field is valid
PSHPushReceiver should pass data to application immediately without buffering
RSTResetAbruptly terminates/resets the connection
SYNSynchronizeUsed during connection establishment (3-way handshake) to synchronize sequence numbers
FINFinishUsed during connection termination; sender has no more data to send

8. Window Size (16 bits)

  • Specifies the number of bytes the sender is willing to accept from the receiver (receive buffer size).
  • Maximum window size = 65535 bytes.
  • Use: Implements flow control using the sliding window mechanism. Prevents the sender from overwhelming the receiver with too much data.

9. Checksum (16 bits)

  • Covers the entire TCP segment (header + data) plus a pseudo-header (source IP, destination IP, protocol, TCP length).
  • Calculated by the sender and verified by the receiver.
  • Use: Provides error detection. If the checksum does not match, the segment is discarded.

10. Urgent Pointer (16 bits)

  • Valid only when the URG flag is set.
  • Points to the last byte of urgent data within the segment.
  • Use: Allows TCP to send out-of-band urgent data (e.g., interrupt signals) that must be processed immediately by the receiving application.

11. Options (Variable, 0 to 40 bytes)

  • Carries optional parameters negotiated when the connection is opened, such as the maximum segment size, the window scale factor, selective acknowledgment permission and timestamps.
  • Present only when HLEN is greater than 5, which is how the header grows from 20 bytes to at most 60 bytes.
  • Use: Lets TCP extend its behaviour beyond the fixed part of the header, for example by agreeing on a larger window or on a segment size that avoids fragmentation.

12. Padding (Variable)

  • Zero bits appended after the options so that the header ends on a 32-bit word boundary.
  • Use: Keeps the header length an exact multiple of 4 bytes so that the value in HLEN remains meaningful.

Uses of the TCP Header

PurposeFields that provide it
Process to process deliverySource Port, Destination Port
Ordered delivery and reassemblySequence Number
Reliability and retransmissionAcknowledgment Number, ACK flag
Connection setup and releaseSYN, ACK, FIN, RST flags
Flow controlWindow Size
Error detectionChecksum
Priority (out-of-band) dataURG flag, Urgent Pointer
Header extensionHLEN, Options, Padding

Conclusion

Every field in the TCP header exists to support one of the guarantees TCP makes. The port numbers deliver the segment to the correct process, the sequence and acknowledgment numbers together with the checksum make delivery reliable and in order, the control flags manage the life of the connection, and the window size keeps a fast sender from overwhelming a slow receiver. This is why the header is 20 bytes at minimum and can reach 60 bytes once options are negotiated.

Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.