Vault Notes

Computer Networks

Subject 1 of 10 ยท from the OSI model to network security, with the tables and formulas that actually matter.

1. Network Basics & the OSI Model

The OSI (Open Systems Interconnection) model is a conceptual framework that standardizes how network communication is designed. It splits communication into seven distinct layers. Each layer provides services to the layer above it and receives services from the layer below. These layers form the foundation for understanding how data moves through networks, from raw physical signals up to application-level messages.

The seven layers

LayerNameFunction
7ApplicationUser interface, apps โ€” the services users touch directly
6PresentationData formatting, encryption, compression
5SessionConnection setup, management, teardown between apps
4TransportReliable end-to-end data delivery
3NetworkRouting and logical addressing
2Data LinkFrame formatting, node-to-node delivery
1PhysicalElectrical / optical signals, raw bits

Two groups of layers

Data flows down the stack when sending and up the stack when receiving. The key benefit of the whole scheme is interoperability: equipment from different manufacturers can talk to each other because everyone standardizes against the same layer boundaries.

2. Network Topologies

Wireless networks are classified by their infrastructure.

Infrastructure mode

Ad hoc networks

Infrastructure-less communication: no central base station, no wired backbone. Every node can act as both client and router, talking directly device-to-device.

Remember

Infrastructure mode = centralized control. Ad hoc = peer to peer.

3. Physical Layer

The Physical Layer sits at the very bottom of the OSI model. It handles the actual transmission of raw bits over the physical medium: managing the physical connection between devices, controlling how bits are pushed through cables, and converting raw bits into signals.

Key specifications

SpecWhat it defines
ElectricalVoltage levels representing binary 1 and 0
MechanicalPhysical connectors, pin configurations, cable specs
TimingSignal duration, synchronization between sender and receiver
BandwidthData transmission rate, maximum channel capacity

Transmission media

Signal characteristics define how long each bit is transmitted (bit duration = 1 / bandwidth) and the signaling method used (NRZ, Manchester, and friends).

Note

The Physical Layer doesn't understand data meaning. It only knows how to push bits from one point to another. All the intelligence lives at higher layers.

4. Data Link Layer

The Data Link Layer (Layer 2) manages reliable transmission between directly connected nodes. Its jobs: framing, error detection, flow control, and mediating access to a shared medium.

Framing

Framing converts packets from the Network Layer into frames by adding a header and a trailer. Each frame carries a header with control information (like MAC addresses), the data payload, and a trailer with error-detection codes.

The fundamental problem framing solves

Where does one frame end and another begin in a continuous bit stream?

Error detection

An error-detection code is computed for each frame. The common methods:

The receiver extracts frames from the bit stream, verifies integrity with the code, and requests retransmission if errors are found.

Ethernet (IEEE 802.3)

Ethernet defines both physical and data-link behavior for LANs. It is connectionless (no setup before sending) and best-effort (no acknowledgments, flow control, or error recovery at this layer). Classic Ethernet used a shared bus with CSMA/CD for medium access.

FieldSize (bytes)Content
Preamble71010โ€ฆ10 โ€” synchronizes the receiver clock
SFD110101011 โ€” Start Frame Delimiter, marks the real frame start
Destination MAC6Who the frame is for
Source MAC6Who sent it
Length2Size of the data field in bytes
Data46โ€“1500Actual payload (padded to 46 bytes minimum)
CRC432-bit error-detection code

Frame size limits

CSMA/CD performance

Slot time โ€” the worst-case round trip for a collision signalslot time = 2 ร— propagation delay
Channel utilization under contentionU = 1 / (1 + 5a)    where  a = Tprop / Ttrans = (d/v) / (L/R)
d = cable length, v = signal speed, L = frame length in bits, R = bandwidth in bps

Key insight: longer frames improve efficiency by shrinking the relative cost of collision overhead. When N stations compete, the probability that exactly one transmits successfully in a slot is P = Nยทpยท(1โˆ’p)Nโˆ’1, and the average contention period before success is k ร— 2ฯ„ where k = 1/p.

Modern reality

