Computer Networks
Learn how computers communicate over networks, from basic networking concepts and protocols to IP addressing, routing, TCP/UDP, HTTP/HTTPS, DNS, and network security fundamentals.

Introduction
A computer network is a system of interconnected devices, such as computers, servers, smartphones, and printers, that communicate to exchange data. They communicate using wired or wireless connections and can range from small home networks to the global Internet. 1. Resource Sharing: Allows sharing of hardware like printers, scanners, and storage devices, reducing cost. 2. Data Sharing: Enables users to share files, applications, and databases easily. 3. Communication: Supports email, video conferencing, instant messaging, and web access. 4. Data Management: Helps in storing, securing, and backing up data efficiently. 5. Remote Access: Allows users to access systems and cloud services from anywhere. 6. Better Collaboration: Improves teamwork and information exchange among users.
#Fundamentals of Computer Networks#
1. Basics of Computer Networks
Computer Network: A set of interconnected devices (computers, servers, phones, printers, etc.) that communicate and share resources/data over wired or wireless links.
Benefits
- Resource sharing – files, printers, storage, internet connection
- Fast communication – email, messaging, video calls
- Centralized data & management – easier backup, control, security
- Cost-effective – shared hardware/software reduces cost
- Scalability – devices can be added easily
- Reliability – data can be replicated; alternate paths on failure
Key Characteristics
- Performance – speed, throughput, latency
- Reliability – consistent operation, fault tolerance
- Scalability – handles growth in users/devices
- Security – protection from unauthorized access
- Availability – uptime and accessibility
- Cost – setup and maintenance
Essential Components
| Component | Role |
|---|---|
| Nodes/Hosts | End devices (computers, servers, phones) |
| Network devices | Hub, repeater, bridge, switch, router, gateway |
| Transmission media | Wired (twisted pair, coaxial, fiber) / Wireless (radio, microwave, satellite) |
| Protocols | Rules for communication (TCP/IP, HTTP, etc.) |
| NIC | Hardware that connects a device to the network |
2. Network Devices
| Device | OSI Layer | Function | Key Points |
|---|---|---|---|
| Hub | Physical (1) | Broadcasts incoming data to all ports | Multiport repeater; no filtering; causes collisions; half-duplex |
| Repeater | Physical (1) | Regenerates/amplifies signal to extend distance | Does not filter data; 2 ports |
| Bridge | Data Link (2) | Connects two LANs; filters by MAC address | Learns MAC addresses; reduces collisions; 2 ports |
| Switch | Data Link (2) | Forwards frames only to the intended port using MAC table | Multiport bridge; full-duplex; separate collision domain per port |
| Router | Network (3) | Forwards packets between different networks using IP address | Chooses best path (routing table); connects LAN to WAN/internet |
| Gateway | Any (up to 7) | Connects networks using different protocols/architectures | Protocol translator; entry/exit point of a network |
Quick distinctions
- Hub = broadcasts to all; Switch = sends to the specific device
- Switch = works with MAC addresses; Router = works with IP addresses
- Router = connects similar networks; Gateway = connects dissimilar networks
3. Types of Computer Networks
| Type | Full Form | Coverage | Example | Notes |
|---|---|---|---|---|
| PAN | Personal Area Network | ~1–10 m | Bluetooth headset, phone hotspot | Single person's devices |
| LAN | Local Area Network | Room/building/campus (up to ~1 km) | Home, office, school network | High speed, low cost, privately owned |
| CAN | Campus Area Network | Campus (multiple LANs) | University campus | Interconnected LANs of one organization |
| MAN | Metropolitan Area Network | City (~5–50 km) | Cable TV network, city-wide ISP | Larger than LAN, smaller than WAN |
| WAN | Wide Area Network | Country/continent/global | The Internet | Slowest of the four, highest cost, uses leased lines/satellite |
Order by size: PAN < LAN < CAN < MAN < WAN
#Network Models#
Network models are foundational frameworks that standardize communication in computer networks. They define a layered structure that organizes network functions for efficient data flow.
Covered models: OSI Model, TCP/IP Model
1. OSI Model (Open Systems Interconnection)
A 7-layer conceptual framework (by ISO) that divides network communication into distinct layers. Each layer has a specific function and communicates with the layers directly above and below it.
| # | Layer | Function | Data Unit | Examples |
|---|---|---|---|---|
| 7 | Application | Interface for user applications to access network services | Data | HTTP, FTP, SMTP, DNS |
| 6 | Presentation | Translation, encryption, compression | Data | SSL/TLS, JPEG, ASCII |
| 5 | Session | Establishes, manages, terminates sessions | Data | NetBIOS, RPC |
| 4 | Transport | End-to-end delivery, segmentation, flow & error control | Segment / Datagram | TCP, UDP |
| 3 | Network | Logical addressing, routing | Packet | IP, ICMP, Routers |
| 2 | Data Link | Physical addressing (MAC), framing, error detection | Frame | Ethernet, Switches |
| 1 | Physical | Transmission of raw bits over the medium | Bits | Cables, Hubs |
Mnemonic (7 → 1): All People Seem To Need Data Processing
Key Points
- Top 3 layers (5-7): Software/user-oriented (Application, Presentation, Session).
- Bottom 4 layers (1-4): Data transport-oriented (Transport, Network, Data Link, Physical).
- Data is encapsulated going down the layers (sender) and de-encapsulated going up (receiver).
- A theoretical/reference model, not used directly in practice.
2. TCP/IP Model
A practical, protocol-driven model used as the basis of the Internet. Originally a 4-layer model (also shown as 5-layer).
| # | Layer | Function | Protocols |
|---|---|---|---|
| 4 | Application | User services, data formatting, session handling | HTTP, FTP, SMTP, DNS, SSH |
| 3 | Transport | End-to-end communication, reliability, flow control | TCP, UDP |
| 2 | Internet | Logical addressing, routing of packets | IP, ICMP, ARP |
| 1 | Network Access (Link) | Physical transmission and MAC addressing | Ethernet, Wi-Fi |
Key Points
- Developed by DARPA for ARPANET.
- Protocol-oriented and implemented in real networks.
- TCP: connection-oriented, reliable. UDP: connectionless, faster.
3. OSI vs TCP/IP
| Aspect | OSI Model | TCP/IP Model |
|---|---|---|
| Layers | 7 | 4 |
| Nature | Theoretical, reference model | Practical, implemented |
| Approach | Generic, protocol-independent | Protocol-specific |
| Layer separation | Strict (Session, Presentation separate) | Combined into Application layer |
| Transport | Connection-oriented and connectionless | TCP (connection-oriented), UDP (connectionless) |
| Usage | Teaching/troubleshooting | Internet standard |
Layer Mapping
| OSI | TCP/IP |
|---|---|
| Application, Presentation, Session | Application |
| Transport | Transport |
| Network | Internet |
| Data Link, Physical | Network Access |
#Physical Layer#
The foundation of network communication. Covers network topologies, transmission media, and transmission modes.
1. Physical Layer (OSI Model)
- Layer 1 of the OSI model.
- Deals with the actual physical transmission of raw bits (0s and 1s) over a medium.
- Unit of data: Bit.
- Responsibilities:
- Bit representation (encoding bits as electrical / optical / radio signals)
- Data rate (transmission rate, bits per second)
- Bit synchronization (sender and receiver clock sync)
- Physical topology (arrangement of devices)
- Transmission mode (simplex, half duplex, full duplex)
- Physical interface and medium specification (cables, connectors, voltages)
- Devices: Hub, Repeater, Modem, Cables, Connectors.
2. Types of Network Topology
Network topology = the arrangement of nodes (devices) and links in a network. Two kinds: Physical (actual layout) and Logical (how data flows).
| Topology | Structure | Pros | Cons |
|---|---|---|---|
| Bus | All devices share a single backbone cable | Cheap, easy to set up, less cable | Backbone failure kills the network, low performance with load, hard to troubleshoot |
| Ring | Each device connects to two neighbours, forming a closed loop | Orderly data flow, no collisions (token-based) | One node/link failure breaks the ring (unless dual ring), adding nodes disrupts network |
| Star | All devices connect to a central hub/switch | Easy to add/remove nodes, one cable failure affects only that node, easy fault detection | Central device is a single point of failure, more cabling |
| Mesh | Every device connects to every other device (full) or some (partial) | Highly reliable, no traffic issues, robust | Very expensive, complex, heavy cabling (full mesh links = n(n-1)/2) |
| Tree | Hierarchy of star networks connected to a root (bus backbone) | Scalable, easy fault isolation, hierarchical management | Root/backbone failure splits network, complex cabling |
| Hybrid | Combination of two or more topologies | Flexible, scalable, reliable | Complex design, costly |
3. Modes of Transmission
Defines the direction of data flow between two devices.
| Mode | Direction | Example |
|---|---|---|
| Simplex | One-way only (sender → receiver) | Keyboard, TV/radio broadcast |
| Half Duplex | Both directions, but one at a time | Walkie-talkie |
| Full Duplex | Both directions simultaneously | Telephone, mobile calls |
- Simplex: uses the entire channel capacity for one direction.
- Half duplex: channel capacity shared; direction alternates.
- Full duplex: highest throughput, requires two channels or bandwidth split.
4. Transmission Media
The physical path between sender and receiver. Two categories:
A. Guided Media (Wired / Bounded)
Signal travels through a physical conductor.
| Type | Description | Key Points |
|---|---|---|
| Twisted Pair | Pairs of insulated copper wires twisted together to reduce interference | UTP (unshielded): cheap, common in LANs. STP (shielded): less noise, costlier |
| Coaxial Cable | Central copper core + insulation + metallic shield + outer jacket | Higher bandwidth and better noise immunity than twisted pair; used in cable TV, older Ethernet |
| Fiber Optic | Light signals through glass/plastic strands (core + cladding) | Highest speed and bandwidth, long distance, immune to EMI, secure; expensive and fragile |
B. Unguided Media (Wireless / Unbounded)
Signal travels through air/space without a physical conductor.
| Type | Description | Use |
|---|---|---|
| Radio Waves | Omnidirectional, pass through walls | Radio, Wi-Fi, Bluetooth, mobile networks |
| Microwaves | Line-of-sight, unidirectional | Satellite links, point-to-point communication |
| Infrared | Short range, cannot pass through walls | Remote controls, short-range device links |
Quick Summary
- Physical Layer → raw bit transmission over a medium (Layer 1).
- Topology → Bus, Ring, Star, Mesh, Tree, Hybrid.
- Modes → Simplex, Half Duplex, Full Duplex.
- Media → Guided (Twisted Pair, Coaxial, Fiber) and Unguided (Radio, Microwave, Infrared).
#Data Link Layer#
Layer 2 of the OSI model. Handles reliable data transfer between directly connected devices: framing, error detection & correction, flow control, and switching.
- PDU: Frame
- Addressing: MAC address
- Devices: Switch, Bridge, NIC
- Sub-layers: LLC (Logical Link Control) and MAC (Media Access Control)
1. Framing
Divides the bit stream from the network layer into manageable units called frames, so the receiver can identify where each frame starts and ends.
Frame structure: Header | Payload | Trailer
| Type | Description |
|---|---|
| Fixed-size | Frame length is constant; no delimiter needed (e.g., ATM cells) |
| Variable-size | Needs a method to mark frame boundaries |
Methods for variable-size framing:
| Method | Idea |
|---|---|
| Character count | Header field stores the number of characters in the frame |
| Flag bytes + byte stuffing | Special flag byte marks start/end; an escape byte is inserted if the flag appears in data |
| Flag bits + bit stuffing | Flag 01111110; a 0 is inserted after five consecutive 1s in data |
| Physical layer coding violations | Uses invalid signal patterns to mark boundaries |
2. Error Control
Detects and corrects errors in frames during transmission.
- Error types: Single-bit error, Burst error
- Approach: Detect the error → correct it (by retransmission or by correcting codes)
2.1 Error Detection
Adds redundant bits to the data so the receiver can detect corruption.
| Technique | Key Points |
|---|---|
| Parity check | Adds 1 parity bit (even/odd); detects single-bit errors only |
| Two-dimensional parity | Parity on rows and columns; detects burst errors and locates single-bit errors |
| Checksum | Sender sums data segments and sends the complement; receiver verifies the sum |
| CRC (Cyclic Redundancy Check) | Polynomial division; remainder appended to data; widely used, detects burst errors |
2.2 Error Correction
| Approach | Description |
|---|---|
| Backward error correction | Receiver detects the error and requests retransmission (ARQ) |
| Forward error correction (FEC) | Receiver corrects errors itself using redundant bits (e.g., Hamming code) |
Hamming code: Redundant bits placed at positions that are powers of 2; formula 2^r ≥ m + r + 1 (r = redundant bits, m = data bits).
3. Flow Control
Prevents a fast sender from overwhelming a slow receiver.
| Type | Description |
|---|---|
| Stop-and-Wait | Sender sends one frame and waits for its ACK |
| Sliding Window | Sender can send multiple frames before needing an ACK |
3.1 Stop-and-Wait ARQ
- Sender sends 1 frame, then waits for ACK
- Timer starts after sending; if no ACK before timeout → retransmit
- Window size: sender = 1, receiver = 1
- Simple, but low efficiency (channel idle while waiting)
- Efficiency =
1 / (1 + 2a), wherea = Tp / Tt
3.2 Sliding Window – Go-Back-N
- Sender window size = N, receiver window size = 1
- Receiver accepts frames only in order; out-of-order frames are discarded
- On error/timeout, sender retransmits the lost frame and all frames after it
- Uses cumulative acknowledgement
- Sequence numbers needed:
N + 1 - Simple receiver, but wastes bandwidth on retransmission
3.3 Sliding Window – Selective Repeat
- Sender window size = N, receiver window size = N
- Receiver buffers out-of-order frames and reorders them
- Only the lost/damaged frame is retransmitted
- Uses individual acknowledgement
- Sequence numbers needed:
2N - More efficient, but complex receiver (sorting & buffering)
| Feature | Stop-and-Wait | Go-Back-N | Selective Repeat |
|---|---|---|---|
| Sender window | 1 | N | N |
| Receiver window | 1 | 1 | N |
| Retransmission | Lost frame | Lost frame + all after | Only lost frame |
| Receiver buffering | No | No | Yes |
| Efficiency | Low | Medium | High |
| Complexity | Low | Medium | High |
3.4 Piggybacking
- In bidirectional (full-duplex) communication, the ACK for received data is attached to an outgoing data frame instead of sent as a separate frame
- Benefit: Reduces the number of frames and improves bandwidth utilization
- If no data is ready to send, the receiver waits briefly, then sends a standalone ACK
4. Switching Techniques
Methods of transferring data from source to destination across a network.
| Technique | Description | Key Points |
|---|---|---|
| Circuit switching | Dedicated path established before transmission | Fixed bandwidth, constant delay, setup time, resources wasted when idle (e.g., telephone) |
| Message switching | Entire message stored and forwarded hop by hop | Store-and-forward, no dedicated path, high delay, needs large buffers |
| Packet switching | Message split into packets sent independently | Efficient bandwidth use, packets may take different routes (e.g., Internet) |
Packet switching approaches:
| Approach | Description |
|---|---|
| Datagram | Connectionless; each packet routed independently; may arrive out of order |
| Virtual circuit | Connection-oriented; fixed route set up first; packets arrive in order |
5. Virtual LAN (VLAN)
A logical grouping of devices into a separate broadcast domain, regardless of physical location.
- Configured on switches
- Each VLAN = one broadcast domain; traffic is isolated between VLANs
- Inter-VLAN communication requires a router / Layer 3 switch
- Standard: IEEE 802.1Q (adds a VLAN tag to the Ethernet frame)
Benefits: Better security, reduced broadcast traffic, flexible network management, improved performance.
| Port Type | Description |
|---|---|
| Access port | Belongs to a single VLAN; connects end devices |
| Trunk port | Carries traffic of multiple VLANs between switches |
6. Link Aggregation
Combines multiple physical links into one logical link to increase bandwidth and provide redundancy.
- Protocol: LACP (Link Aggregation Control Protocol), IEEE 802.3ad / 802.1AX
- Also called port channel / EtherChannel / NIC teaming
Benefits:
- Higher throughput
- Fault tolerance (traffic continues if one link fails)
- Load balancing across links
🧭 Continue Learning
Related technical blueprints and practical guides in Core CS.

DBMS (Database Management System)
A comprehensive guide to Database Management Systems covering database fundamentals, ER modeling, relational algebra, normalization, SQL, transactions, indexing, query optimization, recovery, and database security. Designed for strong conceptual understanding and technical interview preparation.

Object-Oriented Programming (OOP)
A comprehensive guide to Object-Oriented Programming (OOP), covering classes, objects, encapsulation, abstraction, inheritance, polymorphism, constructors, destructors, interfaces, exception handling, and object relationships. Includes practical C++ and Java examples, SOLID principles, design patterns fundamentals, and interview-oriented questions to build strong object-oriented design skills.