Computer Networks Cheatsheet

Quick reference — OSI layers, HTTP methods and status codes, TCP vs UDP, common ports.

TCP/IPHTTPDNSOSI Model
NotesCheatsheet

OSI Model — 7 Layers

#LayerExamplesPDU
7ApplicationHTTP, HTTPS, DNS, FTP, SMTP, WebSocketMessage
6PresentationTLS/SSL, JSON, XML, JPEGData
5SessionSession tokens, TLS handshake setupData
4TransportTCP, UDPSegment
3NetworkIP, ICMP, routersPacket
2Data LinkEthernet, Wi-Fi, switches, MACFrame
1PhysicalCables, fibre, radio, voltageBit

Mnemonic: All People Seem To Need Data Processing (7 → 1)

TCP vs UDP

FeatureTCPUDP
ConnectionConnection-oriented (3-way handshake)Connectionless
ReliabilityGuaranteed delivery, retransmit on lossBest-effort, no retransmit
OrderingIn-orderMay arrive out of order or not at all
OverheadHigher (ACK, retransmit, flow control)Minimal header (8 bytes)
Use casesHTTP/S, SSH, email, file transferDNS, video streaming, gaming, VoIP

TCP 3-Way Handshake

Client → Server:  SYN  (seq=x)
Server → Client:  SYN-ACK  (seq=y, ack=x+1)
Client → Server:  ACK  (ack=y+1)
[CONNECTION OPEN]

// Close: FIN → FIN-ACK → FIN → ACK  (4-way)

HTTP Methods

MethodActionIdempotentSafe
GETRetrieveYesYes
POSTCreateNoNo
PUTReplace entire resourceYesNo
PATCHPartial updateDependsNo
DELETEDeleteYesNo

HTTP Status Codes

RangeKey codes
2xx Success200 OK · 201 Created · 204 No Content
3xx Redirect301 Moved Permanently · 302 Found · 304 Not Modified
4xx Client Error400 Bad Request · 401 Unauthorized · 403 Forbidden · 404 Not Found · 409 Conflict · 422 Unprocessable · 429 Too Many Requests
5xx Server Error500 Internal Server Error · 502 Bad Gateway · 503 Unavailable · 504 Gateway Timeout

DNS Record Types

A       → IPv4 address          (example.com → 93.184.216.34)
AAAA    → IPv6 address
CNAME   → Alias to another hostname  (www → example.com)
MX      → Mail exchange server
TXT     → Arbitrary text  (SPF, DKIM, domain verification)
NS      → Nameserver for the domain

// Resolution order:
// 1. Browser cache → 2. OS /etc/hosts → 3. Recursive resolver
// → 4. Root NS → 5. TLD NS (.com) → 6. Authoritative NS → IP

Common Ports

PortProtocolTransport
22SSHTCP
53DNSUDP (TCP for zone transfers)
80HTTPTCP
443HTTPSTCP
3306MySQLTCP
5432PostgreSQLTCP
6379RedisTCP

TLS Handshake (Simplified)

// TLS 1.3
Client → Server:  ClientHello  (cipher suites, key share)
Server → Client:  ServerHello  (chosen cipher, key share, certificate)
Client:           Verify certificate against trusted CAs
Client → Server:  Finished  (encrypted with shared secret derived via ECDHE)
Server → Client:  Finished
// All subsequent data encrypted with symmetric key

// Guarantees:
// Confidentiality — encrypted
// Integrity       — tamper detection (HMAC / AEAD)
// Authentication  — certificate proves server identity

Key Rules

  • Focus on layers 4 (TCP/UDP), 3 (IP), and 7 (HTTP/DNS) — layers 5 and 6 are rarely tested separately.
  • TCP = reliable + ordered + connected; UDP = fast + unreliable + connectionless.
  • HTTP is stateless — every request is independent; cookies/sessions/JWTs add state on top.
  • 401 = not authenticated (no/bad credentials); 403 = authenticated but not authorised.
  • DNS TTL: lower TTL → faster propagation but more DNS load; typical TTL = 300–3600 seconds.