Transport and networkLayer 4RFC 9293
TCP: reliable delivery
How two computers agree to talk, keep the data in order and close the line politely.
Ports and use: Used by HTTP (80), HTTPS (443), SSH (22) and more
In one sentenceTCP makes an unreliable network feel reliable by numbering data, confirming it and resending what is lost.
Think of it like thisIt is a phone call: you both say hello first, you repeat what you did not catch, and you say goodbye at the end.
Watch it happen
7 steps and 3 byte-by-byte decodes. Use the buttons or the arrow keys. Hover or focus a field to find its bytes.
- Your laptop
- Web server
- SYN: "Can we talk?"Your laptop to Web server
- SYN-ACK: "Yes, and you?"Web server to Your laptop
- ACK: "Agreed"Your laptop to Web server
- Data: the requestYour laptop to Web server
- ACK: "Got it up to here"Web server to Your laptop
- FIN: "I am finished"Your laptop to Web server
- FIN and ACKWeb server to Your laptop
Step 1 of 7 SYN: "Can we talk?"
Your laptop → Web server
Your laptop picks a random starting number (the sequence number) and sends a segment with only the SYN flag set.
SYN segment 24 bytes
c9 3a 00 50 1a 2b 3c 4d 00 00 00 00 60 02 fa f0 7f 7a 00 00 02 04 05 b4
| Field | Bytes | What it means |
|---|---|---|
| Source port | c9 3a | 51514: the sender's port, which tells replies which program to reach. |
| Destination port | 00 50 | 80: the program the packet is for. 80 is a web server. |
| Sequence number | 1a 2b 3c 4d | 0x1a2b3c4d: a random starting number for the data this side will send. |
| Acknowledgement number | 00 00 00 00 | 0: nothing to acknowledge yet. |
| Header length and flags | 60 02 | Header length 6 words (24 bytes). The only flag set is SYN, which means "start a connection". |
| Window size | fa f0 | 64240: this side can receive 64,240 bytes before it must wait. |
| Checksum | 7f 7a | Lets the receiver detect damage. It also covers the source and destination IP addresses. |
| Urgent pointer | 00 00 | Rarely used. Zero. |
| Option: maximum segment size | 02 04 05 b4 | Kind 2, length 4, value 1460: "send me at most 1460 bytes of data per segment". |
Step 2 of 7 SYN-ACK: "Yes, and you?"
Web server → Your laptop
The server picks its own starting number and confirms yours by acknowledging your number plus one.
SYN-ACK segment 24 bytes
00 50 c9 3a 5e 6f 7a 8b 1a 2b 3c 4e 60 12 ff ff a1 5f 00 00 02 04 05 b4
| Field | Bytes | What it means |
|---|---|---|
| Source port | 00 50 | 80: the sender's port, which tells replies which program to reach. |
| Destination port | c9 3a | 51514: the program the packet is for. 80 is a web server. |
| Sequence number | 5e 6f 7a 8b | 0x5e6f7a8b: the server's own random starting number. |
| Acknowledgement number | 1a 2b 3c 4e | 0x1a2b3c4e: your number plus one, meaning "I got your SYN, send the next byte". |
| Header length and flags | 60 12 | SYN and ACK flags are both set. |
| Window size | ff ff | 65535: the server can receive up to 65,535 bytes at once. |
| Checksum | a1 5f | Lets the receiver detect damage. It also covers the source and destination IP addresses. |
| Urgent pointer | 00 00 | Rarely used. Zero. |
| Option: maximum segment size | 02 04 05 b4 | Kind 2, length 4, value 1460: "send me at most 1460 bytes of data per segment". |
Step 3 of 7 ACK: "Agreed"
Your laptop → Web server
Your laptop confirms the server's number. The connection is open, and data can flow in both directions.
ACK segment 20 bytes
c9 3a 00 50 1a 2b 3c 4e 5e 6f 7a 8c 50 10 fa f0 be 2b 00 00
| Field | Bytes | What it means |
|---|---|---|
| Source port | c9 3a | 51514: the sender's port, which tells replies which program to reach. |
| Destination port | 00 50 | 80: the program the packet is for. 80 is a web server. |
| Sequence number | 1a 2b 3c 4e | 0x1a2b3c4e: the first data byte this side will send. |
| Acknowledgement number | 5e 6f 7a 8c | 0x5e6f7a8c: the server's number plus one. |
| Header length and flags | 50 10 | Header length 5 words (20 bytes). Only the ACK flag is set. |
| Window size | fa f0 | 64240: unchanged. |
| Checksum | be 2b | Lets the receiver detect damage. It also covers the source and destination IP addresses. |
| Urgent pointer | 00 00 | Rarely used. Zero. |
Step 4 of 7 Data: the request
Your laptop → Web server
Your browser sends its HTTP request. Each byte has a number, so the server knows the order and can spot gaps.
Step 5 of 7 ACK: "Got it up to here"
Web server → Your laptop
The server acknowledges how far it has received. If an acknowledgement does not arrive in time, the sender transmits that data again.
Step 6 of 7 FIN: "I am finished"
Your laptop → Web server
When your browser is done, it sends a FIN. This closes your side of the connection.
Step 7 of 7 FIN and ACK
Web server → Your laptop
The server acknowledges and closes its own side. After a short wait, both computers forget the connection.
Where you meet it
- Web pages, email, file downloads and remote logins all use TCP.
- Databases and APIs use it so that no part of a message goes missing.
- Anything where correctness matters more than a tiny delay.
Common mistakes
- Thinking TCP is slow. The handshake costs one round trip, which is small on a fast network but noticeable across continents.
- Blaming the application when the real problem is lost packets causing retransmissions.
- Ignoring ports: two programs on the same computer are told apart only by their port numbers.
- Forgetting that a connection can stay half-open when one side crashes.
Try it yourself
Run these on your own computer and compare the output with the lesson above.
ss -tnLinux: lists your open TCP connections.netstat -anWindows and macOS: the same idea.sudo tcpdump -n -i any "tcp[tcpflags] & tcp-syn != 0" -c 5Shows the next five SYN packets on your machine.
Addresses and values in the examples are made up for teaching (the 203.0.113.x range is reserved for documentation). Real traffic carries more options and details. Check the standard named above for the full rules.