A client with ISN 1,000 connects to a server with ISN 5,000. The client sends 200 bytes; the server replies with 500 bytes; then the client closes, followed by the server. Give the seq and ack numbers of every segment.
The transport layer delivers data between processes using port numbers. TCP adds connections, reliability, ordering, flow and congestion control over unreliable IP; UDP adds almost nothing and is fast. Headers, handshakes, sequence numbers, timers and well-known ports are core exam material.
IP delivers datagrams to a host, but a host runs many programs at once — a browser, a mail client, a DNS resolver. The transport layer extends delivery to the right process. At the sender it multiplexes: gathers data from many sockets and adds a header with port numbers. At the receiver it demultiplexes: reads the destination port and hands the data to the matching socket.
| Range | Name | Used for |
|---|---|---|
| 0 – 1023 | Well-known (system) ports | Standard servers: 22 SSH, 25 SMTP, 53 DNS, 80 HTTP, 443 HTTPS; binding to them needs administrator rights on Unix |
| 1024 – 49151 | Registered (user) ports | Registered applications: 3306 MySQL, 3389 RDP, 5432 PostgreSQL, 8080 alternative HTTP |
| 49152 – 65535 | Dynamic / private (ephemeral) ports | Temporary client ports chosen by the operating system for each connection |
A socket address is the pair (IP address, port number). A TCP connection is identified by the 4-tuple (source IP, source port, destination IP, destination port), which is how one web server listening on port 443 serves thousands of clients simultaneously: each connection differs in the client's address or ephemeral port. Two tabs on the same laptop might be 192.0.2.10:52341 → 203.0.113.80:443 and 192.0.2.10:52342 → 203.0.113.80:443. UDP sockets are demultiplexed by the destination IP and port only.
| Field | Bits | Meaning |
|---|---|---|
| Source port / destination port | 16 + 16 | Identify the sending and receiving processes |
| Sequence number | 32 | Number of the first data byte in this segment (the ISN in a SYN) |
| Acknowledgement number | 32 | Next byte the sender of this segment expects to receive — valid when ACK = 1 |
| Data offset (HLEN) | 4 | Header length in 32-bit words: 5 (20 bytes) to 15 (60 bytes) |
| Reserved + ECN bits | 4 + 2 | Includes CWR and ECE, used by ECN |
| Flags | 6 | URG, ACK, PSH, RST, SYN, FIN |
| Window | 16 | Receive window (rwnd) in bytes, possibly scaled |
| Checksum | 16 | Over a pseudo-header (source and destination IP, protocol 6, TCP length), the header and the data — mandatory |
| Urgent pointer | 16 | Offset of the last urgent byte — valid when URG = 1 |
| Options | 0–320 | MSS, window scale, SACK-permitted and SACK blocks, timestamps, NOP/end padding |
| Flag | Meaning |
|---|---|
| URG | The urgent pointer is valid — data to be handled out of band (e.g. an interrupt key in Telnet) |
| ACK | The acknowledgement number is valid (set on every segment after the initial SYN) |
| PSH | Push: deliver buffered data to the application now |
| RST | Reset: abort the connection, or refuse a SYN sent to a port with no listener |
| SYN | Synchronise sequence numbers — open a connection |
| FIN | The sender has finished sending data |
Why three messages and not two? Each side must choose an initial sequence number and see it acknowledged. The third message also protects against a delayed duplicate SYN from an old connection: the server's SYN+ACK to it would be answered with RST rather than accepted. ISNs are chosen unpredictably (RFC 6528) so that segments from an old incarnation of the same 4-tuple, or an attacker guessing numbers, are not accepted.
In a SYN-flood attack, an attacker sends many SYNs from forged addresses; the server allocates state for each half-open connection and its backlog fills up, locking out real clients. Defences include SYN cookies (encoding the connection state in the server's ISN so nothing is stored until the final ACK), backlog limits and firewall rate-limits. Both sides may also send SYN at the same time (simultaneous open); TCP handles that too.
TCP numbers bytes, not segments. A segment's sequence number is the number of its first data byte; the acknowledgement number is the number of the next byte expected, and it is cumulative — 'everything before this has arrived'. If segments arrive out of order, the receiver buffers them and keeps sending the same ACK (a duplicate ACK) for the gap.
Receivers usually delay ACKs slightly (acknowledging every second full segment, and never waiting more than 500 ms) and piggyback them on data going the other way, reducing traffic.
If the receiver's buffer fills it advertises rwnd = 0 and the sender stops. To avoid deadlock if the later window update is lost, the sender's persistence timer periodically sends a 1-byte window probe. PSH asks the receiver to pass data to the application at once; URG with the urgent pointer marks data the application should handle out of band.
If B has nothing more to send, its ACK and FIN can travel in one segment — a three-way close. An application can also abort with RST, discarding any queued data. TIME-WAIT has two purposes: if A's final ACK is lost, B will resend its FIN and A must still be there to acknowledge it; and waiting twice the maximum segment lifetime (MSL) lets stray old segments die out so they cannot be mistaken for data of a new connection with the same 4-tuple. RFC 793 suggested an MSL of 2 minutes; implementations use 30–120 s.
| State | Meaning |
|---|---|
| CLOSED | No connection |
| LISTEN | Server waiting for a SYN (passive open) |
| SYN-SENT | Client has sent SYN, waiting for SYN+ACK |
| SYN-RECEIVED | Server has received SYN and sent SYN+ACK |
| ESTABLISHED | Data transfer |
| FIN-WAIT-1 | Active closer has sent FIN |
| FIN-WAIT-2 | Active closer's FIN acknowledged; waiting for the peer's FIN |
| CLOSE-WAIT | Passive closer received FIN; waiting for its application to close |
| CLOSING | Both sides sent FIN simultaneously; waiting for the ACK |
| LAST-ACK | Passive closer sent its FIN; waiting for the final ACK |
| TIME-WAIT | Active closer waiting 2 MSL before CLOSED |
The RTO must adapt: too short causes needless retransmissions that add to congestion; too long makes recovery slow. TCP keeps a smoothed RTT and a measure of its variation (Jacobson/Karels, standardized in RFC 6298).
Karn's algorithm: when a segment has been retransmitted, its ACK is ambiguous — it may acknowledge the original or the copy — so its RTT sample is ignored. Instead, on each timeout the RTO is doubled (exponential backoff) and kept until a segment that was not retransmitted is acknowledged. The timestamps option removes the ambiguity altogether.
Timeouts are slow, so TCP also uses fast retransmit: three duplicate ACKs for the same byte mean a segment was lost while later ones arrived, and the missing segment is resent immediately (TCP's congestion control then halves its window). With SACK the receiver lists the blocks it holds, so a sender can repair several holes in one round trip.
UDP (User Datagram Protocol, RFC 768, 1980) adds just two things to IP: port numbers and an optional checksum. It is connectionless (no handshake), unreliable (no ACKs, no retransmission, no ordering), message-oriented (each send is one datagram, boundaries preserved) and has no flow or congestion control. In exchange it is fast, light (8-byte header) and supports broadcast and multicast.
| Field | Bits | Notes |
|---|---|---|
| Source port | 16 | Optional — 0 if no reply is expected |
| Destination port | 16 | Identifies the receiving process |
| Length | 16 | Header + data in bytes; minimum 8 |
| Checksum | 16 | Over a pseudo-header (IPs, protocol 17, UDP length), header and data; optional in IPv4 (0 = not computed), mandatory in IPv6 |
| Feature | TCP | UDP | SCTP |
|---|---|---|---|
| Connection | Yes — 3-way handshake | No | Yes — 4-way handshake with a state cookie |
| Reliability | Reliable (ACK + retransmission) | None | Reliable |
| Ordering | Strict byte order | None | Per stream (unordered delivery optional) |
| Data unit | Byte stream (no boundaries) | Message (datagram) | Message (chunks) |
| Header | 20–60 bytes | 8 bytes | 12-byte common header + chunks |
| Flow / congestion control | Yes / yes | No / no | Yes / yes |
| Multistreaming / multihoming | No / no | No / no | Yes / yes |
| Broadcast / multicast | No | Yes | No |
| Typical uses | Web, e-mail, file transfer, SSH, databases | DNS, DHCP, TFTP, SNMP, VoIP, streaming, games | Telephony signalling (SIGTRAN), mobile-core signalling, WebRTC data channels |
SCTP (Stream Control Transmission Protocol, IP protocol 132, RFC 9260) is a third transport-layer protocol. It is message-oriented like UDP but reliable and congestion-controlled like TCP. Multistreaming carries several independent streams in one association, so a loss in one stream does not block the others; multihoming lets an endpoint use several IP addresses and fail over between them. Its four-way setup (INIT, INIT-ACK with a cookie, COOKIE-ECHO, COOKIE-ACK) resists SYN-flood-style attacks.
| Port | Service | Transport |
|---|---|---|
| 20 / 21 | FTP data / control | TCP |
| 22 | SSH (also SCP, SFTP) | TCP |
| 23 | Telnet | TCP |
| 25 | SMTP (server-to-server relay) | TCP |
| 53 | DNS | UDP (TCP for zone transfers and large replies) |
| 67 / 68 | DHCP server / client | UDP |
| 69 | TFTP | UDP |
| 80 | HTTP | TCP |
| 110 | POP3 | TCP |
| 123 | NTP | UDP |
| 143 | IMAP | TCP |
| 161 / 162 | SNMP agent / trap | UDP |
| 179 | BGP | TCP |
| 443 | HTTPS (HTTP/3 uses UDP 443) | TCP |
| 465 / 587 | SMTP submission: implicit TLS / STARTTLS | TCP |
| 993 / 995 | IMAPS / POP3S | TCP |
| 3306 | MySQL | TCP |
| 3389 | Remote Desktop (RDP) | TCP |
Try the problem first, then reveal the working one step at a time.
A client with ISN 1,000 connects to a server with ISN 5,000. The client sends 200 bytes; the server replies with 500 bytes; then the client closes, followed by the server. Give the seq and ack numbers of every segment.
A sender's ISN is 4,000 and it sends a 6,000-byte file in four 1,500-byte segments. Give each segment's sequence number and the ACKs if nothing is lost. Then suppose segment 2 is lost.
A TCP connection has SRTT = 100 ms and RTTVAR = 10 ms. A new RTT sample of 140 ms arrives. Compute the new RTTVAR, SRTT and RTO (RFC 6298). Then a segment times out and is retransmitted; what happens to the RTO and to the RTT sample of that segment?
(a) A UDP header reads D5A4 0035 0030 9F2E (hex). (b) The first 20 bytes of a TCP segment read 04D2 0050 00002710 00000000 6002 7210 A1B2 0000. Decode both.
On a 1 Gbps link with a maximum segment lifetime of 60 s, how many bits would a sequence-number field need so that numbers do not wrap around within one MSL? How long does TCP's 32-bit space last at 10 Gbps?
Without window scaling, what is the maximum throughput of a TCP connection with RTT = 50 ms? What window-scale shift is needed to fill a 1 Gbps path with the same RTT?
A client sends two segments: seq 2,001 with 500 bytes, then seq 2,501 with 700 bytes. What ACK does the server send after both arrive? What does it send if the first segment is lost but the second arrives? What after the first is retransmitted?
What is the largest UDP payload that fits in one IPv4 datagram with a 20-byte header? What is the smallest legal value of the UDP length field, and what does it mean?
A receiver has a 32,768-byte buffer. Its application has read up to byte 10,000 and bytes up to 26,000 have arrived. What window does it advertise? If the application stops reading, how many more bytes can arrive before rwnd = 0?
12 questions. 70 % passes the topic quiz (+30 XP, +20 more for 100 %). Exam scoring: +1 correct, −⅓ wrong.
Modelled on real KPSC questions (reworded) with the same concept and answer; each links to its original paper.