TCP's Service Model and Header: Segments, Sequence Numbers and Flags
What TCP promises applications (a connection-oriented, reliable, full-duplex byte stream), how it achieves reliability, and every field of the TCP header, decoded from a real SYN captured in the lab: ports, sequence and acknowledgment numbers, offset, flags, window, checksum and options.
kvi5hnuCode Sprout team member14 min readOn this page
Article 57 built a reliable transport from parts: acknowledgments, sequence numbers, timers and windows. TCP is the Internet's version of that design, and it's the transport under HTTP/1.1 and HTTP/2 (HTTP/3 uses QUIC over UDP instead, article 86), SSH (secure remote login), SMTP (email delivery between servers), database protocols and most other traffic that needs every byte. TCP is specified in RFC 9293 (2022), which replaced the original 1981 specification, RFC 793, and folded in four decades of corrections. Many extensions live in other RFCs that this part of the course points to as they come up.
This article covers what TCP offers an application, how it delivers on that offer, and the header that carries it all, field by field, using a real segment from the course lab.
The service TCP provides
TCP gives an application a connection-oriented, reliable, full-duplex byte stream. Each of those words is a promise.
- Connection-oriented. The two programs must set up a connection before exchanging data (article 59). A connection has exactly two endpoints. There's no TCP broadcast or multicast.
- Reliable. Every byte arrives, in order, with no duplicates. If TCP can't deliver, the application gets an error instead of silently missing data.
- Full-duplex. Data flows in both directions at once, and each direction has its own sequence numbers, window and acknowledgments.
- Byte stream. TCP doesn't preserve message boundaries. If one side writes 10 bytes, then 20, then 50, the other side might read 80 bytes at once, or 40 + 40, or any other split. Article 1 showed this in a real run. TCP also doesn't interpret the bytes: text, images and encrypted TLS records all look the same to it.
A connection is identified by four numbers, the 4-tuple: source IP address, source port, destination IP address and destination port. Two connections from the same browser to the same server differ in the client's port.
How TCP makes it reliable
TCP applies the ARQ ideas from article 57, with some TCP-specific twists:
- Segments. TCP cuts the application's stream into chunks called segments, each sized to fit into one IP datagram without fragmentation. A UDP application chooses its own datagram sizes; a TCP application doesn't control segment sizes at all.
- Byte sequence numbers. Each segment carries the sequence number of its first data byte. Because numbering is by byte, a retransmission can carry a different amount of data than the original, which is called repacketization.
- Cumulative acknowledgments. An ACK carries the number of the next byte the receiver expects. "ACK 1001" means "I have every byte up to 1000". A single ACK can acknowledge many segments, and a lost ACK is covered by the next one.
- Retransmission. The sender keeps a copy of unacknowledged data and resends it on a timeout (articles 64 and 65), or earlier when duplicate ACKs or SACK show a gap (article 66).
- Reordering and duplicates. The receiver puts out-of-order segments into order using their sequence numbers, and drops duplicates.
- A checksum. Every segment carries a mandatory checksum covering the header, the data and parts of the IP header. A segment with a bad checksum is dropped without an ACK, and the sender eventually resends it. The checksum is weak by modern standards, which is one reason applications that care about integrity use TLS or their own stronger checks.
- Flow control. Each side advertises how much more data it can buffer (article 69).
A real connection in the lab
The lab ran a tiny HTTP server on server (198.51.100.10, port 8080), fetched one page from client (192.0.2.10) with curl, and captured the whole connection on the client. There was 5 ms of delay in each direction, so the RTT was about 10 ms. Here is every segment, as tshark shows it (timestamp options removed to keep the lines short):
1 0.000000 192.0.2.10 → 198.51.100.10 TCP 74 57584 → 8080 [SYN, ECE, CWR] Seq=0 Win=64240 Len=0 MSS=1460 SACK_PERM WS=128
2 0.021687 198.51.100.10 → 192.0.2.10 TCP 74 8080 → 57584 [SYN, ACK, ECE] Seq=0 Ack=1 Win=65160 Len=0 MSS=1460 SACK_PERM WS=128
3 0.021727 192.0.2.10 → 198.51.100.10 TCP 66 57584 → 8080 [ACK] Seq=1 Ack=1 Win=64256 Len=0
4 0.021806 192.0.2.10 → 198.51.100.10 HTTP 148 GET / HTTP/1.1
5 0.035925 198.51.100.10 → 192.0.2.10 TCP 66 8080 → 57584 [ACK] Seq=1 Ack=83 Win=65152 Len=0
6 0.037164 198.51.100.10 → 192.0.2.10 HTTP 110 HTTP/1.1 200 OK
7 0.037175 192.0.2.10 → 198.51.100.10 TCP 66 57584 → 8080 [ACK] Seq=83 Ack=45 Win=64256 Len=0
8 0.037176 198.51.100.10 → 192.0.2.10 TCP 66 8080 → 57584 [FIN, ACK] Seq=45 Ack=83 Win=65152 Len=0
9 0.037258 192.0.2.10 → 198.51.100.10 TCP 66 57584 → 8080 [FIN, ACK] Seq=83 Ack=46 Win=64256 Len=0
10 0.050143 198.51.100.10 → 192.0.2.10 TCP 66 8080 → 57584 [ACK] Seq=46 Ack=84 Win=65152 Len=0
Each line shows the frame number, the time in seconds since the first frame, the source and destination addresses, the protocol, the frame length in bytes, the ports, the flags in brackets, then Seq, Ack, Win (window) and Len (bytes of data). MSS, SACK_PERM and WS in the SYNs are options, explained at the end of this article. The whole life of a TCP connection is here:
- Segments 1 to 3 are the three-way handshake (article 59).
- Segment 4 carries 82 bytes of HTTP request.
- Segment 5 acknowledges them:
Ack=83means the server has bytes 1 to 82 and expects byte 83 next. - Segment 6 carries the 44-byte response.
- Segments 8 to 10 close the connection.
The numbers above are relative sequence numbers: tshark subtracts each direction's starting number, so the first SYN shows Seq=0. On the wire, the numbers are large and random. Here are the raw values (frame, source port, raw sequence number, raw acknowledgment number, data length):
1 57584 3514699859 0 0
2 8080 675702879 3514699860 0
3 57584 3514699860 675702880 0
4 57584 3514699860 675702880 82
5 8080 675702880 3514699942 0
6 8080 675702880 3514699942 44
7 57584 3514699942 675702924 0
The client's first sequence number was 3514699859 and the server's was 675702879. Each side picks its own random initial sequence number (ISN), and article 59 explains why.
The TCP header
TCP is carried directly inside IP: the IPv4 Protocol field, or the IPv6 Next Header field, is 6. The TCP header that follows is 20 bytes long without options and up to 60 bytes with them.
The diagram shows the header's layout, 32 bits per row; the sections after it decode each field from a real segment.