Switched, full-duplex Ethernet eliminated collisions entirely, so CSMA/CD is legacy. It still matters for exams and for understanding shared-medium behavior.

ARP โ€” Address Resolution Protocol

ARP maps IP addresses to MAC addresses when a device needs to talk on its local network. A device knows the destination IP but needs the MAC to build the frame.

Four use cases: host-to-host on the same network, host-to-router (needs the router's MAC), router-to-router (next-hop MAC), router-to-host (final delivery).

RARP and its successors

RARP did the reverse: given only a MAC address, get an IP (for diskless workstations). It needed a dedicated RARP server per segment and its broadcasts couldn't cross routers โ€” a scaling dead end. BOOTP extended the idea, and DHCP eventually replaced RARP entirely.

5. Flow Control & ARQ Protocols

Flow control regulates how fast a sender transmits so it never overwhelms the receiver. The classic family is ARQ โ€” Automatic Repeat reQuest.

Stop-and-Wait ARQ

The sender transmits one frame, then waits for its acknowledgment before sending the next. Simple, but the channel sits idle most of the time.

Efficiencyฮท = 1 / (1 + 2a)    where  a = Tprop / Ttrans

On a satellite link with 270 ms propagation delay and 1 ms transmission time, ฮท โ‰ˆ 1/(1+540) โ‰ˆ 0.0018 โ€” under 0.2% utilization. Stop-and-wait collapses wherever bandwidth is high or distance is long.

Go-Back-N ARQ

A sliding-window protocol: the sender may have up to N frames unacknowledged. The receiver only accepts in-order frames (receiver window = 1) and sends cumulative ACKs.

Efficiencyฮท = N / (1 + 2a)

Selective Repeat ARQ

The efficient sibling: the receiver buffers out-of-order frames and the sender retransmits only the lost or corrupted ones. Each frame gets its own ACK. Maximum window is 2^(Nโˆ’1) for N-bit sequence numbers.

Efficiency / throughputฮท = N / (1 + 2a)    ยท    Throughput = (N ร— L) / (Tt + 2Tp)

Sliding window, summarized

ProtocolSender windowReceiver windowOn loss
Stop-and-Wait11Resend the one frame
Go-Back-NN1Resend all from the lost frame onward
Selective RepeatNNResend only the lost frame

6. MAC Sublayer & Wireless LANs

CSMA/CA โ€” why wireless can't use CSMA/CD

On a wire, a station can listen while transmitting and detect collisions. On radio it can't โ€” its own transmission drowns out everything else. Two extra problems appear:

So 802.11 uses CSMA/CA (collision avoidance): listen first, then reserve the channel with an RTS/CTS handshake before sending data. Timing gaps keep things orderly: SIFS (short, for immediate responses like ACK/CTS) and DIFS (longer, before contending for the channel).

ModeConnection
InfrastructureVia base station (access point)
Ad hocDevice to device, no AP

802.11 standards

StandardFrequency bandMax data rate
802.11 (1997)2.4 GHz2 Mbps
802.11a5 GHz54 Mbps
802.11b2.4 GHz11 Mbps
802.11g2.4 GHz54 Mbps
802.11n2.4 / 5 GHzup to 600 Mbps

Joining a network: scanning

802.11 frame structure

FieldSizeNotes
Frame Control2 bytesType, subtype, flags (below)
Duration / ID2 bytesChannel reservation time
Address 1โ€“36 bytes eachReceiver, transmitter, BSSID/filtering addr
Sequence Control2 bytesFragment/sequence numbers
Address 46 bytesOnly in wireless distribution (AP-to-AP)
Frame Body0โ€“2312 bytesThe payload
FCS4 bytesFrame check sequence

Frame Control subfields (16 bits)

FieldBitsPurpose
Protocol Version2Always 0 so far
Type2Management / Control / Data
Subtype4e.g. beacon, RTS, CTS, ACK
To DS / From DS1 + 1Direction relative to the distribution system
More Fragments1More fragments of this frame follow
Retry1This is a retransmission
Power Management1Station entering power-save
More Data1AP has buffered frames for this station
Protected (WEP)1Frame is encrypted
Order1Strict ordering requested

Token Ring (IEEE 802.5)

A deterministic LAN: stations sit on a ring and take turns transmitting by passing a small token frame. No collisions, ever โ€” you can only send while holding the token. A station may hold it for at most the Token Holding Time (THT), and priority levels (0โ€“7) let urgent traffic jump the queue. A dedicated monitor station keeps ring timing healthy and regenerates lost tokens.

Ring speedMax ring length
4 Mbps1000 m
16 Mbps500 m

Higher speeds need shorter rings to keep signal quality up. Token frame: SD (1 byte) + AC (1 byte) + ED (1 byte).

AspectToken RingEthernet (classic)
Medium accessToken passing โ€” deterministicCSMA/CD โ€” probabilistic
CollisionsNone by designDetected and retried
EfficiencyStays high under heavy loadDegrades as contention rises
ReliabilityHigher โ€” bounded access delayLower โ€” unbounded backoff
Best atSustained heavy loadLight, bursty load

7. Network Layer & IP Addressing

The Network Layer (Layer 3) handles logical addressing and routing: assigning IP addresses, picking the best path, forwarding packets through routers, and fragmenting/reassembling packets that exceed a link's MTU.

Delivery types

IPv4 address classes

ClassRangeLeading bitsUse
A0 โ€“ 1270xxx xxxxHuge networks (224 hosts each)
B128 โ€“ 19110xx xxxxMedium networks (216 hosts)
C192 โ€“ 223110x xxxxSmall networks (254 hosts)
D224 โ€“ 2391110 xxxxMulticast
E240 โ€“ 2551111 xxxxExperimental / reserved

Special addresses worth memorizing: 0.0.0.0 (this network), 127.0.0.1 (loopback), 255.255.255.255 (limited broadcast), and the private ranges 10/8, 172.16/12, 192.168/16.

Subnetting

Subnetting borrows host bits to carve one network into smaller ones. A subnet mask (e.g. 255.255.255.0, or /24) splits the address into network + host portions. Benefits: less broadcast traffic, better address use, simpler routing through aggregation.

IPv4 header

FieldSizePurpose
Version4 bits4 for IPv4
IHL4 bitsHeader length in 32-bit words
Type of Service8 bitsQoS / priority hints
Total Length16 bitsWhole datagram in bytes
Identification16 bitsGroups fragments of one datagram
Flags3 bitsDon't-fragment / more-fragments
Fragment Offset13 bitsPosition of this fragment
TTL8 bitsHop countdown โ€” kills routing loops
Protocol8 bitsWhat rides inside: 6 = TCP, 17 = UDP
Header Checksum16 bitsHeader integrity only
Source / Dest Address32 bits eachEndpoints
Options + PaddingvariableRarely used extras

IPv6 basics

128-bit addresses, written as eight hex groups (2001:db8::1), give ~3.4ร—1038 addresses. The header is fixed at 40 bytes and simpler than IPv4's: no checksum (left to lower layers), no fragmentation fields (only the source fragments).

FieldSize
Version4 bits
Traffic Class8 bits
Flow Label20 bits
Payload Length16 bits
Next Header8 bits
Hop Limit8 bits
Source Address128 bits
Destination Address128 bits

IPv6 Next Header values

ValueHeader
0Hop-by-Hop Options
6TCP
17UDP
41Encapsulated IPv6
43Routing Header
44Fragment Header
50ESP (encrypted payload)
51AH (authentication header)
58ICMPv6
59No Next Header
60Destination Options

ICMP

The Internet Control Message Protocol is IP's error-reporting sidekick: destination-unreachable, time-exceeded (that's what traceroute exploits), echo request/reply (ping). It reports problems; it doesn't fix them.

