IP brings a packet to the right device, ports to the right program. A web server waits on port 80, SSH on 22, SMTP on 25. The client chooses a free port from 49152. A connection is uniquely identified by source, destination and both ports.
Three-way handshake
Step
Flags
Meaning
1
SYN
client: “I want to connect, my initial number is x”
2
SYN, ACK
server: “Agreed, mine is y, I expect x+1”
3
ACK
client: “I expect y+1” – the connection is up
The TCP header
Without options 20 bytes. The first segment (SYN) usually carries the MSS option, then the header is 24 bytes long. Values from the HTTP request of the demo “DNS, TCP and HTTP”.
TCPSegment · RFC 9293
0481216202428
Source port16 bits49152
Destination port16 bits80
Sequence number32 bits11001
Acknowledgment number32 bits51001
Data offset4 bits5
Reserved4 bits0
Flags8 bitsACK, PSH
Window16 bits64240
Checksum16 bits0xeed9
Urgent pointer16 bits0
Options0–40 bytes
Datavariable100 Byte
Each row has 32 bits (4 bytes), bit 0 on the left, as the RFCs draw their headers. Dashed: variable or optional. Point at a field for an explanation.
Field
Length
Example value
Meaning
Source port
16 bits (2 bytes)
49152
Port of the sending program, usually random from 49152 on the client.
Destination port
16 bits (2 bytes)
80
Port of the service: 80 HTTP, 443 HTTPS, 22 SSH, 25 SMTP.
Sequence number
32 bits (4 bytes)
11001
Number of the first data byte in this segment; with SYN the random initial number.
Acknowledgment number
32 bits (4 bytes)
51001
The next byte expected (valid when ACK is set).
Data offset
4 bits
5
Header length in 32-bit words: 5 = 20 bytes without options.
Reserved
4 bits
0
Reserved, always 0.
Flags
8 bits
ACK, PSH
SYN open, ACK acknowledgement valid, FIN close, RST abort, PSH push immediately, URG, ECE and CWR for congestion.
Window
16 bits (2 bytes)
64240
How many bytes the other side may still send without acknowledgement (flow control).
Checksum
16 bits (2 bytes)
0xeed9
Checksum over header, data and a pseudo header with the IP addresses.
Urgent pointer
16 bits (2 bytes)
0
Only with URG: end of urgent data; hardly used today.
Options (optional)
0–40 bytes
E.g. MSS (maximum segment size), window scale, SACK, timestamps; mostly in the SYN.
Data
variable
100 Byte
The application data, e.g. the HTTP request.
Values: Real frame from the demo “DNS, TCP and HTTP” (no. 36, 158 bytes), exactly as the packet list in leyoNET shows it.
Reliability
Every byte has a sequence number. The receiver acknowledges with the ACK number which byte it expects next. If the acknowledgement is missing, the sender retransmits. Large data is split into segments (MSS 1460 bytes on Ethernet). Teardown starts with a FIN, each side acknowledges; an RST aborts immediately, e.g. if nobody is waiting on the port.
Window and flow control
The TCP header contains the window: how many bytes the receiver can still take without every segment having to be acknowledged individually. The sender may have at most that much unacknowledged data on the way (RFC 9293, Section 3.8.6). If the receiver is overloaded, it reports a smaller window, down to 0: the sender waits. That is how TCP adapts to slow receivers (flow control). Against an overloaded network on the way, congestion control helps as well: if segments get lost, TCP sends more slowly.
In leyoNET
Open a web page in a PC’s browser, then filter the packet list with tcp. Clicking a packet and “Follow TCP stream” shows all segments of the connection. netstat on the command line lists open connections.
See an example
Slow motion This is how it looks in the simulation: every dot is a frame on the cable.DNS, TCP and HTTP
A notebook fetches a web page through a router.
DNS query for www.schule.example, TCP handshake (SYN, SYN-ACK, ACK) and the HTTP request in the browser.
“Watch live” opens the network in leyoNET, the simulation runs in a loop. In the app you find it under File → Demo networks, with a step-by-step tour.
Practise
★★★★☆Protocol analysis – Task 3: ARP, DNS and HTTP· 7 goals · Worksheet (German)
★★★☆☆Open a web page via DNS· 3 goals · Worksheet (German)
In leyoNET under Tools → Exercise catalogue. Every exercise checks itself.
What leyoNET simplifies
Protocol
Layer
Simplification in the simulation
TCP
4
Three-way handshake, sequence numbers in bytes, MSS 1460, retransmission after 1 s (at most three times), FIN/RST; fixed window size, no congestion control
UDPThe fast, connectionless transport for DNS, DHCP and RIP: no handshake, no acknowledgement, just ports and a checksum.
HTTPHow the browser fetches a web page: URL, DNS, TCP connection, GET request, status code and response – byte by byte.
OSI model and encapsulationSeven layers that describe every network connection, and why a packet is built like a Russian doll.
Structure of frames and packetsHow Ethernet frames, IPv4 and IPv6 packets, TCP segments and UDP datagrams nest inside each other, field by field according to the standards, with real bytes from leyoNET.