Here is the first segment of the lab connection, the client's SYN, as raw bytes. The decoding was done by a short script reading those bytes:
e0 f0 1f 90 d1 7e 10 53 00 00 00 00 a0 c2 fa f0 ec 76 00 00 02 04 05 b4 04 02 08 0a c8 e9 81 49 00 00 00 00 01 03 03 07
bytes 0-1 e0 f0 Source Port 57584
bytes 2-3 1f 90 Destination Port 8080
bytes 4-7 d1 7e 10 53 Sequence Number 3514699859
bytes 8-11 00 00 00 00 Acknowledgment Number 0
bytes 12 a0 Data Offset (high 4 bits) 10 words = 40 bytes
bytes 12-13 a0 c2 Flags (low 9 bits) SYN ECE CWR
bytes 14-15 fa f0 Window 64240
bytes 16-17 ec 76 Checksum 0xec76
bytes 18-19 00 00 Urgent Pointer 0
bytes 20-39 ... Options (20 bytes) MSS, SACK-permitted, Timestamps, NOP, Window Scale
The diagram below lays the same 40 bytes out in 4-byte rows, colored by field.

Ports
Source Port and Destination Port are 16 bits each. Bytes e0 f0 are 57584, the client's ephemeral port, and 1f 90 is 8080, the server's listening port. Together with the IP addresses, the ports identify the connection and tell the receiving host which socket gets the segment. Article 4 covers port ranges, and article 63 covers how servers bind and accept.
Sequence Number
32 bits. In a segment carrying data, it's the stream position of the first data byte. In a SYN, it's the ISN. The SYN itself consumes one sequence number, and so does a FIN, which is why the first data byte in segment 4 is relative byte 1, not 0. Sequence numbers wrap around after 2³² bytes (4 GiB), and comparisons use wraparound arithmetic: a number just past the wrap, such as 5, counts as later than one just before it, such as 4,294,967,290.
Acknowledgment Number
32 bits: the next sequence number the sender of this segment expects to receive. It's meaningful only when the ACK flag is set. In the SYN it's zero, because the client hasn't heard anything yet. Every segment after the first SYN has ACK set.
Data Offset
4 bits: the header length in 32-bit words. Here the byte is a0, so the offset is a = 10 words = 40 bytes: 20 bytes of fixed header plus 20 bytes of options. The maximum, 15 words, means at most 40 bytes of options. The data starts right after the header.
Flags
After three reserved bits come nine 1-bit flags. The first, AE, is the lowest bit of byte 12: a0 = 1010 0000 ends in 0, so AE is off. The other eight fill byte 13, in the order CWR, ECE, URG, ACK, PSH, RST, SYN, FIN, worth 128, 64, 32, 16, 8, 4, 2 and 1. Byte c2 = binary 1100 0010 = 128 + 64 + 2, which sets CWR, ECE and SYN. Three of the flags belong to ECN (Explicit Congestion Notification, article 25), where routers mark packets instead of dropping them.
| Flag | Meaning |
|---|---|
| AE | Accurate ECN. Formerly the experimental "nonce sum" bit (now historic). RFC 9768 (April 2026) uses it with CWR and ECE for more detailed congestion feedback. Linux supports it since 6.18 (net.ipv4.tcp_ecn = 3). |
| CWR | Congestion Window Reduced: "I've reacted to your ECN echo". |
| ECE | ECN-Echo: "a router marked a packet of yours with congestion". In a SYN, CWR and ECE together ask to use ECN, which this client did because the lab enabled it. |
| URG | The Urgent Pointer is valid. Rarely used (article 70). |
| ACK | The Acknowledgment Number is valid. Set on every segment except the first SYN, and except a reset sent in reply to a segment that itself had ACK set (article 62). |
| PSH | Push: deliver this data to the application without waiting for more. Senders set it at the end of a write, and receivers mostly ignore it. |
| RST | Reset: abort the connection immediately (article 62). |
| SYN | Synchronize sequence numbers: used only to open a connection. |
| FIN | Finished: this side won't send any more data. |
The server's reply in the capture had [SYN, ACK, ECE]: ACK because it's acknowledging the client's SYN, and ECE without CWR, which is how a server agrees to use classic ECN. Article 25 covers ECN in detail.
Window
16 bits: how many bytes, starting at the Acknowledgment Number, the sender of this segment is prepared to receive. In a SYN the value is taken literally: fa f0 = 64240 bytes. After the handshake, if both sides sent the window scale option, the value is shifted left by the agreed scale. That's why the HTTP request segment in this capture showed Window: 502. With a scale of 7, it means 502 × 128 = 64,256 bytes. Without scaling, 65,535 bytes would be the largest window possible, far too small for fast, long paths (article 70).
Checksum
16 bits, computed over the TCP header, the data and a pseudo-header built from the IP source and destination addresses, the protocol number and the TCP length. Including the IP addresses means a segment delivered to the wrong host fails the check. Article 24 shows how the Internet checksum is computed, and article 45 shows the pseudo-header.
Urgent Pointer
16 bits, meaningful only with URG set: an offset from the sequence number that marks the end of "urgent" data. It's a leftover from Telnet's interrupt keys. RFC 9293 says new applications shouldn't use it. Article 70 shows it working anyway.
Options
Options take the rest of the header. Each has a 1-byte kind, and all but two of them also have a 1-byte length. The SYN above carried the typical modern set:
- MSS (kind 2), Maximum Segment Size:
02 04 05 b4, the largest segment the client wants to receive:05b4= 5 × 256 + 180 = 1460 bytes. - SACK permitted (kind 4): the client can handle selective acknowledgments.
- Timestamps (kind 8): 10 bytes holding two 32-bit timestamps, used for RTT measurement and protection against wrapped sequence numbers.
- NOP (kind 1): a single padding byte that keeps the next option aligned.
- Window scale (kind 3): shift count 7, so this client's windows are multiplied by 128.
Article 60 covers each option, plus a few you'll see less often: User Timeout, TCP-AO and TCP Fast Open.
Common questions
Is a TCP segment the same as an IP packet?
A segment is TCP's unit: TCP header plus data. It travels as the payload of one IP datagram. TCP picks segment sizes so that each fits in one datagram, so in practice there's one segment per packet, but they're different layers.
What does the PSH flag actually do?
Very little today. A sender sets it on the last segment of a write, meaning "there's no more data queued right now". Most receivers deliver data to the application as soon as it's in order anyway, so PSH rarely changes behavior. Applications can't set or read it through the sockets API.
Why does a SYN consume a sequence number if it has no data?
So that it can be acknowledged and retransmitted like data. The ACK of a SYN is the ISN plus 1, which proves the other side saw this particular SYN. FIN works the same way.
Why is there no length field in the TCP header?
IP already carries the total length of the datagram, and TCP knows its own header length from the Data Offset field. The data length is the IP payload length minus the TCP header length.
Can I change the MSS or window from my application?
Partly. The socket options TCP_MAXSEG and SO_RCVBUF influence the MSS and the receive buffer, which affects the advertised window. In most cases you should leave both alone: the kernel tunes the receive window automatically (article 70).
What are relative sequence numbers in Wireshark?
A display convenience: Wireshark subtracts each direction's ISN so the numbers start at 0. The real values on the wire are the large random ones. You can turn the setting off under TCP protocol preferences.
Does TCP care what's in the data?
No. TCP carries bytes. Whether they're HTTP text, a TLS record or a database protocol is up to the applications.
Summary
- TCP provides a connection-oriented, reliable, full-duplex byte stream between exactly two endpoints. It's defined in RFC 9293.
- Reliability comes from segments numbered by byte, cumulative ACKs, retransmission, reordering, a mandatory checksum and flow control.
- The header is 20 bytes plus up to 40 bytes of options: ports, sequence number, acknowledgment number, data offset, flags, window, checksum, urgent pointer and options.
- SYN and FIN each consume one sequence number. ACK is set on every segment after the first SYN.
- The window field is scaled after the handshake when window scaling is negotiated: 502 meant 64,256 bytes in the lab capture.
- Captures taken on a sending host often show unfinished checksums because of checksum offload.
Practice questions
1. A segment has Sequence Number 5000 and carries 1200 bytes. What Acknowledgment Number will the receiver send if this segment fills the last gap?
Answer
6200: the next byte it expects, 5000 + 1200.
2. A TCP header's byte 12 is 80. How long is the header, and how many bytes of options does it carry?
Answer
The high 4 bits are 8, so the header is 8 × 4 = 32 bytes, with 12 bytes of options.
3. The flags byte of a segment is 18. Which flags are set?
Answer
18 is binary 0001 1000: bit values 16 (ACK) and 8 (PSH). It's an ordinary data segment with ACK and PSH.
4. After a handshake in which both sides sent window scale 7, a segment shows Window 1024. How many bytes is the receiver offering?
Answer
1024 × 2⁷ = 1024 × 128 = 131,072 bytes.
5. A client opens two connections to the same server's port 443 at the same time. How does the server tell the connections apart?
Answer
By the 4-tuple. The client's IP address and the server's address and port are the same, but the client uses a different source port for each connection.
6. Why does the TCP checksum cover a pseudo-header containing IP addresses?
Answer
So that a segment delivered to the wrong host, or with corrupted addresses, fails the check. The TCP header itself doesn't contain the addresses, so without the pseudo-header that kind of error would go undetected.
Previous: How Reliable Transport Works: ARQ, Sliding Windows, Flow Control and Timeouts
Next: Opening and Closing TCP Connections: The Three-Way Handshake, FIN and Half-Close