8. Routing Algorithms

Distance Vector (RIP)

Each router keeps a vector of (destination, distance) and periodically shares it with neighbors. Bellman-Ford underneath. Simple, but slow to converge โ€” and infamous for the count-to-infinity problem when a link dies. Fixes: split horizon, poison reverse, holddown timers.

Link State (OSPF)

Each router learns the full topology, then runs Dijkstra locally. The five steps:

  1. Discover neighbors, learn their network addresses
  2. Measure the cost (delay) to each neighbor
  3. Bundle it into a link-state packet
  4. Flood the packet to all routers
  5. Compute the shortest path tree to every destination

Fast convergence, hierarchical areas to keep large networks manageable.

Path Vector (BGP)

The protocol of the internet backbone: inter-autonomous-system routing. Instead of raw distances, routers exchange full paths, which kills count-to-infinity and lets operators enforce policy ("don't route through AS X").

9. Transport Layer

The Transport Layer manages reliable data delivery between applications on different hosts: segmentation, port-based addressing, connection control, flow control, error control, and congestion control. It delivers end-to-end reliability regardless of what the network underneath does.

TCP โ€” Transmission Control Protocol

TCP is connection-oriented and reliable: a byte stream with acknowledgments and retransmissions. Connections are point-to-point, with a sliding window for flow control.

