Getting everything ready for you…

Loading courses, problems and your progress. This takes just a moment.

0s

Computer Networks Documentation

Networking on one page — OSI and TCP/IP, ports, TCP vs UDP, subnetting formulas, DNS, HTTP status codes, routing and devices.

Networking on one page: the layer models, protocols and their ports, TCP vs UDP, IP addressing and subnetting formulas, HTTP, DNS and the devices — the facts you need for interviews and exams. Detailed explanations live in the linked notes.

1. Layer Models

# OSI layer Job Protocols Data unit Device
7 Application Services for apps HTTP(S), DNS, SMTP, FTP, SSH Data —
6 Presentation Format, encryption, compression TLS, JPEG, UTF-8 Data —
5 Session Open/manage sessions RPC, NetBIOS Data —
4 Transport Process-to-process, ports, reliability TCP, UDP Segment / datagram L4 firewall / LB
3 Network Logical addressing, routing IP, ICMP, OSPF, BGP Packet Router
2 Data link Node-to-node, MAC, error detection Ethernet, Wi-Fi, PPP, ARP* Frame Switch, bridge
1 Physical Bits on the medium Cables, radio Bits Hub, repeater

TCP/IP model: Application (5–7) · Transport (4) · Internet (3) · Network access (1–2). Mnemonic (top→bottom): All People Seem To Need Data Processing. Details: OSI and TCP/IP Models.

2. Common Ports

Port Protocol Port Protocol
20/21 FTP 110 POP3
22 SSH / SFTP 143 IMAP
23 Telnet 443 HTTPS
25 SMTP 3306 MySQL
53 DNS 5432 PostgreSQL
67/68 DHCP 6379 Redis
80 HTTP 27017 MongoDB

Well-known 0–1023 · registered 1024–49151 · dynamic/ephemeral 49152–65535. More in Network Devices and Common Ports.

3. TCP vs UDP

TCP UDP
Connection Yes (3-way handshake) No
Reliability ACKs, retransmission, ordering Best effort
Header 20–60 bytes 8 bytes
Flow / congestion control Yes No
Used by HTTP/1.1–2, SSH, SMTP, FTP, DBs DNS, video calls, games, VoIP, DHCP, QUIC
Handshake:  SYN → SYN-ACK → ACK
Teardown:   FIN → ACK → FIN → ACK  (then TIME_WAIT = 2 × MSL)
Flow control: receiver window (rwnd)
Congestion control: slow start (×2 per RTT) → congestion avoidance (+1) → on loss halve (AIMD)

Details: TCP vs UDP and the 3-Way Handshake.

4. IPv4 Addressing

Class First octet Default mask Use
A 1–126 /8 Very large networks
B 128–191 /16 Medium
C 192–223 /24 Small
D 224–239 — Multicast
E 240–255 — Experimental

Private ranges: 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16. Loopback 127.0.0.0/8. APIPA 169.254.0.0/16.

5. Subnetting Formulas

Usable hosts per subnet = 2^(32 − prefix) − 2
Number of subnets when borrowing b bits = 2^b
Block size = 256 − mask value in the interesting octet
Network address = largest multiple of block size ≤ the IP's octet
Broadcast = next network − 1
Prefix Mask Hosts
/24 255.255.255.0 254
/25 .128 126
/26 .192 62
/27 .224 30
/28 .240 14
/29 .248 6
/30 .252 2

Example: 192.168.10.75/26 → block 64 → network .64, broadcast .127, hosts .65–.126. More solved problems: IP Addressing and Subnetting.

6. IPv6

  • 128-bit, written in hex groups: 2001:db8::ff00:42:8329 (drop leading zeros; one run of zero groups → ::).
  • No broadcast (multicast instead), no NAT needed, auto-configuration (SLAAC), loopback ::1.

7. Supporting Protocols

Protocol What it does
ARP IP → MAC on the local network
DHCP Gives a device IP, mask, gateway, DNS — DORA: Discover, Offer, Request, Ack
NAT / PAT Many private IPs share one public IP (ports keep connections apart)
ICMP Errors and diagnostics — ping, traceroute
DNS Names → IP addresses

8. DNS

Lookup order: browser cache → OS cache / hosts file → resolver (ISP / 8.8.8.8 / 1.1.1.1)
Resolver asks: root → TLD (.com) → authoritative server → answer cached for its TTL
Record Holds
A / AAAA IPv4 / IPv6 address
CNAME Alias to another name
MX Mail server
NS Name servers for the domain
TXT Verification, SPF/DKIM

Details: DNS — The Internet's Phone Book.

9. HTTP and HTTPS

Method Use Idempotent
GET Read Yes
POST Create No
PUT Replace Yes
PATCH Partial update Not necessarily
DELETE Remove Yes

Status codes: 2xx success (200 OK, 201 Created, 204 No Content) · 3xx redirect (301 permanent, 302/307 temporary, 304 not modified) · 4xx client error (400, 401 unauthenticated, 403 forbidden, 404, 429 too many requests) · 5xx server error (500, 502 bad gateway, 503 unavailable, 504 timeout).

Versions: HTTP/1.1 (keep-alive) → HTTP/2 (multiplexing, header compression, one TCP connection) → HTTP/3 (over QUIC/UDP, no head-of-line blocking).

HTTPS = HTTP over TLS: certificate check + key exchange → symmetric encryption. Details: HTTP and HTTPS.

10. Routing

Type Examples
Static Routes set by hand
Distance vector RIP (hop count, Bellman-Ford)
Link state OSPF (Dijkstra on the full map)
Path vector (between ISPs) BGP

Longest prefix match decides which route a packet takes. Details: Routing and the Network Layer.

11. Devices

Device Layer Works with
Hub / repeater 1 Bits — sends to all ports
Switch / bridge 2 MAC addresses
Router 3 IP addresses, connects networks
Firewall 3–7 Filters traffic by rules
Load balancer 4 or 7 Spreads requests across servers
Proxy / reverse proxy 7 Forwards requests for clients / servers

Collision domain: each switch port is its own; a hub is one. Broadcast domain: a router (or VLAN) separates them.

12. Commands

ping google.com            # reachability (ICMP)
traceroute google.com      # path (tracert on Windows)
nslookup / dig google.com  # DNS lookup
ipconfig / ip addr         # your IP configuration
netstat -tulpn / ss -tulpn # open ports and connections
curl -I https://site.com   # HTTP headers

13. Interview Favourites

Question Where
What happens when you type a URL? Full walkthrough
Why does DNS use UDP? One small request/response; TCP for large answers
Why a 3-way (not 2-way) handshake? Both sides confirm each other's sequence numbers
Switch vs router? MAC within a network vs IP between networks
HTTP vs HTTPS? Plain text vs TLS-encrypted with a verified certificate
TCP vs UDP for video calls? UDP — late data is useless, speed matters

14. Cheat Sheet & References

Layers

7 Application · 6 Presentation · 5 Session · 4 Transport · 3 Network · 2 Data link · 1 Physical
Units: data → segment → packet → frame → bits
Devices: hub L1 · switch L2 · router L3

Numbers

Hosts = 2^(32 − prefix) − 2       Block = 256 − mask octet
Private: 10/8 · 172.16/12 · 192.168/16
Ports: 22 SSH · 25 SMTP · 53 DNS · 80 HTTP · 443 HTTPS · 3306 MySQL
TCP header 20–60 B · UDP header 8 B

Protocol flow

URL → DNS (UDP 53) → TCP handshake → TLS → HTTP request → response → render
DHCP: Discover → Offer → Request → Ack
TCP open: SYN, SYN-ACK, ACK · close: FIN, ACK, FIN, ACK

References