More in TCP/IP Course
Quiz: TCP/IP Delicate Details
Twenty-five questions on the details that catch out experienced engineers: sequence numbers for SYN and FIN, TIME_WAIT versus tcp_fin_timeout, Karn's algorithm, socket buffer doubling, even and odd ephemeral ports, IPv6 checksums and fragmentation, negative DNS caching, and capture filter traps.
Quiz: TCP/IP Interview Questions
Thirty-three networking questions of the kind asked in developer, SRE and network engineering interviews: what happens when you load a URL, TCP versus UDP, handshakes, closing and TIME_WAIT, subnetting, NAT, DNS, MTU problems, congestion, TLS and QUIC, and debugging slow or failing connections.
Quiz: TCP/IP Course Final Exam (All Parts)
The final exam for the TCP/IP course: thirty questions across all fourteen parts, from packets and addressing through Ethernet, ARP, IP, DHCP, NAT, ICMP, UDP, DNS, TCP connections, reliability, congestion control, security, QUIC and troubleshooting.
Quiz: Modern Transports and Troubleshooting (TCP/IP Part 14)
Review modern transports and troubleshooting: QUIC packets, handshakes, 0-RTT, streams and connection migration, HTTP/3, Multipath TCP, SCTP multihoming, and a layered method for diagnosing real network faults.
Discussion
Sign in to ask a question or share what you learned.