FieldSize (bits)
Source Port16
Destination Port16
Sequence Number32
Acknowledgment Number32
Header Length4
Reserved6
Control Flags6
Window Size16
Checksum16
Urgent Pointer16
Optionsvariable

Control flags: SYN, ACK, FIN, RST, PSH, URG.

Well-known TCP ports

ProtocolPortPurpose
HTTP80Web browsing
HTTPS443Secure web
FTP21File transfer (control)
SSH22Secure remote terminal
SMTP25Sending email
DNS53Domain name resolution

TCP congestion control

Congestion control keeps the network from collapsing under load, balancing efficiency with fairness. The classic algorithm has four phases:

TCP also runs four timers: retransmission (resend unacked segments), persist (probe a zero-window receiver), keepalive (check idle connections), and time-wait (linger after close so late duplicates die).

UDP โ€” User Datagram Protocol

UDP is connectionless and unreliable โ€” no handshake, no ordering, no flow or congestion control. What it buys is speed and simplicity: message-oriented datagrams with an 8-byte header.

UDP header (8 bytes)
Source Port (16 bits)Destination Port (16 bits)
Length (16 bits)Checksum (16 bits, optional)
FeatureUDPTCP
ConnectionConnectionlessConnection-oriented
ReliabilityUnreliableReliable
SpeedFasterSlower
Use casesStreaming, gaming, DNSWeb, email, file transfer

Well-known UDP ports: DNS 53, DHCP 67/68, TFTP 69, SNMP 161, RIP 520.

10. Application Layer

The top of the stack: network services delivered directly to end-user applications โ€” file transfer, email, web access, directory services. These are the protocols users actually touch.

OSI layerPrimary protocols
ApplicationHTTP, FTP, SMTP, DNS
PresentationTLS, SSL, MIME
SessionNetBIOS, PPTP, RDP
TransportTCP, UDP, SCTP
NetworkIP, ICMP, ICMPv6
Data LinkEthernet, Wi-Fi (802.11)
PhysicalHubs, repeaters, cabling

DNS โ€” Domain Name System

Translates human-readable names into IP addresses so nobody memorizes numbers. A hierarchical distributed database: root servers โ†’ TLD servers โ†’ authoritative servers. A lookup for example.com goes: local cache โ†’ root โ†’ .com TLD โ†’ authoritative server โ†’ IP back to you. Runs on UDP port 53 (TCP for zone transfers and large responses), with caching at every level.

BOOTP & DHCP

BOOTP let diskless workstations boot: broadcast a request with your MAC, get back an IP configuration. Static mappings, one server per network (relays forward across networks).

DHCP extends BOOTP with dynamic, leased addresses from a pool โ€” the reason your phone just works on any Wi-Fi. The four-step dance (DORA):

  1. Discover โ€” client broadcasts "any DHCP server out there?"
  2. Offer โ€” server(s) respond with a proposed address
  3. Request โ€” client picks one and asks for it
  4. ACK โ€” server confirms, lease timer starts

HTTP โ€” Hyper Text Transfer Protocol

