Fundamentals — Cheat Sheet
Computer Networks · 5 topics. Download the PDF or the Instagram carousel and share it.
OSI Model
The OSI model is a 7-layer conceptual framework that standardises how different network protocols communicate, from physical bit transmission to application-level data exchange.
- ✓OSI has 7 layers: Physical (1), Data Link (2), Network (3), Transport (4), Session (5), Presentation (6), Application (7).
- ✓Each layer adds its own header during encapsulation and strips it during decapsulation.
- ✓The OSI model is theoretical; TCP/IP (4 layers) is what is actually implemented.
- ✓Routers operate at Layer 3; switches at Layer 2; hubs at Layer 1.
- ✓TLS operates at Layer 6 (Presentation) — it encrypts before TCP sends data.
- ✓Knowing which layer a protocol belongs to is critical for network troubleshooting.
// OSI Layers — top to bottom // ┌─────────────────────────────────────────────────────────────────────┐ // │ Layer 7 — Application │ HTTP, HTTPS, FTP, SMTP, DNS, WebSocket │ // │ Layer 6 — Presentation │ TLS/SSL, JPEG, MPEG, ASCII encoding │ // │ Layer 5 — Session │ NetBIOS, RPC, session establishment │ // │ Layer 4 — Transport │ TCP, UDP — ports, reliability, flow ctrl │ // │ Layer 3 — Network │ IP, ICMP, ARP, routing │ // │ Layer 2 — Data Link │ Ethernet, MAC, switches, frames │ // │ Layer 1 — Physical │ Cables, fibre, Wi-Fi, bits │ // └─────────────────────────────────────────────────────────────────────┘ // Java socket sits at Layer 4/5 boundary: ServerSocket server = new ServerSocket(8080); // Transport layer (TCP port) Socket client = server.accept(); // Session layer (connection) InputStream in = client.getInputStream(); // Layer 5–7 data exchange
TCP/IP Model
The TCP/IP model is the practical 4-layer networking framework that powers the internet — combining the OSI model's upper layers into one Application layer and mapping cleanly to real protocols.
- ✓TCP/IP has 4 layers: Network Access, Internet, Transport, Application.
- ✓OSI is a conceptual model; TCP/IP is what the internet actually runs on.
- ✓Application layer = HTTP, HTTPS, DNS, SMTP, SSH, WebSocket.
- ✓Transport layer = TCP (reliable) and UDP (unreliable but fast).
- ✓Internet layer = IP addressing and routing between networks.
- ✓Data units: Message → Segment/Datagram → Packet → Frame → Bits.
// TCP/IP vs OSI mapping: // ┌──────────────────────┬──────────────────────────────────────┐ // │ TCP/IP Layer │ OSI Equivalent │ Protocols │ // ├──────────────────────┼──────────────────────────────────────┤ // │ Application │ Layers 5, 6, 7 │ HTTP, DNS, SSH │ // │ Transport │ Layer 4 │ TCP, UDP │ // │ Internet │ Layer 3 │ IP, ICMP, ARP │ // │ Network Access/Link │ Layers 1, 2 │ Ethernet, Wi-Fi│ // └──────────────────────┴──────────────────────────────────────┘ // A Java HTTP request flows through: // 1. Application: HttpClient sends GET /api/users HTTP/1.1 // 2. Transport: TCP segments the request, adds port (443), handles reliability // 3. Internet: IP adds source/destination IP, routes across routers // 4. Network Access: Ethernet frames carry IP packets over the physical network
Network Types — LAN, WAN, MAN & VPN
Networks are classified by geographic scope: PAN (personal), LAN (local), MAN (metro), WAN (wide area). VPN extends a private network securely over a public WAN.
- ✓LAN: local network (building/campus), < 1ms latency, Ethernet/Wi-Fi.
- ✓WAN: wide area network (internet), 50–300ms latency, leased lines or internet.
- ✓MAN: metropolitan, city-scale, used by ISPs and large enterprises.
- ✓VPN creates an encrypted Layer 3 tunnel over a public WAN.
- ✓Intra-datacenter (LAN) latency ~0.1–1ms; cross-region (WAN) ~50–200ms — design systems accordingly.
- ✓Cloud VPCs are private virtual LANs — inter-VPC traffic over a WAN requires VPC peering or VPN.
// Network types at a glance: // ┌────────┬─────────────────┬─────────┬──────────┬──────────────────────┐ // │ Type │ Scope │ Speed │ Latency │ Example │ // ├────────┼─────────────────┼─────────┼──────────┼──────────────────────┤ // │ PAN │ < 10 metres │ ~3 Mbps │ < 1ms │ Bluetooth, USB │ // │ LAN │ Building/Campus │ 1 Gbps+ │ < 1ms │ Office Wi-Fi │ // │ MAN │ City │ 100Mbps │ 1–10ms │ ISP city ring │ // │ WAN │ Global │ Varies │ 50–300ms │ Internet, MPLS links │ // └────────┴─────────────────┴─────────┴──────────┴──────────────────────┘ // In a microservices context: // Service A → Service B (same datacenter, LAN): ~0.5ms // Service A → Service B (different region, WAN): ~150ms // This is why you keep chatty services co-located and use async // messaging for cross-region communication.
Bandwidth, Latency & Throughput
Bandwidth is maximum capacity, latency is delay, and throughput is actual data transferred per second. Understanding the relationship between them is essential for designing and debugging performant distributed systems.
- ✓Bandwidth = max capacity of a link (Gbps). Latency = delay for a packet to travel (ms). Throughput = actual data rate achieved.
- ✓Throughput ≤ Bandwidth; reduced by latency, packet loss, and overhead.
- ✓Bandwidth-Delay Product = Bandwidth × RTT — the amount of data in-flight to saturate the link.
- ✓For small payloads (APIs), latency dominates; for large payloads (file transfers), bandwidth dominates.
- ✓RTT ranges: ~0.1ms (LAN), ~1–10ms (same region), ~50–150ms (cross-continent).
- ✓Parallel async calls (CompletableFuture) reduce perceived latency in microservice fan-outs.
// Bandwidth-Delay Product (BDP): // BDP = Bandwidth × RTT // = the amount of data "in flight" at any moment // Example: 1 Gbps link, 100ms RTT // BDP = 1,000,000,000 bits/s × 0.1s = 100,000,000 bits = 12.5 MB // To fully utilise this link, the TCP window must be ≥ 12.5 MB // Latency components: // 1. Propagation delay = distance / speed of light in medium // London → New York ≈ 5,570 km, ~28ms one-way // 2. Transmission delay = packet size / bandwidth // 1 KB packet on 1 Gbps link = 8,000 bits / 1e9 bps = 0.008ms // 3. Queuing delay = time waiting in router buffers (variable) // 4. Processing delay = time for router to inspect headers // Rule of thumb: // < 1ms — same datacenter (LAN) // 1–10ms — same region / CDN edge // 50–100ms — same continent // 100–300ms — cross-continent
Packets, Frames & Encapsulation
Data is broken into packets at Layer 3 and frames at Layer 2. Encapsulation wraps data with headers at each layer; MTU limits frame size and drives IP fragmentation.
- ✓Packets (Layer 3) carry IP addresses; frames (Layer 2) carry MAC addresses.
- ✓Ethernet MTU is 1500 bytes — the maximum IP packet payload per frame.
- ✓TCP MSS = MTU − IP header (20B) − TCP header (20B) = 1460 bytes.
- ✓IP fragmentation splits oversized packets; reassembly happens only at the destination.
- ✓Path MTU Discovery avoids fragmentation by probing the minimum MTU on the path.
- ✓VPNs add header overhead, reducing effective MTU — MSS clamping compensates.
// Ethernet Frame structure (Layer 2): // ┌──────────────┬──────────────┬──────┬──────────────────────┬─────┐ // │ Dst MAC (6B) │ Src MAC (6B) │ Type │ Payload (IP Packet) │ FCS │ // └──────────────┴──────────────┴──────┴──────────────────────┴─────┘ // Max payload = 1500 bytes (standard Ethernet MTU) // Jumbo frames = up to 9000 bytes (datacenter NICs) // IPv4 Packet structure (Layer 3): // ┌────────────────────────────────────────────────────────────────┐ // │ Version │ IHL │ DSCP │ Total Length │ ID │ Flags │ Fragment │ // │ TTL │ Protocol │ Checksum │ Source IP (4B) │ // │ Destination IP (4B) │ Options (variable) │ // │ Payload (TCP Segment / UDP Datagram) │ // └────────────────────────────────────────────────────────────────┘ // Protocol field identifies Layer 4 protocol: // 6 = TCP, 17 = UDP, 1 = ICMP