Course contents

Unit 7: TCP, UDP and PortsLesson 7.1.2 (2 of 23 in this unit)51 of 104 in the Network Fundamentals course

The TCP header

A capture shows SEQ, ACK, flags and a window value. Which field answers which question? Let's read them as parts of one conversation instead of memorising a list.

Intermediate · 7 min read

Covers Header fields, Flags and Header size.

Technical definition

TCP header is the block of control fields at the start of every TCP segment, 20 bytes long without options and up to 60 bytes with them. It carries the source and destination ports, the sequence and acknowledgement numbers, flags such as SYN, ACK and FIN, the window size and a checksum.

A capture full of unfamiliar fields

You open a packet capture to find out why a web page will not load. Each TCP segment shows a list of fields: flags, sequence numbers, a window size and more. To read the capture, you need to know what each field means. The good news is that there are only about a dozen.

20 to 60 bytes in front of the data

Every TCP segment starts with a header: a block of control information in front of the data. It is at least 20 bytes and at most 60 bytes, depending on how many options it carries. The diagram shows it in rows of 32 bits (4 bytes), the way the standards (RFCs) draw it.

Source port16 bits
Destination port16 bits
Sequence number32 bits
Acknowledgement number32 bits
Data offset4 bitsheader length
Reserved4 bits
Flags8 bitsCWR ECE URG ACK PSH RST SYN FIN
Window16 bits
Checksum16 bits
Urgent pointer16 bits
Options (if any)0–40 bytes

Read each row from left to right. The ruler gives bit positions 0–31 within that row; field sizes are labelled in bits or bytes.

Base TCP header layout in RFC 9293. The fixed part is 20 bytes; options can add up to 40 bytes. Later extensions to the control bits are outside this introductory diagram.

The job of each field

Imagine PC-1 sends a data segment with source port 52000, destination port 443, sequence number 1001 and 500 bytes of payload. The ports identify the application endpoints; SEQ 1001 says where the first byte belongs. If the ACK field is 5001 and the ACK flag is set, that number refers to the other direction: PC-1 expects byte 5001 from the server next.

SEQ describes this direction's byte stream; ACK reports progress in the opposite direction. The window field is also a statement by the sender of this header about its receiving space, not a measured network speed. An ACK-only segment can carry useful control information even when it has no application payload.

Diagram
The job of each field
The job of each field
FieldSizeJob
Source / destination port16 bits eachWhich application sent the segment and which one should receive it
Sequence number32 bitsThe number of the first data byte in this segment
Acknowledgement number32 bitsThe next byte the sender of this segment expects to receive (valid when ACK is set)
Data offset4 bitsHeader length in 4-byte words: 5 means 20 bytes, 15 means 60
Flags8 bitsOn/off bits that show what kind of segment this is
Window16 bitsHow many more bytes the sender of this segment can receive right now
Checksum16 bitsDetects damaged headers or data; a damaged segment is discarded
Urgent pointer16 bitsMarks urgent data when URG is set; rarely used today
Options0–40 bytesExtras such as MSS, window scaling, SACK and timestamps
Read each row across: the left box names the item, the others describe it.

SYN, ACK, FIN, RST and the other flags

A flag is a single bit that is either on (1) or off (0). You will see these six classic flags most often:

Diagram
SYN, ACK, FIN, RST and the other flags
SYN, ACK, FIN, RST and the other flags
FlagMeaningSeen in
SYNSynchronise: “I want to start a connection; here is my first sequence number”The first two handshake messages
ACKThe acknowledgement number is validAlmost every segment after the first SYN
FINFinish: “I have no more data to send”Closing a connection
RSTReset: “stop now; this connection is not valid”Refused or broken connections
PSHPush: requests delivery without waiting for more data; does not mark an application message boundaryData segments
URGThe urgent pointer field is validRare
Read each row across: the left box names the item, the others describe it.

The other two flags, CWR and ECE, are used by Explicit Congestion Notification (ECN), a way for routers to warn about congestion without dropping packets.

When reading a capture of a failed connection, the flags are usually the first thing worth checking. A SYN with no reply points at something dropping traffic on the way; a SYN answered by RST means the host, or a firewall acting for it, refused a connection to that port.

Diagram
Flags change as a connection moves on
Flags change as a connection moves on
Client192.168.1.20:52000RouterServer203.0.113.10:443

Device key: Client (laptop)

Lines show the example’s network connections. Thick links: uplinks/WAN, as labelled. The coloured path and envelope follow the current step; its text identifies the sender, receiver and traffic type.

Reading the addresses

IP labels identify interfaces or destinations. Subnet labels identify networks; /n is the prefix length. A router ID (RID) identifies a routing process and need not be a reachable interface.

An IP address alone is not a URL. A web URL includes a scheme such as https://; an address on a router or printer does not imply a website.

  • Client: 192.168.1.20:52000
  • Server: 203.0.113.10:443
  1. 1. Opening: only SYN is set. The acknowledgement number is not used yet.
  2. 2. Reply: SYN and ACK are both set: the server starts its side of the connection and acknowledges the client's SYN.
  3. 3. Data: a normal data segment has ACK set, often with PSH.
  4. 4. Closing: FIN says this side has finished sending.

Why TCP needs 20 bytes and UDP only 8

Each feature of TCP needs a field. Reliable delivery needs sequence and acknowledgement numbers. Flow control needs the window. Setting up and closing a connection needs the flags. That is why the TCP header is at least 20 bytes, while the UDP header, which offers almost none of these features, is only 8 bytes. The options area has let TCP gain new features over the years without changing the fixed part.

A SYN segment decoded by a capture tool

A packet capture tool such as Wireshark decodes the header for you. Below is the first segment of a connection (a SYN). It is an example written for this lesson, not captured from a real network.

Example decoded TCP header, as a capture tool shows it
Transmission Control Protocol, Src Port: 52000, Dst Port: 443
    Source Port: 52000
    Destination Port: 443
    Sequence Number (raw): 1520031250
    Acknowledgment Number (raw): 0
    1010 .... = Header Length: 40 bytes (10)
    Flags: 0x002 (SYN)
    Window: 64240
    Checksum: 0x5c1a
    Urgent Pointer: 0
    Options: (20 bytes), Maximum segment size, SACK permitted,
             Timestamps, No-Operation (NOP), Window scale
What to look for: Header Length: 40 bytes (10) is the data offset. 10 × 4 = 40 bytes: 20 fixed bytes plus 20 bytes of options. Flags: 0x002 (SYN) shows that only SYN is on, so this is the first message of the handshake. That is also why Acknowledgment Number is 0: the ACK flag is off, so the field is not used yet. The Options line lists what this client offers, such as its MSS and SACK support.

Test yourself on the TCP header

Predict · scenario 1

In a capture, the data offset field of a TCP segment is 5. How long is its TCP header?

Predict · scenario 2

A capture shows a connection that ends suddenly, with no orderly closing exchange. Which flag was most likely in the last segment?

Predict · scenario 3

A receiver's buffer is almost full and it wants the sender to slow down. Which header field does it use to say how much more data it can accept?

Technical references

RFC 9293: base TCP header, connection state, sequence space and delivery.