Computer Networks Interview Sprint¶
Last-minute revision notes covering fundamentals, OSI/TCP-IP models, data link, network, transport, and application layers with corrected formulas and interview-ready facts.
1. Network Fundamentals¶
A computer network is a collection of interconnected devices that exchange data and share resources using communication protocols.
Objectives
- Resource sharing — files, printers, storage.
- Communication — email, messaging, video calls.
- Reliability — redundancy and alternate paths.
- Scalability — accommodate more devices and users.
- Cost efficiency — shared infrastructure.
Basic components: Sender, receiver, message, transmission medium, protocol.
1.1 Network Topologies¶
| Topology | Structure | Main Advantage | Main Disadvantage |
|---|---|---|---|
| Mesh | Every pair directly connected | High fault tolerance | Expensive |
| Bus | Shared backbone cable | Simple, inexpensive | Backbone failure affects network |
| Star | All devices connect to central hub/switch | Easy management | Central-device failure affects network |
| Ring | Each device connects to two neighbors | Orderly transmission | Link/device failure can disrupt a basic ring |
For a full mesh of N devices:
- \(\text{Links} = \frac{N(N-1)}{2}\)
In a star with N end devices, N links connect them to the central device.
1.2 Transmission Modes¶
- Simplex: One-way communication.
- Half-duplex: Both directions, but one at a time.
- Full-duplex: Both directions simultaneously.
2. OSI Model¶
The OSI model has seven layers, defined by ISO.
| Layer | Name | Role |
|---|---|---|
| 7 | Application | Network services for applications; HTTP, DNS, SMTP |
| 6 | Presentation | Data representation, encoding, encryption, compression |
| 5 | Session | Establishes, manages and terminates logical sessions |
| 4 | Transport | Process-to-process delivery, ports, reliability and flow control |
| 3 | Network | Logical addressing and routing; IP, routers |
| 2 | Data Link | Frames, MAC addresses, link-level error detection; switches |
| 1 | Physical | Transmission of raw bits, signals, cables and connectors |
Memory trick (Layer 7 → 1): All People Seem To Need Data Processing.
2.1 PDU Names¶
- Layers 7–5: Data
- Layer 4: Segment (TCP) / Datagram (UDP)
- Layer 3: Packet
- Layer 2: Frame
- Layer 1: Bits
2.2 Addressing by Layer¶
- Transport → port number
- Network → IP address
- Data Link → MAC address
2.3 Encapsulation¶
Each lower layer adds its own header (and sometimes a trailer). At the receiver, decapsulation removes them in reverse order.
3. Transmission Media¶
3.1 Guided Media¶
- Twisted pair: Inexpensive, common in LANs.
- Coaxial: Better shielding against interference; cable TV.
- Optical fiber: High bandwidth, long distance, immune to electromagnetic interference.
3.2 Unguided Media¶
- Radio waves: Wi-Fi, Bluetooth.
- Microwaves: Cellular and satellite links.
- Infrared: Short-range communication.
4. Switching Techniques¶
| Circuit Switching | Message Switching | Packet Switching |
|---|---|---|
| Dedicated path established | Entire message stored and forwarded | Message divided into packets |
| Resources reserved for session | No dedicated path | No dedicated path |
| Predictable delay after setup | Potentially high delay | Variable queuing and routing delay |
| Traditional telephone networks | Historical telegraph systems | Internet |
Key distinction: Packet switching efficiently shares network resources; packets may take different routes and arrive out of order. TCP can reorder data for the application.
5. Data Link Layer¶
Provides node-to-node delivery over a link.
Main functions:
- Framing — divides the bit stream into frames.
- Physical addressing — uses MAC addresses.
- Error control — detects errors and may support retransmission/correction.
- Flow control — prevents a sender from overwhelming a receiver.
- MAC — coordinates access to a shared medium.
5.1 Network Delay Formulas¶
| Quantity | Formula | Meaning |
|---|---|---|
| Transmission delay (Td) | L / R | Time to put all L bits onto the link |
| Propagation delay (Pd) | d / v | Signal travel time over distance d |
| RTT | Round-trip time | Time for a signal to reach the destination and a response to return |
Where L = packet/frame length in bits, R = bandwidth in bits/s, d = distance, v = propagation speed.
[!IMPORTANT] Transmission delay depends on packet size and link rate; propagation delay depends on distance and signal speed. Total delay can also include processing and queuing delays.
5.2 Flow Control and ARQ¶
ARQ (Automatic Repeat reQuest) uses acknowledgments and retransmissions to recover from lost or corrupted frames.
5.3 Stop-and-Wait ARQ¶
- Sends one frame and waits for its ACK before sending the next.
- Simple but inefficient on links with high propagation delay.
- If the ACK is lost or times out, the sender retransmits.
5.4 Go-Back-N ARQ¶
- Sender can transmit multiple frames using a sliding window.
- Receiver window size = 1 in the standard protocol.
- Uses cumulative ACKs.
- On a loss/error, retransmits the missing frame and all subsequent outstanding frames.
- For k sequence-number bits, maximum sender window = 2^k - 1.
5.5 Selective Repeat ARQ¶
- Retransmits only lost or corrupted frames.
- Receiver can buffer out-of-order frames.
- More efficient in many cases but needs more buffering and protocol complexity.
- For k sequence-number bits, maximum sender and receiver windows are each 2^(k-1).
5.6 Stop-and-Wait Efficiency¶
For a simplified, error-free link with negligible ACK transmission time and processing/queuing delays:
- \(U = \frac{Td}{Td + 2Pd} = \frac{1}{1 + 2a}, \quad \text{where } a = \frac{Pd}{Td}\)
For a sliding window of N frames, a common idealized utilization approximation is:
- \(U = \min(1, \frac{N}{1 + 2a})\)
[!NOTE] These simplified formulas assume error-free operation and negligible ACK transmission time. Actual throughput depends on ACKs, errors, frame sizes, and protocol details.
5.7 Framing Techniques¶
- Byte/character stuffing: Inserts an escape byte when a data byte would otherwise be interpreted as a frame delimiter.
- Bit stuffing: Inserts a
0after five consecutive1s in protocols such as HDLC, so data is not mistaken for a flag pattern.
6. Medium Access Control¶
6.1 Contention-Based Protocols¶
- Pure ALOHA: Transmit whenever ready; collisions are possible. Maximum theoretical throughput ≈ 18.4%.
- Slotted ALOHA: Transmit only at slot boundaries. Maximum theoretical throughput ≈ 36.8%.
- CSMA: Sense the medium before transmitting.
- CSMA/CD: Detects collisions and handles retransmission; classic shared, half-duplex Ethernet.
- CSMA/CA: Attempts to avoid collisions; used in Wi-Fi. RTS/CTS may be used but is not mandatory for every transmission.
6.2 Controlled Access Protocols¶
- Polling: A central controller invites devices to transmit.
- Token passing: Only the device holding the token may transmit.
7. Error Detection and Correction¶
-
Hamming code: Adds redundant bits for single-bit error correction. For m data bits and r redundant bits:
-
\(2^r \geq m + r + 1\)
-
CRC (Cyclic Redundancy Check): Polynomial-based error detection; particularly effective at detecting burst errors.
- Checksum: Adds a computed value that the receiver verifies to detect corruption. It is not universally more reliable than CRC.
8. Network Layer¶
Responsible for logical addressing, routing, and packet forwarding across networks.
8.1 IPv4 Addressing¶
- IPv4 address = 32 bits.
- IPv6 address = 128 bits.
- IPv4 consists of a network prefix and host portion, identified using a subnet mask or prefix length.
8.2 Classful Addressing¶
This is historical; modern networking uses CIDR.
| Class | First Octet | Default Prefix | Purpose |
|---|---|---|---|
| A | 1–126 | /8 | Large networks |
| B | 128–191 | /16 | Medium networks |
| C | 192–223 | /24 | Small networks |
| D | 224–239 | — | Multicast |
| E | 240–255 | — | Reserved/experimental |
127.0.0.0/8 is reserved for loopback.
8.3 IPv4 Datagram Header¶
| Field | Key Point |
|---|---|
| Version | 4 bits; IPv4 = 4 |
| IHL / HLEN | Header length in 32-bit words; minimum 5 = 20 bytes |
| DSCP/ECN (formerly ToS) | Service differentiation and congestion notification |
| Total Length | Header + data; 16 bits, maximum 65,535 bytes |
| Identification | Identifies fragments belonging to a datagram |
| Flags | Reserved, DF (Don't Fragment), MF (More Fragments) |
| Fragment Offset | Fragment position in units of 8 bytes |
| TTL | Decreased at each router; packet is discarded when it expires |
| Protocol | Identifies the upper-layer protocol, e.g. TCP = 6, UDP = 17 |
| Header Checksum | Detects IPv4 header corruption; recalculated at each router |
| Source/Destination IP | 32-bit addresses |
| Options | Optional fields; increase header length |
Minimum IPv4 header = 20 bytes; maximum with options = 60 bytes.
8.4 Subnetting¶
Divides a network into smaller logical networks. Benefits include better address allocation, reduced broadcast domains, and easier management.
Example: Divide 192.168.1.0/24 into 4 equal subnets.
- Borrow 2 host bits because 2^2 = 4.
- New prefix =
/26; subnet mask =255.255.255.192. - Addresses per subnet = 2^(32-26) = 64.
- Conventionally, usable host addresses = 64 - 2 = 62.
| Subnet | Network Address | Usable Host Range | Broadcast |
|---|---|---|---|
| 1 | 192.168.1.0 | .1 – .62 | .63 |
| 2 | 192.168.1.64 | .65 – .126 | .127 |
| 3 | 192.168.1.128 | .129 – .190 | .191 |
| 4 | 192.168.1.192 | .193 – .254 | .255 |
[!NOTE] The usual subtraction of two excludes the network and broadcast addresses in conventional IPv4 subnets; special cases such as /31 point-to-point links differ.
General formulas
- Number of subnets from n borrowed bits: \(2^n\)
- Addresses per subnet with prefix /p: \(2^{32-p}\)
- Conventional usable hosts: \(2^{32-p} - 2\)
8.5 CIDR, Supernetting, and VLSM¶
- CIDR: Classless Inter-Domain Routing; uses arbitrary prefix lengths such as
/20or/27. - Supernetting / route aggregation: Combines contiguous networks into a larger prefix to reduce routing-table entries.
- VLSM: Uses different subnet sizes within the same address block, reducing IP address wastage.
8.6 ICMP¶
Internet Control Message Protocol reports network-layer errors and supports diagnostics.
Common messages:
- Echo Request / Echo Reply: Used by
ping. - Destination Unreachable: Destination or service cannot be reached.
- Time Exceeded: TTL expires; used by
tracerouteimplementations.
ICMP does not make IP reliable; it reports conditions and errors.
8.7 ARP and RARP¶
- ARP: Resolves a known IPv4 address to a MAC address on the local network.
- RARP: Historically obtained an IP address from a device's MAC address; largely superseded by BOOTP and DHCP.
[!IMPORTANT] When the destination IP is outside the local subnet, a host typically resolves the default gateway's MAC address, not the remote host's MAC address.
9. Routing Algorithms¶
9.1 DVR vs LSR¶
| Distance Vector Routing (DVR) | Link State Routing (LSR) |
|---|---|
| Shares routing information with neighbors | Floods link-state information through the routing domain |
| Learns routes iteratively from neighbor information | Builds a topology database |
| Bellman–Ford-based calculation | Dijkstra's shortest-path algorithm |
| Can suffer from count-to-infinity | Avoids the classic DVR count-to-infinity problem |
| RIP is a common example | OSPF and IS-IS are examples |
Hop count: Number of routers traversed. RIP uses hop count, with 15 as the maximum usable distance; 16 means unreachable.
9.2 OSPF¶
- Link-state routing protocol.
- Uses Dijkstra's SPF algorithm.
- Metric is cost, commonly derived from bandwidth.
- Converges relatively quickly and scales better than RIP.
- DR/BDR elections occur on applicable multi-access networks.
9.3 RIP¶
- Distance-vector routing protocol.
- Uses hop count.
- UDP port 520.
- Maximum usable hop count = 15.
- Administrative distance = 120 on Cisco routers (vendor-specific).
- Commonly categorized as an application-layer routing protocol running over UDP, although it serves the network-layer routing control plane.
10. Transport Layer¶
Provides process-to-process communication between applications on different hosts.
Key functions:
- Segmentation and reassembly.
- Port-based multiplexing and demultiplexing.
- Reliability and error recovery (TCP).
- Flow control and congestion control (TCP).
10.1 TCP vs UDP¶
| Feature | TCP | UDP |
|---|---|---|
| Connection | Connection-oriented | Connectionless |
| Reliability | ACKs and retransmissions | No built-in retransmission |
| Ordering | Ordered byte stream | No ordering guarantee |
| Data model | Byte-stream | Datagram/message-oriented |
| Flow control | Yes | No built-in flow control |
| Congestion control | Yes, in standard implementations | No built-in congestion control |
| Header size | Minimum 20 bytes | 8 bytes |
| Handshake | Three-way handshake | No transport handshake |
| Typical uses | HTTP(S), SSH, email transfer | DNS, real-time media, gaming |
[!TIP] Interview points: - TCP guarantees an ordered byte stream, not preservation of application message boundaries. - UDP is not inherently faster in every situation; it has less built-in protocol overhead. - UDP applications may implement their own reliability, ordering, and congestion control. - UDP checksum is optional in IPv4, but mandatory in IPv6 (with limited exceptions).
10.2 TCP Header¶
Minimum header = 20 bytes, excluding options.
Important fields: Source and destination ports, sequence number, acknowledgment number, header length and flags (SYN, ACK, FIN, RST, etc.), window size, checksum, urgent pointer, and optional fields.
10.3 TCP Three-Way Handshake¶
Client → Server: SYN, sequence number = x
Server → Client: SYN + ACK, sequence = y, ACK = x + 1
Client → Server: ACK = y + 1
Why three steps? Both sides synchronize initial sequence numbers and confirm that communication works in both directions.
10.4 TCP Connection Termination¶
- Normally uses a four-segment exchange:
FIN → ACK → FIN → ACK. - Each direction can close independently; TCP supports half-close.
FINrepresents graceful closure.RSTresets a connection abruptly.
10.5 TCP Congestion Control¶
- Slow Start: Congestion window (
cwnd) grows exponentially, approximately doubling each RTT under typical ACK behavior. - Congestion Avoidance:
cwndgrows approximately linearly, commonly by about 1 MSS per RTT. - Congestion detected: TCP reduces its sending window; the response depends on the congestion-control algorithm and the type of loss signal.
[!IMPORTANT] Flow control protects the receiver; congestion control protects the network. The sender's effective limit is constrained by both the receiver's advertised window (
rwnd) and the congestion window (cwnd).
11. Upper Layers¶
11.1 Session Layer¶
- Establishes, manages, and terminates logical sessions.
- Supports dialog control and synchronization/checkpoints.
- A checkpoint can allow a long operation to resume from a known point when the application protocol supports it.
11.2 Presentation Layer¶
- Data representation and format conversion.
- Character encoding, e.g. ASCII and Unicode/UTF-8.
- Encryption/decryption and compression/decompression as conceptual presentation-layer functions.
Compression examples:
- Lossless: ZIP, PNG.
- Lossy: JPEG, MP3.
[!NOTE] In real Internet implementations, these functions are often handled by applications and libraries rather than distinct OSI layers. TLS, for example, is not literally a separate OSI Presentation Layer protocol in the TCP/IP stack.
11.3 Application Layer¶
Provides network services used by applications:
- Web browsing and web APIs.
- Email.
- File transfer.
- Remote login.
- Name resolution.
- Client-server communication.
The Application Layer provides services to software; it is not simply the graphical user interface.
12. TCP/IP Model¶
The four-layer TCP/IP model is the practical model underlying Internet communication.
| TCP/IP Layer | Corresponding OSI Layers | Examples |
|---|---|---|
| Application | Application, Presentation, Session | HTTP, DNS, SMTP, SSH |
| Transport | Transport | TCP, UDP |
| Internet | Network | IP, ICMP |
| Network Access / Link | Data Link, Physical | Ethernet, Wi-Fi |
12.1 OSI vs TCP/IP¶
| OSI | TCP/IP |
|---|---|
| 7 layers | Commonly represented as 4 layers |
| Reference model developed by ISO | Internet protocol suite associated with DARPA/DoD research |
| Separates Session and Presentation layers | Includes their functions in Application |
| Separates Data Link and Physical layers | Combines them in Network Access/Link |
| Protocol-independent reference model | Based on actual Internet protocols |
[!IMPORTANT] TCP/IP supports both TCP and UDP at the transport layer. IP itself is connectionless, but that does not mean every TCP/IP service is connectionless.
12.2 Encapsulation Example¶
When a browser sends an HTTPS request:
- Application creates HTTP data.
- TCP adds its header, producing a TCP segment.
- IP adds its header, producing an IP packet.
- Ethernet or Wi-Fi encapsulates it into a frame.
- The physical medium carries the bits.
At each router, the link-layer frame is replaced for the next link; the IP packet is forwarded toward the destination.
13. Protocols and Port Numbers¶
| Protocol | Port | Purpose |
|---|---|---|
| HTTP | TCP 80 | Web communication |
| HTTPS | TCP 443 | Secure web communication using TLS |
| FTP | TCP 21 control, 20 active-mode data | File transfer |
| SSH | TCP 22 | Secure remote login |
| Telnet | TCP 23 | Unencrypted remote login |
| SMTP | TCP 25 | Email transfer between mail servers |
| DNS | UDP/TCP 53 | Domain name resolution |
| DHCP | UDP 67 server, 68 client | Automatic IP configuration |
| TFTP | UDP 69 | Simple file transfer |
| POP3 | TCP 110 | Email retrieval |
| NTP | UDP 123 | Time synchronization |
| IMAP | TCP 143 | Email access and synchronization |
| SNMP | UDP 161/162 | Network monitoring and notifications |
| BGP | TCP 179 | Inter-domain routing |
| RIP | UDP 520 | Distance-vector routing |
[!WARNING] Common interview traps: - DNS normally uses UDP, but also uses TCP when required, including zone transfers and some large responses. - HTTPS is HTTP secured using TLS; port 443 is the default, not the only possible port. - SMTP is primarily for sending/relaying email; IMAP and POP3 are used for retrieval. - DHCP assigns IP configuration, including the IP address, subnet mask, default gateway and DNS servers.
14. Network Devices¶
| Device | Main Function | Typical Layer |
|---|---|---|
| Repeater | Regenerates/retimes signals | Physical |
| Hub | Repeats incoming bits to all ports | Physical |
| Bridge | Connects LAN segments and filters frames using MAC addresses | Data Link |
| Switch | Forwards frames using a MAC address table | Data Link |
| Router | Forwards IP packets between networks | Network |
| Gateway | Connects systems/networks using different protocols or architectures | Multiple |
| Modem | Modulates/demodulates signals for a transmission technology | Depends on implementation |
| Wireless AP | Connects wireless clients to a LAN | Mainly Data Link |
| Firewall | Filters traffic based on security rules | Network through Application |
14.1 Hub vs Switch vs Router¶
- Hub: Sends incoming signals to all other ports; no MAC learning.
- Switch: Learns source MAC addresses and forwards frames to the appropriate port.
- Router: Uses destination IP addresses and routing tables to forward packets between networks.
A Layer 2 switch forwards based on MAC addresses; a Layer 3 switch can also perform routing.
15. Formula and Fact Sheet¶
Use this section for a quick glance immediately before an interview.
15.1 Formulas¶
- Full mesh links: \(\frac{N(N-1)}{2}\)
- Transmission delay: \(Td = \frac{\text{Packet length (bits)}}{\text{Bandwidth (bits/s)}}\)
- Propagation delay: \(Pd = \frac{\text{Distance}}{\text{Propagation speed}}\)
- Number of subnets (n borrowed): \(2^n\)
- IPv4 addresses per subnet (/p): \(2^{32-p}\)
- Hamming redundant bits: \(2^r \geq m + r + 1\)
- Go-Back-N max sender window: \(2^k - 1\)
- Selective Repeat max window: \(2^{k-1}\)
- Stop-and-Wait efficiency: \(U = \frac{1}{1 + 2a}, \quad a = \frac{Pd}{Td}\)
- Sliding window efficiency: \(U = \min(1, \frac{N}{1 + 2a})\)
15.2 Facts to Memorize¶
- IPv4: 32 bits; IPv6: 128 bits.
- MAC address: commonly 48 bits.
- Minimum IPv4 header: 20 bytes.
- Minimum TCP header: 20 bytes.
- UDP header: 8 bytes.
- TCP handshake: SYN → SYN-ACK → ACK.
- RIP: UDP port 520, maximum usable hop count 15.
- OSPF: link-state, Dijkstra, cost metric.
- DVR: Bellman–Ford; can suffer count-to-infinity.
- ARP: IPv4 address → MAC address on a local network.
- ICMP: diagnostics and network error reporting.
- CSMA/CD: classic shared Ethernet; CSMA/CA: Wi-Fi.
- Flow control protects the receiver; congestion control protects the network.
- Subnetting divides networks; supernetting aggregates networks; VLSM allows different subnet sizes.
16. Assessment of Original Notes¶
Revision priority: OSI/TCP-IP → TCP vs UDP and handshake → subnetting → ARQ and delay formulas → routing algorithms → protocols and ports → MAC and error control.
Key corrections incorporated above:
- Correct TCP/IP vs OSI comparisons.
- Correct Selective Repeat window size and ARQ behavior.
- Correct CRC/checksum claims and framing details.
- Correct interpretation of TCP congestion control and its windows.
- Correct subnet ranges and IPv4 header terminology.
- Clarify ARP, RIP, ICMP, and the practical roles of OSI layers.