Overview
Networking is how computers communicate with each other. Every web page you load, every API you call, and every message you send travels through a network. Understanding networking helps you build faster applications, debug mysterious failures, design secure systems, and reason clearly about distributed architecture.
The OSI Model
Section titled “The OSI Model”The OSI (Open Systems Interconnection) model breaks network communication into 7 abstract layers. Each layer has a specific responsibility and communicates only with the layers directly above and below it.
- Layer 1 - Physical - raw bits on the wire; cables, Wi-Fi signals, fibre optics
- Layer 2 - Data Link - frames sent between devices on the same local network; MAC addresses and switches
- Layer 3 - Network - packets routed between different networks; IP addresses and routers
- Layer 4 - Transport - segments of data sent end-to-end; TCP and UDP; ports
- Layer 5 - Session - managing sessions (opening, maintaining, closing connections)
- Layer 6 - Presentation - data formatting, encryption, and compression
- Layer 7 - Application - protocols your applications use directly: HTTP, DNS, SMTP, FTP
In practice, the TCP/IP model (4 layers) is what the internet actually uses. It collapses OSI layers 5, 6, and 7 into one Application layer.
IP Addressing
Section titled “IP Addressing”Every device on a network has an IP address that identifies it.
- IPv4 - 32-bit addresses written as four octets:
192.168.1.1; approximately 4 billion unique addresses - IPv6 - 128-bit addresses written as eight groups of hex:
2001:0db8:85a3::8a2e:0370:7334; virtually unlimited addresses - Public vs Private IP - private addresses (10.x.x.x, 172.16-31.x.x, 192.168.x.x) are used inside networks; public addresses are routable on the internet
- Subnets and CIDR Notation -
192.168.1.0/24means the first 24 bits are the network address, leaving 8 bits for host addresses (256 possible hosts) - NAT (Network Address Translation) - allows many devices with private IPs to share one public IP; your home router does this
- Loopback -
127.0.0.1(IPv4) and::1(IPv6) always refer to the local machine
DNS (Domain Name System) translates human-readable domain names into IP addresses.
- Why DNS - people use names like
example.com; machines use IP addresses like93.184.216.34 - DNS resolution process:
- Browser checks its local cache
- OS checks
/etc/hostsand its own cache - Query goes to the Recursive Resolver (usually provided by your ISP or a public resolver like
8.8.8.8) - Resolver queries the Root Nameserver
- Root directs the resolver to the TLD Nameserver (e.g.,
.com) - TLD directs the resolver to the Authoritative Nameserver for the domain
- Authoritative Nameserver returns the IP address
- Record Types:
A- maps a domain to an IPv4 addressAAAA- maps a domain to an IPv6 addressCNAME- maps a domain to another domain (alias)MX- mail exchange; where to send email for this domainTXT- arbitrary text; used for verification and SPF/DKIM email authenticationNS- nameserver records; which DNS servers are authoritative for this domainSOA- start of authority; administrative information about the zone
- TTL (Time to Live) - how long a DNS record is cached before being re-fetched
- DNS over HTTPS (DoH) and DNS over TLS (DoT) - encrypting DNS queries for privacy
TCP and UDP
Section titled “TCP and UDP”The Transport layer is responsible for sending data reliably (or quickly) between two endpoints.
TCP (Transmission Control Protocol)
Section titled “TCP (Transmission Control Protocol)”TCP is reliable, ordered, and connection-oriented.
- Three-Way Handshake - establishing a connection:
- Client sends
SYN - Server responds
SYN-ACK - Client sends
ACK; connection is established
- Client sends
- Four-Way Teardown - closing a connection:
FIN -> FIN-ACK -> FIN -> FIN-ACK - Reliability mechanisms:
- Sequence numbers and acknowledgements (ACKs)
- Retransmission of lost packets
- Flow control (sliding window) - prevents the sender from overwhelming the receiver
- Congestion control - prevents the sender from overwhelming the network (slow start, AIMD)
- Use cases: HTTP/HTTPS, email, file transfers, anything where data must arrive intact
UDP (User Datagram Protocol)
Section titled “UDP (User Datagram Protocol)”UDP is fast, connectionless, and unreliable (no guarantee of delivery or order).
- No handshake, no acknowledgements, no retransmissions
- Much lower overhead than TCP
- The application handles any needed reliability
- Use cases: DNS lookups, video streaming, online gaming, VoIP, live broadcasts
- QUIC - a modern protocol built on UDP that adds reliability and encryption (used by HTTP/3)
HTTP and HTTPS
Section titled “HTTP and HTTPS”HTTP is the protocol that powers the web. It is a text-based, request-response protocol.
HTTP Request Structure
Section titled “HTTP Request Structure”GET /api/users?page=1 HTTP/1.1Host: example.comAuthorization: Bearer <token>Accept: application/jsonHTTP Response Structure
Section titled “HTTP Response Structure”HTTP/1.1 200 OKContent-Type: application/jsonContent-Length: 123
{"users": [...]}HTTP Methods
Section titled “HTTP Methods”GET- retrieve a resource; safe and idempotentPOST- create a resource or submit data; not idempotentPUT- replace a resource entirely; idempotentPATCH- partially update a resourceDELETE- remove a resource; idempotentHEAD- like GET but returns only headers, no bodyOPTIONS- describes the communication options for the target resource (used in CORS preflight)
HTTP Status Codes
Section titled “HTTP Status Codes”- 1xx Informational:
100 Continue - 2xx Success:
200 OK,201 Created,204 No Content - 3xx Redirection:
301 Moved Permanently,302 Found,304 Not Modified - 4xx Client Error:
400 Bad Request,401 Unauthorised,403 Forbidden,404 Not Found,429 Too Many Requests - 5xx Server Error:
500 Internal Server Error,502 Bad Gateway,503 Service Unavailable
HTTP Versions
Section titled “HTTP Versions”- HTTP/1.0 - one request per connection; very inefficient
- HTTP/1.1 - persistent connections and pipelining; still widely used
- HTTP/2 - multiplexing (multiple requests over one connection), header compression, server push
- HTTP/3 - built on QUIC (UDP); eliminates head-of-line blocking; faster connection setup
HTTPS and TLS
Section titled “HTTPS and TLS”- TLS (Transport Layer Security) - encrypts the connection between client and server
- TLS Handshake - negotiating cipher suites and exchanging certificates to establish an encrypted session
- Certificates - issued by Certificate Authorities (CAs); prove the server’s identity
- HSTS (HTTP Strict Transport Security) - forces browsers to always use HTTPS for a domain
Sockets
Section titled “Sockets”Sockets are the fundamental API for network communication.
- A socket is one endpoint of a two-way communication link; identified by IP address + port
- TCP socket lifecycle:
socket() -> bind() -> listen() -> accept() -> recv/send -> close() - UDP socket lifecycle:
socket() -> bind() -> recvfrom/sendto -> close() - Ports:
- Well-known ports (0–1023): HTTP (80), HTTPS (443), SSH (22), DNS (53), SMTP (25)
- Registered ports (1024–49151): application-specific
- Dynamic/ephemeral ports (49152–65535): assigned to clients automatically
WebSockets
Section titled “WebSockets”WebSockets enable full-duplex, persistent communication between a client and server.
- Problem with HTTP for real-time - HTTP is request-response; the server cannot push data to the client unprompted
- WebSocket handshake - starts as an HTTP
Upgraderequest; switches to the WebSocket protocol - Full-duplex - both sides can send messages at any time without waiting for the other
- Use cases: live chat, real-time notifications, collaborative editing, stock tickers, online games
- Server-Sent Events (SSE) - a simpler alternative for server-to-client streaming over HTTP (one-directional)
- Long Polling - a workaround before WebSockets; client holds a connection open until the server has something to send
Network Security
Section titled “Network Security”- Encryption: symmetric (AES) vs asymmetric (RSA, ECC); how TLS combines both
- Hashing: SHA-256, bcrypt; password storage and data integrity
- Common Attacks:
- DDoS (Distributed Denial of Service) - flooding a server with traffic to make it unavailable
- Man-in-the-Middle (MITM) - intercepting communication between two parties
- SQL Injection - injecting malicious SQL through user input
- XSS (Cross-Site Scripting) - injecting malicious scripts into web pages
- CSRF (Cross-Site Request Forgery) - tricking a user’s browser into making unintended requests
- DNS Spoofing / Cache Poisoning - sending malicious DNS responses to redirect traffic
- Firewalls - filtering traffic based on rules (IP, port, protocol)
- VPN (Virtual Private Network) - encrypting all traffic and routing it through a private server
- Zero Trust Architecture - never trust any connection by default; verify every request explicitly
Load Balancers
Section titled “Load Balancers”Load balancers distribute incoming requests across multiple servers to improve availability and performance.
- Why load balancing - no single server can handle unlimited traffic; spreading load enables horizontal scaling
- Layer 4 Load Balancing - routes based on IP and TCP/UDP; fast but no application awareness
- Layer 7 Load Balancing - routes based on HTTP content (URL, headers, cookies); smarter but more overhead
- Algorithms:
- Round Robin - requests distributed in order to each server
- Least Connections - send to the server with the fewest active connections
- IP Hash - the same client IP always goes to the same server (session affinity)
- Weighted Round Robin - servers with more capacity receive more requests
- Health checks - the load balancer periodically checks each server and removes unhealthy ones
- Examples: NGINX, HAProxy, AWS ELB/ALB, Cloudflare
A Content Delivery Network (CDN) caches content on servers distributed around the world, reducing latency for end users.
- How CDNs work - when a user requests content, they are served from the nearest CDN edge node (PoP) rather than the origin server
- What CDNs cache: static assets (images, JS, CSS), videos, HTML pages
- Cache-Control headers - the origin server controls how long and how CDN nodes cache a response
- Cache invalidation - purging or updating cached content when the origin changes
- CDN benefits: lower latency, reduced load on origin, protection against DDoS, better availability
- Examples: Cloudflare, AWS CloudFront, Akamai, Fastly
Routing and Switching
Section titled “Routing and Switching”- Switch - connects devices within the same local network (LAN); uses MAC addresses to forward frames (Layer 2)
- Router - connects different networks; uses IP addresses to forward packets (Layer 3)
- Routing Tables - a list of known networks and the next hop to reach them
- Routing Protocols: OSPF, BGP (the protocol that connects autonomous systems on the internet)
- ARP (Address Resolution Protocol) - maps an IP address to a MAC address on a local network
Networking underpins everything in modern software. Once you understand how packets travel from one machine to another, why TCP is reliable while UDP is fast, and how HTTP is structured, you will be much better equipped to build and debug distributed systems.