Dissect how data is packaged and delivered across networks — TCP headers, flags, the famous 3-way handshake, and how UDP trades reliability for speed.
When you send data over a network — whether it's a webpage, an email, or a video call — the data doesn't travel as one giant block. Instead, it gets broken down into small, manageable chunks called packets. Each packet contains a piece of the data plus header information (source address, destination address, sequence number, etc.) that tells the network how to deliver and reassemble it.
Think of it like sending a book through the mail. Rather than shipping the entire book in one box, you tear out each chapter, put it in a separate envelope with a number on it, and mail them all independently. The recipient collects all the envelopes and reassembles the book using the chapter numbers. That's essentially what packet switching does.
The two primary Transport Layer protocols responsible for packaging and delivering data are TCP and UDP. Understanding when and why each is used is fundamental to networking and cybersecurity.
TCP is the workhorse of the internet. It's a connection-oriented protocol, meaning that before any data is exchanged, TCP first establishes a dedicated connection between the sender and receiver through a process called the 3-way handshake. This ensures both sides are ready to communicate.
UDP is TCP's lean, fast sibling. It's connectionless — there is no handshake, no connection setup, no acknowledgments. The sender simply packages data into a datagram and sends it. Whether it arrives or not is not UDP's concern. This "fire and forget" approach makes it incredibly fast.
| Feature | TCP | UDP |
|---|---|---|
| Connection | Connection-oriented (handshake) | Connectionless (no setup) |
| Reliability | Guaranteed delivery (ACKs) | Best-effort, no guarantees |
| Ordering | Sequence numbers ensure order | No ordering |
| Speed | Slower (overhead) | Faster (minimal overhead) |
| Header Size | 20–60 bytes | 8 bytes |
| Flow Control | Yes (sliding window) | No |
| Error Handling | Checksum + retransmission | Checksum only (optional) |
| Use Cases | Web, email, file transfer | DNS, VoIP, gaming, streaming |
Before TCP can send any data, both sides must agree to communicate. This process — the 3-way handshake — establishes a connection and synchronizes sequence numbers. It happens every time you open a website, send an email, or SSH into a server.
The client sends a SYN (Synchronize) segment with its Initial Sequence Number (ISN). This is like saying: "Hey server, I want to talk. My starting sequence number is X."
The server acknowledges the client's SYN (ACK = X+1) and sends its own SYN with its own ISN. "Got your number. Here's mine — my starting sequence is Y."
The client acknowledges the server's SYN (ACK = Y+1). The connection is now ESTABLISHED and data transfer begins. The whole process typically takes <1ms on a LAN.
Closing a TCP connection is a 4-step process because the connection is full-duplex — each direction must be closed independently. Either side can initiate the close.
The initiator sends a FIN segment: "I'm done sending data."
The other side acknowledges: "Got it, I'll finish my remaining data."
The other side sends its own FIN: "I'm also done now."
Final acknowledgment. Connection fully closed. Both sides free their resources.
Note: If a connection needs to be terminated abruptly (crash, error), a RST (Reset) flag is sent instead — this immediately destroys the connection with no negotiation.
www.example.com to an IP
address via DNS (using UDP port 53).All of this happens in under a second — TCP handles the reliability, ordering, and flow control transparently.
Every TCP segment begins with a header that contains all the metadata needed for reliable delivery. Understanding this header is essential for packet analysis with tools like Wireshark. Let's break down each field:
TCP flags are single-bit fields in the header that control the state of the connection. In Wireshark, you'll see these in every TCP packet. Knowing what each flag means is critical for understanding network traffic and detecting anomalies.
TCP's sliding window is one of its most elegant features. It controls how much data can be "in flight" (sent but not yet acknowledged) at any time, balancing speed and reliability.
UDP's header is deliberately simple — just 4 fields, 8 bytes total. Compare this to TCP's minimum 20-byte header. The simplicity is what makes UDP fast.
That's it. No sequence numbers. No acknowledgments. No window size. No flags. Just source, destination, length, and an optional integrity check.
Wireshark is the industry-standard packet analyzer. It captures live network traffic and lets you inspect every byte of every packet. Here's how to use it for TCP/UDP analysis:
In Wireshark, you can right-click any TCP stream and select "Follow TCP Stream" to reconstruct the entire conversation between client and server — incredibly useful for forensics and debugging.
The attacker sends thousands of SYN packets with spoofed source IPs. The server responds with SYN-ACKs to non-existent hosts and waits for ACKs that never come. Each half-open connection consumes server memory. Eventually, the server's connection table fills up and it can't accept legitimate connections.
Defense: SYN cookies (stateless SYN handling), connection timeouts, rate limiting, cloud DDoS mitigation (Cloudflare, AWS Shield).
An attacker on the same network sniffs the sequence numbers of an active TCP session and injects packets with valid sequence numbers, effectively taking over the conversation. They can execute commands as the legitimate user.
Defense: Encryption (TLS/SSL), randomized ISNs, network segmentation.
The attacker sends small UDP requests (e.g., DNS queries) with the victim's IP as the source address. The servers respond with much larger replies to the victim. A 60-byte query can generate a 4,000-byte response — a 70x amplification factor.
Defense: BCP38 (ingress filtering), response rate limiting, disable open resolvers.
Tools like Nmap use crafted TCP/UDP packets to discover open ports. A SYN scan sends SYN to each port — if SYN-ACK returns, the port is open. An XMAS scan sets FIN+PSH+URG flags to evade basic firewalls. A NULL scan sends no flags at all.
Defense: Firewalls, IDS/IPS, port knocking, limiting exposed services.
| Port | Protocol | Service | Notes |
|---|---|---|---|
| 20/21 | TCP | FTP | File Transfer (20=data, 21=control) |
| 22 | TCP | SSH | Secure Shell / encrypted remote access |
| 23 | TCP | Telnet | Unencrypted remote access (avoid!) |
| 25 | TCP | SMTP | Send email |
| 53 | TCP/UDP | DNS | Domain Name System |
| 80 | TCP | HTTP | Unencrypted web traffic |
| 443 | TCP | HTTPS | Encrypted web traffic (TLS) |
| 3389 | TCP | RDP | Windows Remote Desktop |
| 8080 | TCP | HTTP Alt | Common for proxies / dev servers |
Well-known ports: 0–1023 (require root/admin). Registered: 1024–49151. Ephemeral/Dynamic: 49152–65535 (used by clients for outgoing connections).
Watch TCP packets fly between Client and Server. Click "Start Handshake" to begin!
Toggle TCP flags to build your own segment. The hex value and meaning update in real-time.
All certification names are referenced for educational purposes only. This project is not affiliated with any certification body.