The web's protocol: application-layer, client-server, running over TCP port 80. Stateless โ€” each request stands alone (cookies and sessions are layered on top, not part of HTTP itself).

HTTP methods

MethodWhat it does
GETRetrieve data from the server
POSTSubmit data to the server
PUTReplace / update a resource
DELETERemove a resource
HEADHeaders only, no body
OPTIONSAsk what methods a resource supports
TRACEEcho the request back for debugging
CONNECTOpen a tunnel (how HTTPS proxies work)

HTTP connection types

TypeBehavior
Non-persistentA new TCP connection per request
PersistentOne TCP connection reused for many requests
PipeliningSend multiple requests without waiting for responses

FTP โ€” File Transfer Protocol

Runs over TCP with two connections: port 21 carries commands and responses (control), port 20 carries the actual file data. Two modes for opening the data connection:

Relatives: TFTP (trivial FTP, port 69 โ€” no authentication, tiny, used for booting devices) and SFTP (FTP tunneled over SSH, port 22 โ€” not to be confused with FTPS, which is FTP over TLS).

SMTP, POP3, IMAP โ€” email

SMTP (port 25, submission on 587) only sends mail โ€” pushing messages between servers. MIME extends it to attachments and non-ASCII text. Reading mail is a different job:

FeaturePOP3 (port 110)IMAP (port 143)
StorageLocal deviceServer
AccessDownload, then usually delete from serverSync โ€” mail stays on server
Multi-devicePoorExcellent
Server storageMinimalHigh

This is why your phone, laptop, and webmail all show the same inbox: IMAP.

SSH โ€” Secure Shell

Encrypted remote login and command execution on port 22 โ€” the replacement for plaintext Telnet. Handles session management, strong authentication, and full encryption of everything in the session. Also the transport under SFTP and Git-over-SSH.

11. Network Security

Cryptography basics

Rule of thumb

The strength of cryptography depends on the key, not on keeping the algorithm secret.

Types of cryptography

TypeHow it worksExamples
SymmetricOne shared key encrypts and decryptsDES, AES
AsymmetricPublic key encrypts, private key decryptsRSA, Diffie-Hellman
Hash functionsOne-way digest โ€” integrity, not secrecyMD5, SHA-1, SHA-256

Common hash algorithms

AlgorithmDigest sizeNotes
MD2128 bitsOldest, obsolete
MD4128 bitsFast, but broken
MD5128 bitsEnhanced MD4 โ€” collision-broken, avoid
SHA-1160 bitsFive 32-bit words from 512-bit blocks โ€” deprecated
SHA-256256 bitsCurrent safe default

MACs and digital signatures

Performance note

For long messages, symmetric cryptography is far more efficient than asymmetric โ€” so real systems mix them: asymmetric to exchange a key, symmetric for the bulk data.

Eavesdropping

A passive attack: the attacker taps transmission lines and silently captures packets โ€” no modification, so it leaves no trace. On a shared Ethernet segment, sniffing tools can harvest passwords, emails, and file transfers sent in plaintext. Targets: serial lines, Ethernet traffic, wireless transmissions, and any unencrypted protocol (HTTP, Telnet, FTP). Defense: encrypt everything in transit (HTTPS, SSH, VPN) and physically secure the infrastructure.

Firewalls, DoS & DDoS

Firewalls filter traffic at network boundaries by rules โ€” what gets in, what stays out.

A Denial-of-Service attack targets availability, not data: flood the target with traffic, burn its CPU/memory/bandwidth, and legitimate requests starve. A Distributed DoS coordinates thousands of compromised machines (a botnet) at once โ€” far harder to block, since there's no single source to filter. A botnet of 1000 machines each sending 100 requests/second is 100,000 requests/second โ€” enough to flatten most web servers.

Common vectors: TCP SYN floods, UDP floods, HTTP request flooding, resource exhaustion (memory, disk). Defenses: rate limiting, traffic filtering, load balancing across servers, dedicated DDoS protection services.

Distinction

Unlike attacks that steal data, DoS is purely about disrupting service availability.

โ† Back to all subjects