The Big Picture
The Internet is a network of networks — billions of devices connected through a hierarchy of local, regional, and global networks, all speaking the same set of protocols. Every interaction you have online, from loading a webpage to streaming video, involves data being broken into packets, routed across multiple networks, and reassembled at the destination.
The Internet is not a single technology but an architecture — a set of agreements about how to communicate, layered on top of each other. — Vint Cerf, co-designer of TCP/IP
Layered Architecture
Networking is organized into layers, each responsible for a specific concern. This separation lets you swap out physical media (copper to fiber) without changing how TCP works, or deploy a new application protocol without touching routing.
Packet Switching vs Circuit Switching
The Internet uses packet switching, not circuit switching (like traditional phone networks). This fundamental design choice is what makes the Internet resilient and efficient.
Circuit Switching
- Dedicated path for entire call
- Guaranteed bandwidth
- Wasteful when idle
- Connection setup delay
- Single point of failure
- Used by: PSTN (phone network)
Packet Switching
- Data split into independent packets
- Packets share links (statistical multiplexing)
- Efficient — bandwidth used only when needed
- Packets can take different routes
- Resilient to link failures
- Used by: The Internet
End-to-End Principle
The core design philosophy of the Internet: keep the network core simple and dumb (just forward packets), and put intelligence at the endpoints (devices). This is why innovation happens at the edges — you don't need to upgrade the entire Internet to deploy a new protocol.
Best-Effort Delivery
IP provides no guarantees — packets can be lost, duplicated, reordered, or delayed. Reliability is built on top (TCP), not into the network itself. This keeps routers fast and simple.
Physical Layer
Everything on the Internet ultimately comes down to physical signals — electrical voltages, pulses of light, or radio waves. The physical layer is responsible for converting bits (0s and 1s) into signals that can travel across a medium.
Transmission Media
Copper (Twisted Pair)
Electrical signals over copper wires. Cat5e supports up to 1 Gbps, Cat6a up to 10 Gbps. Maximum distance ~100m. Susceptible to electromagnetic interference (EMI). Used in Ethernet LANs.
Fiber Optics
Pulses of light through glass/plastic fibers. Single-mode fiber carries signals 100+ km. Multi-mode for shorter runs (~550m). Immune to EMI. Bandwidth up to 100+ Tbps per fiber with DWDM.
Radio Waves (Wireless)
Wi-Fi (2.4/5/6 GHz), cellular (4G/5G), Bluetooth. Subject to interference, attenuation, and multipath. Wi-Fi 6E reaches ~9.6 Gbps theoretical. 5G mmWave: up to 10+ Gbps but very short range.
Submarine Cables
Fiber optic cables on the ocean floor connecting continents. ~550+ active cables carrying 99% of intercontinental data. Each cable contains multiple fiber pairs, each carrying terabits/s. Repeaters every ~60-100 km amplify the signal.
How Bits Become Signals
Real networks use more sophisticated encoding schemes like Manchester encoding (clock embedded in signal), 4B/5B (Ethernet), QAM (Wi-Fi/cellular, encodes multiple bits per symbol), and PAM-4 (modern Ethernet, 2 bits per symbol using 4 voltage levels).
| Medium | Signal Type | Max Speed | Max Distance | Latency |
|---|---|---|---|---|
| Cat6a Copper | Electrical | 10 Gbps | 100m | ~5 ns/m |
| Single-mode Fiber | Light | 100+ Tbps (DWDM) | 100+ km | ~5 ns/m |
| Wi-Fi 6E | Radio (6 GHz) | 9.6 Gbps | ~30m (indoor) | ~1-5 ms |
| 5G mmWave | Radio (24-100 GHz) | 10+ Gbps | ~200m | ~1 ms |
| Submarine Fiber | Light | Tbps per pair | Trans-oceanic | ~5 ns/m + repeaters |
OSI vs TCP/IP Model
There are two major models for understanding network communication: the OSI model (7 layers, theoretical reference) and the TCP/IP model (4 layers, what the Internet actually uses). The OSI model is more granular; the TCP/IP model is more practical.
All 7 OSI Layers Explained
| Layer | Name | Function | Data Unit | Protocols/Examples |
|---|---|---|---|---|
| 7 | Application | User-facing services and interfaces | Data | HTTP, FTP, SMTP, DNS, SSH |
| 6 | Presentation | Data formatting, encryption, compression | Data | SSL/TLS, JPEG, ASCII, MPEG |
| 5 | Session | Session management, dialog control | Data | NetBIOS, RPC, PPTP |
| 4 | Transport | End-to-end delivery, flow control | Segment | TCP, UDP, QUIC, SCTP |
| 3 | Network | Logical addressing, routing | Packet | IP, ICMP, ARP, BGP, OSPF |
| 2 | Data Link | Framing, MAC addressing, error detection | Frame | Ethernet, Wi-Fi (802.11), PPP |
| 1 | Physical | Raw bit transmission over physical medium | Bits | Copper, Fiber, Radio, USB |
Encapsulation
As data moves down the stack, each layer wraps it with its own header (and sometimes trailer). This is called encapsulation. At the receiving end, each layer strips its header in reverse order.
IP (Internet Protocol)
IP is the network layer protocol that handles addressing and routing. Every device on the Internet has an IP address, and every packet contains source and destination IP addresses so routers know where to forward it. IP is connectionless and provides best-effort delivery.
IPv4 vs IPv6
| Feature | IPv4 | IPv6 |
|---|---|---|
| Address Size | 32 bits (4 bytes) | 128 bits (16 bytes) |
| Address Space | ~4.3 billion | ~3.4 × 1038 |
| Notation | 192.168.1.1 | 2001:0db8::1 |
| Header Size | 20-60 bytes (variable) | 40 bytes (fixed) |
| Checksum | Yes (header only) | No (removed for speed) |
| Fragmentation | Routers + sender | Sender only |
| NAT Required? | Yes (address exhaustion) | No (enough addresses) |
| IPsec | Optional | Built-in (mandatory support) |
| Broadcast | Yes | No (uses multicast) |
IPv4 Packet Structure
Subnetting & CIDR
CIDR (Classless Inter-Domain Routing) replaced the old classful addressing (Class A/B/C). The notation /24 means the first 24 bits are the network portion, leaving 8 bits for hosts.
NAT (Network Address Translation)
Since IPv4 addresses are exhausted, NAT allows many devices to share one public IP. Your home router has one public IP but assigns private IPs (like 192.168.x.x) to your devices internally.
TCP (Transmission Control Protocol)
TCP provides reliable, ordered, error-checked delivery of a byte stream between applications. It is the workhorse of the Internet — HTTP, SSH, SMTP, FTP, and most application protocols run on top of TCP. TCP turns IP's unreliable packet delivery into a reliable communication channel.
TCP Segment Structure
Three-Way Handshake
Before any data flows, TCP establishes a connection using a three-way handshake. This synchronizes sequence numbers and confirms both sides are ready.
Connection Teardown (Four-Way)
Flow Control: Sliding Window
The receiver advertises a window size — how much data it can buffer. The sender never sends more than the window allows. This prevents a fast sender from overwhelming a slow receiver.
Congestion Control
TCP also limits sending rate to avoid congesting the network itself. The sender maintains a congestion window (cwnd) separate from the receive window.
Slow Start
Start with cwnd = 1 MSS. Double cwnd every RTT (exponential growth). Continue until hitting ssthresh (slow start threshold) or detecting loss.
Congestion Avoidance (AIMD)
After reaching ssthresh: Additive Increase — add 1 MSS per RTT (linear growth). On packet loss: Multiplicative Decrease — halve cwnd. This sawtooth pattern probes for available bandwidth.
Fast Retransmit
If sender receives 3 duplicate ACKs for the same sequence number, retransmit the lost segment immediately without waiting for the retransmission timeout (RTO).
Fast Recovery
After fast retransmit, set ssthresh = cwnd/2, set cwnd = ssthresh + 3 MSS, then enter congestion avoidance. Avoids going back to slow start for a single lost packet.
UDP (User Datagram Protocol)
UDP is TCP's minimalist sibling. It provides a connectionless, unreliable transport — just source/destination ports and a checksum. No handshakes, no acknowledgments, no ordering, no flow control. This makes it fast and lightweight, ideal for applications that prefer speed over reliability.
TCP vs UDP
| Feature | TCP | UDP |
|---|---|---|
| Connection | Connection-oriented | Connectionless |
| Reliability | Guaranteed delivery (retransmits) | Best-effort (fire and forget) |
| Ordering | In-order delivery | No ordering guarantee |
| Flow Control | Yes (sliding window) | No |
| Congestion Control | Yes (slow start, AIMD) | No |
| Header Size | 20-60 bytes | 8 bytes |
| Speed | Slower (overhead) | Faster (minimal overhead) |
| Use Cases | HTTP, SSH, email, file transfer | DNS, gaming, video, VoIP, QUIC |
When to Use UDP
Real-Time Gaming
A late packet is worse than a lost packet. Player positions update 30-60 times/sec — by the time a retransmit arrives, the data is stale.
DNS Queries
Small request/response (usually fits in one packet). Connection setup overhead of TCP would double latency. UDP keeps DNS lookups fast.
Video/Audio Streaming
VoIP, video conferencing. Missing a frame is acceptable — the codec can interpolate. Retransmitting would cause jitter and delay.
QUIC (HTTP/3)
Builds its own reliability on top of UDP. Gets the benefits of connection management + encryption while avoiding TCP's head-of-line blocking at the OS level.
DNS (Domain Name System)
DNS is the phone book of the Internet. It translates human-readable domain names (like example.com) into IP addresses (like 93.184.216.34). Without DNS, you'd have to memorize IP addresses for every website. DNS is a hierarchical, distributed database — no single server has all the answers.
DNS Hierarchy
DNS Resolution Flow
Recursive vs Iterative Resolution
Recursive
- Client asks resolver, resolver does all the work
- Resolver queries root, TLD, authoritative on your behalf
- Client gets the final answer
- Used by: your ISP's resolver, 8.8.8.8, 1.1.1.1
- Resolver caches results for future queries
Iterative
- Each server returns a referral, not the answer
- "I don't know, but ask this server"
- Client/resolver follows the chain itself
- Used between: recursive resolvers and authoritative servers
- Root and TLD servers always respond iteratively
DNS Record Types
| Type | Name | Purpose | Example |
|---|---|---|---|
| A | Address | Maps domain to IPv4 address | example.com → 93.184.216.34 |
| AAAA | IPv6 Address | Maps domain to IPv6 address | example.com → 2606:2800:220:1::248 |
| CNAME | Canonical Name | Alias one domain to another | www.example.com → example.com |
| MX | Mail Exchange | Mail server for the domain | example.com → mail.example.com (pri 10) |
| TXT | Text | Arbitrary text (SPF, DKIM, verification) | "v=spf1 include:_spf.google.com ~all" |
| NS | Name Server | Delegates zone to authoritative NS | example.com → ns1.example.com |
| SOA | Start of Authority | Zone metadata (serial, refresh, TTL) | Primary NS, admin email, serial number |
| PTR | Pointer | Reverse DNS (IP to domain) | 34.216.184.93 → example.com |
| SRV | Service | Service location (port + host) | _sip._tcp.example.com → sip.example.com:5060 |
TTL and Caching
Every DNS record has a TTL (Time to Live) in seconds. Resolvers cache the record for that duration. Low TTL (60s) means faster propagation of changes but more DNS queries. High TTL (86400s = 1 day) reduces load but changes propagate slowly.
HTTP/1.1, HTTP/2, HTTP/3
HTTP (HyperText Transfer Protocol) is the application layer protocol that powers the web. It has evolved significantly over three major versions, each solving problems introduced by the previous one.
Evolution at a Glance
| Feature | HTTP/1.1 | HTTP/2 | HTTP/3 |
|---|---|---|---|
| Transport | TCP | TCP | QUIC (UDP) |
| Format | Text-based | Binary framing | Binary framing |
| Multiplexing | No (1 req/conn) | Yes (streams) | Yes (streams) |
| Head-of-Line Blocking | TCP + HTTP | TCP only | None |
| Header Compression | None | HPACK | QPACK |
| Server Push | No | Yes | Yes |
| Connection Setup | TCP + TLS (3 RTTs) | TCP + TLS (2-3 RTTs) | 1 RTT (0-RTT resumption) |
| Encryption | Optional (HTTPS) | Practically required | Built-in (always TLS 1.3) |
The Head-of-Line Blocking Problem
QUIC: The Foundation of HTTP/3
QUIC is a transport protocol built on UDP that provides connection-oriented, encrypted, multiplexed communication. It was developed by Google and standardized as RFC 9000.
0-RTT Connection Resumption
If you've connected to a server before, QUIC can send data in the very first packet using cached session keys. TCP + TLS needs at least 1-3 round trips before any data flows.
Connection Migration
TCP connections are identified by (src IP, src port, dst IP, dst port). Switch from Wi-Fi to cellular? Connection dies. QUIC uses a Connection ID, so it survives network changes.
Built-in Encryption
QUIC integrates TLS 1.3 directly into its handshake. There is no unencrypted QUIC — even the transport headers are partially encrypted, preventing middlebox interference.
Independent Streams
Each QUIC stream has its own flow control and loss recovery. A lost packet on stream A does not block streams B, C, D — solving TCP's fundamental HOL blocking problem.
TLS/SSL
TLS (Transport Layer Security) provides encryption, authentication, and integrity for communications over TCP. It's what makes HTTPS possible. SSL (Secure Sockets Layer) is the deprecated predecessor — modern "SSL" really means TLS.
What TLS Provides
Confidentiality
Data is encrypted so eavesdroppers see gibberish. Uses symmetric encryption (AES-GCM, ChaCha20-Poly1305) for bulk data, negotiated via the handshake.
Authentication
The server proves its identity using a digital certificate signed by a trusted Certificate Authority (CA). Optionally, the client can also authenticate (mutual TLS / mTLS).
Integrity
Each message includes a MAC (Message Authentication Code) that detects any tampering. If a single bit is modified in transit, the recipient knows and rejects the message.
Symmetric vs Asymmetric Encryption
Symmetric (AES, ChaCha20)
- Same key to encrypt and decrypt
- Very fast (~10 Gbps)
- Problem: how to share the key securely?
- Used for: bulk data encryption
- Key sizes: 128 or 256 bits
Asymmetric (RSA, ECDHE)
- Public key encrypts, private key decrypts
- Slow (~1000x slower than symmetric)
- Solves key exchange problem
- Used for: key exchange, signatures
- Key sizes: 2048+ bits (RSA), 256 bits (ECDH)
TLS uses both: asymmetric crypto to securely exchange a symmetric key, then symmetric crypto for the actual data. This is called a hybrid cryptosystem.
TLS 1.3 Handshake (Full)
Certificate Authority Chain of Trust
TLS 1.3 vs 1.2 Improvements
| Feature | TLS 1.2 | TLS 1.3 |
|---|---|---|
| Handshake RTTs | 2 round trips | 1 round trip (0-RTT resumption) |
| Key Exchange | RSA or ECDHE | ECDHE only (forward secrecy mandatory) |
| Cipher Suites | 37 suites (many weak) | 5 suites (all strong) |
| Encryption After | After 2nd round trip | After 1st round trip |
| Removed | — | RSA key exchange, RC4, DES, SHA-1, compression, renegotiation |
| Handshake Encrypted? | Partially (certs in clear) | Yes (after ServerHello) |
Common Cipher Suites (TLS 1.3)
HTTPS
HTTPS is simply HTTP over TLS. It wraps every HTTP request and response in a TLS encrypted tunnel. The URL scheme changes from http:// to https://, and the default port changes from 80 to 443.
What HTTPS Protects
Protected
Request/response body (form data, JSON, HTML), headers (cookies, auth tokens), URL path and query string (encrypted after TLS handshake), HTTP method.
NOT Protected
Domain name (visible via DNS query + TLS SNI), IP addresses (visible in packet headers), connection metadata (timing, packet sizes), that you're communicating at all.
Man-in-the-Middle (MITM) Attack
Certificate Pinning
Certificate pinning defends against compromised CAs by hardcoding the expected certificate (or its public key hash) in the client application. If the presented cert doesn't match the pin, the connection is rejected — even if a CA signed it. Used in mobile apps and high-security scenarios.
HSTS (HTTP Strict Transport Security)
A server can send Strict-Transport-Security: max-age=31536000; includeSubDomains to tell browsers: never connect to this domain over plain HTTP again. Prevents SSL stripping attacks where an attacker downgrades HTTPS to HTTP.
Routing
Routing is how packets find their way from source to destination across the Internet — traversing dozens of routers across multiple networks. Each router makes a local forwarding decision based on the destination IP address and its routing table.
How Routing Works
151.101.1.140Autonomous Systems (AS) and BGP
The Internet is divided into Autonomous Systems (ASes) — networks under a single administrative entity (an ISP, a company, a university). Each AS has a unique ASN (Autonomous System Number). BGP (Border Gateway Protocol) is how ASes exchange routing information with each other.
Traceroute Explained
traceroute works by sending packets with incrementing TTL values. Each router that decrements TTL to 0 sends back an ICMP "Time Exceeded" message, revealing its IP address.
Load Balancing
Load balancers distribute incoming traffic across multiple backend servers to improve availability, reliability, and performance. They sit between clients and servers, acting as a reverse proxy.
L4 vs L7 Load Balancing
Layer 4 (Transport)
- Routes based on IP + port
- Doesn't inspect packet contents
- Very fast (hardware/kernel-level)
- Works with any protocol (TCP, UDP)
- No URL-based routing possible
- Examples: AWS NLB, IPVS, LVS
Layer 7 (Application)
- Routes based on HTTP headers, URL, cookies
- Can terminate TLS, add headers, rewrite URLs
- Slower (must parse HTTP)
- URL path routing: /api → backend A, /static → CDN
- Can do content-based health checks
- Examples: AWS ALB, NGINX, HAProxy, Envoy
Load Balancing Algorithms
| Algorithm | How It Works | Best For |
|---|---|---|
| Round Robin | Send to each server in turn: A, B, C, A, B, C... | Equal-capacity servers, uniform requests |
| Weighted Round Robin | Like round robin but servers with higher weight get more traffic | Mixed-capacity servers |
| Least Connections | Send to the server with fewest active connections | Varying request durations |
| IP Hash | Hash client IP to pick server (same client → same server) | Session affinity without cookies |
| Consistent Hashing | Hash ring: minimal redistribution when servers added/removed | Caching layers, distributed systems |
| Random | Pick a server at random | Simple, stateless, surprisingly effective |
| Least Response Time | Send to server with fastest recent response + fewest connections | Latency-sensitive applications |
Health Checks
CDNs (Content Delivery Networks)
A CDN is a globally distributed network of edge servers that cache content close to users. Instead of every request traveling to the origin server (possibly across the world), it is served from the nearest edge location. This reduces latency, offloads the origin, and improves reliability.
How CDNs Work
Anycast
Anycast is how CDNs route users to the nearest edge. Multiple servers in different locations all advertise the same IP address. BGP routing naturally sends packets to the closest one (in terms of network hops).
Cache Invalidation
TTL-Based Expiry
Origin sets Cache-Control: max-age=3600. Edge serves cached content for 1 hour, then revalidates with origin. Simple but delayed updates.
Purge / Invalidation API
Origin tells CDN "invalidate /images/logo.png across all edges." Immediate but requires API integration. Cloudflare, Fastly, Akamai all offer purge APIs.
Cache Tags / Surrogate Keys
Tag cached objects (e.g., "product-123"). When the product changes, purge all content tagged "product-123" across all edges. Fine-grained invalidation.
Versioned URLs
Use /style.v2.css or /style.css?v=abc123. New version = new URL = guaranteed cache miss. Never need to invalidate — the old URL is simply never requested again.
What Happens When You Type a URL
The complete journey from pressing Enter on https://www.example.com/page to seeing a rendered page involves dozens of steps across every layer of the networking stack.
The Full Journey
https), host (www.example.com), port (443), and path (/page). Checks HSTS list — if the domain is listed, force HTTPS./etc/hosts, then sends a query to the configured DNS resolver (e.g., 8.8.8.8). The resolver queries root → TLD → authoritative servers and returns the IP (e.g., 93.184.216.34).GET /page HTTP/2 with headers: Host, User-Agent, Accept, Accept-Encoding (gzip, br), Cookie, etc. With HTTP/2, this uses binary framing and header compression (HPACK).200 OK with headers (Content-Type, Cache-Control, Set-Cookie) and the HTML body, compressed with Brotli or gzip. Response streams back in TCP segments.WebSockets
WebSockets provide full-duplex, bidirectional communication over a single TCP connection. Unlike HTTP's request-response model, either side can send messages at any time without the other having to ask. This makes WebSockets ideal for real-time applications.
The Upgrade Handshake
A WebSocket connection starts as a regular HTTP request with an Upgrade header. The server agrees by responding with 101 Switching Protocols, and from that point forward the connection is a WebSocket.
WebSockets vs Alternatives
| Technique | Direction | Connection | Latency | Use Case |
|---|---|---|---|---|
| Short Polling | Client → Server | New HTTP request every N seconds | High (up to N seconds delay) | Simple, infrequent updates |
| Long Polling | Client → Server | HTTP request held open until data available | Medium | Near-real-time, broad compatibility |
| SSE (Server-Sent Events) | Server → Client only | Single HTTP connection, text/event-stream | Low | Live feeds, notifications (one-way) |
| WebSocket | Bidirectional | Single TCP connection, full-duplex | Lowest | Chat, gaming, collaborative editing |
gRPC & Protocol Buffers
gRPC is a high-performance RPC (Remote Procedure Call) framework built by Google. It uses Protocol Buffers (protobuf) for serialization and runs on top of HTTP/2. It's widely used for microservice communication where performance matters.
Protocol Buffers vs JSON
JSON (Text-Based)
- Human-readable text
- Self-describing (keys in every message)
- Larger payload size
- Slower to parse
- Schema optional (often absent)
- Universal browser support
Protobuf (Binary)
- Binary, not human-readable
- Schema required (.proto files)
- 3-10x smaller than JSON
- Up to 100x faster parsing
- Strong typing, code generation
- Backward/forward compatible
gRPC Communication Patterns
| Pattern | Client | Server | Use Case |
|---|---|---|---|
| Unary | 1 request | 1 response | Standard request/response (like REST) |
| Server Streaming | 1 request | Stream of responses | Live feeds, large result sets |
| Client Streaming | Stream of requests | 1 response | File upload, sensor data |
| Bidirectional Streaming | Stream | Stream | Chat, real-time collaboration |
gRPC Over HTTP/2
When to Use gRPC vs REST
gRPC: microservice-to-microservice, low latency requirements, streaming data, polyglot services (code generation for 10+ languages). REST: browser clients (gRPC-Web exists but is limited), public APIs, when human readability matters, simpler tooling requirements.
Internet Backbone
The physical structure of the Internet is a hierarchy of interconnected networks, from the massive global backbone carriers down to your local ISP. Understanding this hierarchy explains why some paths are faster than others and how the Internet stays connected.
ISP Tiers
| Tier | Definition | Revenue Model | Examples |
|---|---|---|---|
| Tier 1 | Can reach entire Internet through settlement-free peering (no payment to any other network) | Sells transit to Tier 2/3 | Lumen (Level 3), NTT, Telia, GTT, Zayo |
| Tier 2 | Peers with some networks, buys transit from Tier 1 for the rest | Sells transit to Tier 3, sells to consumers | Cogent, Comcast, Orange, Deutsche Telekom |
| Tier 3 | Buys transit from Tier 2 or Tier 1 for all connectivity | Sells Internet to end users | Local/regional ISPs, municipal networks |
Peering & Transit
Peering
Two networks agree to exchange traffic directly with each other, usually for free (settlement-free). Benefits both: shorter paths, lower latency, no transit costs. Can be private (direct fiber) or public (at an IXP).
Transit
A network pays another (larger) network to carry its traffic to the rest of the Internet. The transit provider announces the customer's IP prefixes via BGP, providing global reachability.
Internet Exchange Points (IXPs)
An IXP is a physical building where hundreds of networks plug into a shared switch fabric and peer with each other. This keeps local traffic local — instead of packets from ISP-A to ISP-B in the same city going through a Tier 1 backbone across the country and back.
Physical Internet Structure
The Internet Is Surprisingly Physical
Despite being "the cloud," the Internet is made of real things: fiber optic cables running along railroad tracks and ocean floors, routers in climate-controlled buildings, and servers in massive data centers consuming megawatts of power. A ship dragging its anchor across a submarine cable has caused nationwide outages. The Internet's resilience comes from redundancy, not invulnerability.