TCP Header Explained: Format, Fields, Flags & Examples
Learn the Transmission Control Protocol header in clear, practical language. This guide explains every field and flag, sequence numbers, acknowledgments, flow control, checksum, options, connection handshakes and a decoded SYN segment.
What Is TCP?
Transmission Control Protocol (TCP) is a connection-oriented transport layer protocol that presents applications with a reliable, ordered byte stream. TCP divides application data into segments, numbers the bytes, detects corruption and loss, retransmits missing data, and controls how quickly a sender can transmit.
Before normal data transfer, two endpoints establish state with a three-way handshake. During the connection, acknowledgments and receive windows coordinate delivery. TCP is full duplex, so each direction has its own sequence space and normally closes independently.
TCP Header Lesson Contents
1. TCP Header Format and Segment Structure
A TCP segment contains a header followed by zero or more bytes of application data. The fixed fields occupy 20 bytes. Options can extend the header to 60 bytes, and zero padding keeps the header aligned to a 32-bit boundary.
2. TCP Header Fields Explained
The fields below follow their transmission order. Each entry explains one TCP header field, how to interpret it and why the receiver needs it.
Source Port - 16 bits
Purpose: identifies the sending application endpoint. A client commonly receives a temporary, or ephemeral, source port from its operating system.
Example: source port 41,417 can identify one client-side connection while the server listens on a known destination port.
Destination Port - 16 bits
Purpose: identifies the receiving application or service on the destination host.
Example: destination port 443 normally indicates HTTPS, while port 22 normally indicates SSH.
Sequence Number - 32 bits
Purpose: normally identifies the first application-data byte carried in this segment. TCP numbers bytes rather than packets.
SYN behavior: when SYN is set, this field carries the initial sequence number. The first data byte then uses the next sequence number because SYN consumes one position.
Acknowledgment Number - 32 bits
Purpose: when ACK is set, identifies the next sequence number this sender expects from its peer.
Example: ACK 1,500 confirms receipt through byte 1,499 and asks for byte 1,500 next. TCP acknowledgments are normally cumulative.
Data Offset - 4 bits
Purpose: tells the receiver where the TCP header ends and application data begins.
How to read it: the value counts 32-bit words. Data Offset 5 means 5 x 4 = 20 bytes; value 6 means 24 bytes. The maximum value 15 represents 60 bytes.
Reserved - 4 bits
Purpose: keeps space available for future protocol extensions.
Current rule: RFC 9293 senders set these bits to zero. Receivers ignore reserved bits for features they do not implement.
Control Flags - 8 bits
Purpose: communicates connection state and special handling. The flags are CWR, ECE, URG, ACK, PSH, RST, SYN and FIN.
Example: SYN begins connection establishment, SYN+ACK answers it, FIN closes one direction normally, and RST aborts or rejects a connection.
Window - 16 bits
Purpose: advertises how many bytes beginning at the acknowledgment number the sender of this segment can currently receive.
Flow control: the advertised receive window protects the receiver's buffer. A negotiated Window Scale option can increase the effective value beyond 65,535 bytes.
Checksum - 16 bits
Purpose: detects accidental corruption and helps protect against delivery using incorrect IP endpoint information.
Coverage: the mandatory checksum includes an IP pseudo-header, the complete TCP header and options, and all TCP application data.
Urgent Pointer - 16 bits
Purpose: indicates the sequence position immediately after urgent data.
When valid: the receiver interprets this field only when URG is set. Urgent-data behavior is uncommon in modern applications.
Options and Padding - 0 to 40 bytes
Purpose: adds negotiated capabilities such as Maximum Segment Size, Window Scale, Selective Acknowledgment and Timestamps.
Alignment: padding makes the complete header an integer number of 32-bit words. Data Offset includes both options and padding.
3. Ports, Sequence Numbers and Acknowledgments
TCP identifies a connection using the source and destination IP addresses, source and destination ports, and protocol. A client normally uses an ephemeral source port while the server listens on a known destination port.
Sequence Number
Tracks byte positions, not segment counts. If a segment begins at sequence 1,000 and carries 500 bytes, the next unsent byte is 1,500.
Acknowledgment Number
Is cumulative: ACK 1,500 means every byte through 1,499 has been received and byte 1,500 is expected next.
SYN sequence use
SYN carries an initial sequence number and consumes one sequence number even when it carries no application data.
FIN sequence use
FIN also consumes one sequence number because it marks the end of the sender's byte stream.
| Application | Common TCP port | Purpose |
|---|---|---|
| FTP control | 21 | File-transfer commands |
| SSH | 22 | Secure remote access |
| Telnet | 23 | Unencrypted remote terminal |
| SMTP | 25 | Mail transfer |
| HTTP | 80 | Web traffic |
| HTTPS | 443 | HTTP protected by TLS |
4. TCP Flags Explained
The control bits describe the purpose and state of a segment. Several flags can be active at once, such as SYN+ACK during connection establishment or FIN+ACK during an orderly close.
CWR
Congestion Window Reduced tells the peer that the sender reacted to an ECN congestion signal.
ECE
ECN-Echo participates in Explicit Congestion Notification negotiation and reporting.
URG
Makes the Urgent Pointer significant. Urgent-data handling is uncommon in modern applications.
ACK
Makes the Acknowledgment Number significant. It is normally set after the initial SYN.
PSH
Requests prompt delivery of received data to the application instead of waiting for more stream data.
RST
Immediately resets a connection or rejects a segment that does not belong to a valid connection.
SYN
Synchronizes initial sequence numbers while establishing a connection.
FIN
Signals that the sender has no more data. It closes one direction of the full-duplex connection.
5. TCP Window Size, Flow Control and Checksum
The Window field provides receiver-driven flow control. It advertises how many bytes, beginning at the current acknowledgment number, the receiver can accept. This receive window is separate from the sender's congestion window, which limits traffic according to network conditions.
Receive window
Prevents a fast sender from overrunning the receiver's buffer. A zero window pauses new data while allowing control traffic and window probes.
Window Scale option
Negotiated only in SYN segments and increases the effective receive window beyond the 16-bit field's 65,535-byte limit.
Checksum coverage
IP pseudo-header + full TCP header and options + TCP data. Odd-length input is zero-padded for calculation only.
Mandatory verification
Unlike UDP over IPv4, the TCP checksum is never optional: senders generate it and receivers check it.
6. TCP Packet Example: Decoding a SYN Segment
This 24-byte TCP header represents an initial SYN from 192.168.12.1 to 192.168.12.2. It contains the 20-byte fixed header plus a four-byte Maximum Segment Size option. The packet carries no application data.
| Field | Raw value | Decoded meaning |
|---|---|---|
| Source Port | A1 C9 | 0xA1C9 = 41,417, an ephemeral client port. |
| Destination Port | 00 17 | 0x0017 = 23, the Telnet service port. |
| Sequence Number | 12 34 56 78 | Initial sequence number 0x12345678. |
| Acknowledgment | 00 00 00 00 | Not active because ACK is clear in the initial SYN. |
| Offset + Flags | 60 02 | Data Offset 6 = 24-byte header; only SYN is set. |
| Window | 10 20 | 0x1020 = 4,128 bytes before scaling. |
| Checksum | E4 25 | Valid for the displayed IPv4 endpoints and TCP segment. |
| Urgent Pointer | 00 00 | Zero because URG is not set. |
| MSS Option | 02 04 05 B4 | Kind 2, length 4, MSS 0x05B4 = 1,460 bytes. |
Wireshark often displays relative sequence number 0 for the first SYN to make traces easier to read. The original 32-bit initial sequence number still exists on the wire.
7. TCP Options: MSS, Window Scale, SACK and Timestamps
Options extend TCP without changing the fixed 20-byte header. Data Offset includes both options and padding, and the complete header must end on a 32-bit boundary.
| Option | Purpose | Where it appears |
|---|---|---|
| Maximum Segment Size (MSS) | Largest TCP data block the sender of the option is prepared to receive | SYN segments only |
| Window Scale | Applies a negotiated shift to the 16-bit Window field | Negotiated in SYN segments |
| SACK Permitted | Allows selective acknowledgments for noncontiguous received data | Negotiated in SYN segments |
| SACK | Reports received byte ranges beyond the cumulative ACK | After SACK is permitted |
| Timestamp | Supports round-trip measurement and protection against old duplicate segments | Negotiated and then used during the connection |
| NOP / End of Option List | Aligns options or marks their logical end | As needed |
8. TCP Three-Way Handshake and Connection Termination
The three-way handshake confirms that both endpoints can communicate and synchronizes both sequence spaces before normal data transfer.
| Step | Direction | Flags | Meaning |
|---|---|---|---|
| 1 | Client to server | SYN | Proposes the client's initial sequence number and options. |
| 2 | Server to client | SYN + ACK | Acknowledges the client and proposes the server's sequence number. |
| 3 | Client to server | ACK | Acknowledges the server; the connection is established. |
An orderly close commonly uses four segments because TCP is full duplex: one side sends FIN, the peer acknowledges it, the peer later sends its own FIN, and the original side acknowledges that FIN. FIN means no more data from that sender; RST instead aborts the connection immediately.
9. TCP vs UDP Header and Service Model
TCP and UDP both use transport-layer ports, but they expose different services. Neither is universally better; the application should choose the behavior it needs.
| Feature | TCP | UDP |
|---|---|---|
| Minimum header | 20 bytes | 8 bytes |
| Communication | Connection-oriented byte stream | Connectionless datagrams |
| Delivery | Reliable and ordered | Best effort |
| Recovery | Acknowledgments and retransmission | Application responsibility |
| Flow control | Receive window | Not built into UDP |
| Congestion control | Built into TCP | Application responsibility |
| Typical uses | HTTPS, SSH, SMTP, file transfer | DNS, DHCP, voice, gaming, QUIC |
Review the companion UDP header guide for its fixed format, checksum rules and worked DNS example.
10. How to Analyze a TCP Header in Wireshark
- Capture traffic or open a packet capture file.
- Use
tcpto show TCP traffic ortcp.port == 443for a service. - Expand Transmission Control Protocol in the packet details pane.
- Compare source and destination ports to identify the connection direction.
- Inspect relative and raw sequence numbers, acknowledgment numbers and segment length.
- Read Header Length and expand Options to identify MSS, SACK, timestamps or scaling.
- Follow the flags through SYN, SYN+ACK and ACK during setup, and FIN or RST during closure.
- Check advertised and calculated window values when diagnosing throughput or stalled transfers.
- Use Follow TCP Stream to reconstruct application bytes while remembering that encryption may hide their content.
TCP Header CCNA and Interview Notes
- Header size: 20 bytes minimum and 60 bytes maximum.
- Data Offset: counts 32-bit words, not bytes.
- Sequence Number: normally identifies the first data byte in the segment.
- Acknowledgment Number: identifies the next byte expected when ACK is set.
- SYN and FIN: each consume one sequence number.
- Window: provides receiver flow control; the congestion window is separate.
- Checksum: is mandatory and covers a pseudo-header, the TCP header, options and data.
- MSS: describes TCP payload size, not complete frame or IP packet size.
Continue with the IPv4 header format, UDP header format, NAT operation and the port checker.
TCP Header Frequently Asked Questions
What is a TCP header?
It is the control section before TCP application data. It carries ports, byte sequencing, acknowledgments, flags, flow-control, checksum and option information.
How large is a TCP header?
The minimum is 20 bytes. Options and padding can extend it to 60 bytes, and Data Offset records its length in 32-bit words.
What do TCP sequence and acknowledgment numbers mean?
The sequence number normally identifies the first data byte in a segment. When ACK is set, the acknowledgment number identifies the next byte expected from the peer.
What are the TCP flags?
The eight current flags are CWR, ECE, URG, ACK, PSH, RST, SYN and FIN. They control congestion signaling, acknowledgments, delivery behavior, reset, setup and closure.
What does the TCP checksum protect?
It covers an IP pseudo-header, the complete TCP header including options, and all TCP data. TCP checksum generation and verification are mandatory.
What is the TCP window size?
It advertises how many bytes beginning at the acknowledgment number the sender of that segment can currently receive. Window scaling can increase the effective value.
How is TCP different from UDP?
TCP provides a connection-oriented, reliable and ordered byte stream with retransmission, flow control and congestion control. UDP sends independent best-effort datagrams with an eight-byte header.
TCP Standards and Additional Resources
- RFC 9293 - Transmission Control Protocol
- RFC 7323 - TCP Extensions for High Performance
- RFC 2018 - TCP Selective Acknowledgment Options
- RFC 5681 - TCP Congestion Control
- IANA Service Name and Port Number Registry
This lesson was independently rewritten and expanded from the supplied TCP header notes. Field definitions, modern reserved-bit layout, checksum calculation, options and connection behavior were checked against the current TCP standard.