🔀 Networking Protocols
Understand TCP, UDP, NAT and how data reliably (or speedily) moves across networks.
🔀 TCP vs UDP
Q1What is the difference between TCP and UDP?Intermediate▼
Both TCP and UDP are transport layer (Layer 4) protocols for sending data over IP networks, but they work very differently:
- TCP (Transmission Control Protocol) — Connection-oriented. Establishes a connection (3-way handshake), guarantees delivery, orders packets, detects errors. Slower but reliable. Used by: HTTP/HTTPS, FTP, SSH, email.
- UDP (User Datagram Protocol) — Connectionless. Fire-and-forget — no guarantee of delivery or ordering. Faster, lower overhead. Used by: DNS, video streaming, online gaming, VoIP.
💡 Think of TCP like a phone call (confirmed connection, two-way, ordered). UDP is like sending postcards (fast, no confirmation, might arrive out of order).
Q2What is the TCP 3-way handshake?Intermediate▼
Before TCP sends any data, it establishes a connection using a 3-way handshake:
- SYN — Client sends a "synchronise" packet to the server: "I want to connect"
- SYN-ACK — Server replies: "OK, I acknowledge your request, and I'm ready"
- ACK — Client confirms: "Great, connection established"
Only after this exchange does actual data transfer begin. This ensures both sides are ready and have agreed on initial sequence numbers.
⚠️ SYN flood attacks exploit this by sending many SYN packets without completing the handshake, exhausting server resources.
🌐 NAT
Q3What is NAT and why is it used?Intermediate▼
NAT (Network Address Translation) is a technique that allows multiple devices on a private network to share a single public IP address when accessing the internet.
Your home router does NAT constantly — your phone, laptop and TV all have private IPs (e.g. 192.168.1.x) but share one public IP assigned by your ISP.
How it works:
- Device sends packet with private source IP to router
- Router replaces private IP with its public IP and records the mapping in a NAT table
- Return traffic arrives at router's public IP; router looks up the table and forwards to the right private device
💡 NAT is one reason IPv4 hasn't run out yet — billions of devices share millions of public IPs. IPv6 was designed to eliminate the need for NAT entirely.