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.

TCP Header Transport Layer TCP Flags Wireshark CCNA

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.

Minimum header20 bytes
Maximum header60 bytes
IP protocol number6
Service modelReliable, ordered byte stream
TCP header format diagram showing ports, sequence and acknowledgment numbers, flags, window, checksum, options and payload
The TCP segment header contains a 20-byte fixed portion and up to 40 bytes of options and padding.

TCP Header Lesson Contents

  1. TCP header format and segment structure
  2. TCP header fields explained
  3. Ports, sequence and acknowledgment numbers
  4. TCP flags explained
  5. Window size and checksum
  6. Worked SYN packet example
  7. TCP options
  8. Connection setup and termination
  9. TCP vs UDP header
  10. Wireshark analysis
  11. Frequently asked questions

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.

Ethernet frame IPv4 header TCP header TCP data
TCP is a byte stream: application write boundaries are not preserved. A receiver may read data in different-sized blocks from those originally supplied by the sender.

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.

Field 1

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.

Field 2

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.

Field 3

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.

Field 4

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.

Field 5

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.

Field 6

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.

Field 7

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.

Field 8

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.

Field 9

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.

Field 10

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.

Field 11

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.

TCP header length in bytes = Data Offset x 4
Not a header field: the TCP payload is the variable-length application byte stream that follows the header. SYN and pure acknowledgment segments can contain no payload.

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.

ApplicationCommon TCP portPurpose
FTP control21File-transfer commands
SSH22Secure remote access
Telnet23Unencrypted remote terminal
SMTP25Mail transfer
HTTP80Web traffic
HTTPS443HTTP protected by TLS
Example: Seq 1000 + 500 data bytes = next expected ACK 1500

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.

Common combinations: SYN | SYN+ACK | ACK | PSH+ACK | FIN+ACK | RST
Flags are context-dependent: an isolated flag value does not prove an attack or fault. Interpret it with connection state, sequence numbers and surrounding packets.

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.

Usable send limit = the smaller of receive window and congestion window
Checksum offload: Wireshark may label an outbound checksum unverified or incorrect when the capture occurs before the network adapter inserts the final value. Checksum status must be interpreted with the capture location.

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.

TCP SYN packet example showing 24 header bytes, decoded ports, sequence number, flags, checksum and MSS option
A complete 24-byte TCP SYN header decoded into fields, with IPv4 endpoint context shown separately.
A1 C9 00 17 12 34 56 78 00 00 00 00 60 02 10 20 E4 25 00 00 02 04 05 B4
FieldRaw valueDecoded meaning
Source PortA1 C90xA1C9 = 41,417, an ephemeral client port.
Destination Port00 170x0017 = 23, the Telnet service port.
Sequence Number12 34 56 78Initial sequence number 0x12345678.
Acknowledgment00 00 00 00Not active because ACK is clear in the initial SYN.
Offset + Flags60 02Data Offset 6 = 24-byte header; only SYN is set.
Window10 200x1020 = 4,128 bytes before scaling.
ChecksumE4 25Valid for the displayed IPv4 endpoints and TCP segment.
Urgent Pointer00 00Zero because URG is not set.
MSS Option02 04 05 B4Kind 2, length 4, MSS 0x05B4 = 1,460 bytes.
Data Offset 6 x 4 = 24-byte TCP header | Segment payload = 0 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.

OptionPurposeWhere it appears
Maximum Segment Size (MSS)Largest TCP data block the sender of the option is prepared to receiveSYN segments only
Window ScaleApplies a negotiated shift to the 16-bit Window fieldNegotiated in SYN segments
SACK PermittedAllows selective acknowledgments for noncontiguous received dataNegotiated in SYN segments
SACKReports received byte ranges beyond the cumulative ACKAfter SACK is permitted
TimestampSupports round-trip measurement and protection against old duplicate segmentsNegotiated and then used during the connection
NOP / End of Option ListAligns options or marks their logical endAs needed
MSS is not MTU: MSS describes TCP payload capacity. For basic IPv4 over a 1,500-byte Ethernet MTU, a common MSS is 1,460 bytes after 20-byte IPv4 and 20-byte TCP headers.

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.

StepDirectionFlagsMeaning
1Client to serverSYNProposes the client's initial sequence number and options.
2Server to clientSYN + ACKAcknowledges the client and proposes the server's sequence number.
3Client to serverACKAcknowledges 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.

Open: SYN -> SYN+ACK -> ACK | Close: FIN+ACK -> ACK -> FIN+ACK -> ACK

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.

FeatureTCPUDP
Minimum header20 bytes8 bytes
CommunicationConnection-oriented byte streamConnectionless datagrams
DeliveryReliable and orderedBest effort
RecoveryAcknowledgments and retransmissionApplication responsibility
Flow controlReceive windowNot built into UDP
Congestion controlBuilt into TCPApplication responsibility
Typical usesHTTPS, SSH, SMTP, file transferDNS, 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

  1. Capture traffic or open a packet capture file.
  2. Use tcp to show TCP traffic or tcp.port == 443 for a service.
  3. Expand Transmission Control Protocol in the packet details pane.
  4. Compare source and destination ports to identify the connection direction.
  5. Inspect relative and raw sequence numbers, acknowledgment numbers and segment length.
  6. Read Header Length and expand Options to identify MSS, SACK, timestamps or scaling.
  7. Follow the flags through SYN, SYN+ACK and ACK during setup, and FIN or RST during closure.
  8. Check advertised and calculated window values when diagnosing throughput or stalled transfers.
  9. Use Follow TCP Stream to reconstruct application bytes while remembering that encryption may hide their content.
Useful filters: tcp | tcp.port == 443 | tcp.flags.syn == 1 | tcp.flags.reset == 1 | tcp.analysis.retransmission

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

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.