Network
Network
computer network is a set of different devices connected to each other to facilitate communication
and data exchange. A network can be as small as two computers linked by a cable or as vast as the
Internet, which is the world's largest computer network, connecting billions of devices
simultaneously. The term "computer network" has evolved; with the rise of smart devices like
phones, cars, and even refrigerators connecting to the internet, the term
"Internet of Things" (IoT) is often more appropriate. Every time you stream a video, browse a
website, or send an email, you are using a computer network to retrieve data from remote servers.
For devices to communicate over a network, they must have unique addresses. There are two
primary types of addresses:
• MAC (Media Access Control) Address: A permanent, hardware-level address built into the
device's Network Interface Card (NIC) by the manufacturer.
Each device on a network, such as a laptop or smartphone, will have both a unique MAC address and
an IP address to participate in communication.
To ensure devices from different manufacturers can understand each other, they follow standardized
rules, or
protocols. Networking models provide a framework for understanding how these protocols work
together in layers to transmit data. The two most important models are the OSI model and the
TCP/IP model.
The TCP/IP model is a practical, four-layer model that describes how data communication occurs on
the Internet. Its name comes from two of its most important protocols: the Transmission Control
Protocol (TCP) and the Internet Protocol (IP). The layers are independent, meaning a change in one
layer does not require a change in the others.
• Function: This is the top layer where user-facing applications and network services reside. It
provides the data that needs to be sent across the network.
• Protocols: HTTP/HTTPS (web browsing), FTP (file transfer), SMTP (email), DNS (domain name
resolution), DHCP (IP address assignment).
Layer 3: Transport Layer
• Function: Establishes end-to-end communication and ensures reliable data delivery between
two devices. It handles flow control and error checking.
• Protocols:
• Function: Responsible for connecting different networks, finding the optimal path between
them, and routing packets from a source to a destination.
• Protocols: IP (IPv4, IPv6), ICMP (Internet Control Message Protocol), and various routing
protocols.
• Function: The lowest layer, responsible for the physical transmission of data over the media,
such as cables or wireless signals.
The Open Systems Interconnection (OSI) model is a more theoretical, seven-layer model that is often
used for educational purposes because it breaks down the networking process into more granular
steps.
Layer
OSI Layer Function PDU
#
Export to Sheets
The TCP/IP model's layers correspond to multiple layers in the OSI model.
Export to Sheets
• Byte: A group of 8 bits. One byte can represent a single character, like 'A'.
• Protocol Data Unit (PDU): The name for a piece of data at a specific layer of the OSI model.
As data moves down the layers, it is given a different name: Data (Layers 7-5), Segment
(Layer 4), Packet (Layer 3), Frame (Layer 2), and Bits (Layer 1).
Encapsulation is the process of adding protocol information (a header) at each layer as data moves
down from the Application layer to the Physical layer on the sending device.
4. Network Access/Data Link Layer: Adds an Ethernet header with source and destination MAC
addresses (creating a frame) and a trailer for error checking.
5. Physical Layer: The frame is converted into bits and sent over the physical medium.
Decapsulation is the reverse process. The receiving device removes the headers at each layer as the
data moves up, reading the information and passing the payload up to the next layer until the
original data reaches the application.
3. Network Performance Characteristics
• Bandwidth: The maximum theoretical amount of data that can be transmitted over a link in
a given amount of time, measured in bits per second (bps). For example, 100 megabits per
second (Mbps) means 100 million bits can be sent per second. The effective bandwidth
between two devices is determined by the slowest link in the path, known as the
bottleneck.
• Throughput: The actual measured amount of data that is successfully transferred over a link,
which is always lower than the bandwidth due to overhead from protocol headers and
network delays.
• Latency: The one-way delay for data to travel from a source to a destination, measured in
milliseconds (ms). It is the sum of several types of delays:
o Processing Delay: Time taken by routers and switches to process the packet header.
o Queuing Delay: Time a packet spends waiting in a queue (buffer) before being
transmitted.
o Transmission Delay: Time it takes to push all of the packet's bits onto the link.
o Propagation Delay: Time it takes for a bit to travel the physical distance of the link.
• Round-Trip Time (RTT): The total time for a signal to be sent from a source to a destination
and for a response to be received back at the source. This is what the
• Jitter: The variation in latency over time for different packets in the same data stream. High
jitter can disrupt real-time applications like video calls, causing broken audio or video.
• Packet Loss: Occurs when network packets fail to reach their destination due to network
congestion, hardware failures, or other errors. Reliable protocols like TCP can recover from
packet loss by retransmitting the lost data.
Ethernet is the most popular set of protocols used at the Data Link (Layer 2) and Physical (Layer 1)
layers. It defines how devices communicate over both wired and wireless media. The standards are
created by the Institute of Electrical and Electronics Engineers (IEEE).
• IEEE 802.3: The standard for wired Ethernet over copper or fiber optic cables.
• IEEE 802.11: The standard for wireless networking (Wi-Fi), with various versions like 802.11n
and 802.11ac.
Physical Media
• Copper Cable: Uses electrical signals to transmit data. It consists of twisted pairs of wires to
reduce interference. Common types include Unshielded Twisted Pair (UTP) and Shielded
Twisted Pair (STP), with different categories (e.g., Cat 6) supporting different speeds, up to 10
Gigabits per second (Gbps). The standard connector is
RJ45.
• Fiber Optic Cable: Transmits data using pulses of light, making it immune to electrical
interference and capable of much higher speeds (up to 100 Gbps) and longer distances (up
to 100 kilometers). It is more expensive and is used for network backbones and connections
between continents.
• Wireless: Uses radio waves to transmit data, offering flexibility and mobility. However, it is a
shared medium, making it susceptible to interference and collisions.
Network Interface Card (NIC) is the hardware component that allows a device to connect to a
network. Every NIC, whether wired or wireless, has a unique MAC address burned into it by the
manufacturer.
MAC Addresses
MAC (Media Access Control) address is a 48-bit unique hardware identifier used to address devices
at the Data Link layer.
o Organizational Unique Identifier (OUI): The first 24 bits, assigned by the IEEE to a
specific manufacturer (e.g., Cisco, Apple).
o NIC-Specific: The last 24 bits, assigned by the manufacturer to be unique for that
specific device.
Network Switches
network switch is a Layer 2 device that connects multiple devices on a local area network (LAN). Its
primary function is to forward Ethernet frames to their correct destination as efficiently as possible.
• How it Works: A switch learns the MAC addresses of the devices connected to each of its
ports by inspecting the source MAC address of incoming frames. It stores this information in
a
MAC address table. When a frame arrives, the switch looks at the destination MAC address, checks
its table, and forwards the frame only to the port where the destination device is located.
• Unknown Destinations: If the destination MAC address is not in its table, the switch will
flood the frame, sending it out to all ports except the one it came in on.
An Ethernet frame is the PDU at the Data Link layer and has a specific structure.
Preamble & A sequence of bits used by the receiving NIC to synchronize with
8 bytes
SFD the incoming signal and identify the start of the frame.
Destination
6 bytes The MAC address of the receiving device.
MAC
0x0800
Type 2 bytes Identifies the protocol of the payload (e.g.,
for IPv4).
Payload 46-1500
The data received from the Network layer (e.g., an IP packet).
(Data) bytes
Export to Sheets
• Full-Duplex: Communication where a device can send and receive data simultaneously. This
is standard for modern wired Ethernet connections.
• Half-Duplex: Communication where a device can only either send or receive at one time, but
not both. This is how Wi-Fi operates.
• Collision: Occurs in a half-duplex environment when two or more devices try to transmit
data at the same time on a shared medium. The signals interfere, corrupting the data.
• Collision Domain: A segment of a network where collisions can occur. On an old hub-based
network, all devices were in one large collision domain. On a modern switched network,
each port on the switch is its own separate collision domain, effectively eliminating collisions
in wired, full-duplex links.
• Collision Handling:
o CSMA/CD (Carrier Sense Multiple Access with Collision Detection): Used in wired
Ethernet. Devices listen to see if the line is free before transmitting. If a collision is
detected, they stop, wait a random amount of time, and try again.
The Network Layer (Layer 3) is responsible for logical addressing and moving packets across different
networks, a process known as
routing.
While Layer 2 (switches and MAC addresses) is effective for small local networks, it doesn't scale
well. A large network of only switches would suffer from:
• Broadcast Storms: A single broadcast frame would be forwarded by every switch to every
device, flooding the network and consuming all available bandwidth.
• Large MAC Address Tables: Switches would need to store the MAC addresses of every device
on the massive network, which is inefficient and can exceed their memory limits.
Routers and IP addresses solve this by dividing large networks into smaller, manageable logical
networks (or
subnets), and routers control the flow of traffic, including broadcasts, between them.
IP Addresses
An
o IPv4: The older, 32-bit address format (e.g., 192.168.1.1). It consists of four decimal
numbers (octets), each ranging from 0 to 255. There are approximately 4.3 billion
possible IPv4 addresses, which have now been exhausted.
• IP Address Types:
Due to the scarcity of IPv4 addresses, a system of public and private addressing was created.
• Private IP Addresses: These are non-routable on the public Internet. They are meant to be
used only within a private local network (e.g., your home or office). The ranges are defined in
RFC 1918:
• Public IP Addresses: These are unique, globally routable addresses assigned by Internet
Service Providers (ISPs). Any IP address not in the private ranges is considered public.
• Network Address Translation (NAT): This is the technology used by routers to allow devices
with private IP addresses to communicate with the Internet. The router translates the private
source IP address of an outgoing packet to its own public IP address and reverses the process
for incoming packets.
• Static IP: An IP address that is manually configured and does not change. This is typically
used for servers, printers, or other devices that need a consistent address.
• Dynamic IP: An IP address that is automatically assigned to a device for a temporary period.
This is managed by a
DHCP (Dynamic Host Configuration Protocol) server, which is often built into home routers. Most
client devices (laptops, phones) use dynamic addressing.
The IPv4 packet header contains crucial information for routing the packet. Key fields include:
Field Description
Total Length The total size of the packet (header + data) in bytes.
Identification, Flags, Fields used for fragmenting large packets into smaller pieces for
Fragment Offset transmission and reassembling them at the destination.
Identifies the transport layer protocol of the payload (e.g., 6 for TCP, 17
Protocol
for UDP).
Export to Sheets
router is a Layer 3 device whose main purpose is to receive incoming packets, look at their
destination IP address, and forward them to the next network on the path to their final destination.
• Routing Table: Every router maintains a routing table, which is a list of known networks and
the path to reach them. A routing table entry typically contains:
o Next-Hop Router: The IP address of the next router to send the packet to.
o Outgoing Interface: The local interface on the router to use to send the packet.
• Routing Decision: When a packet arrives, the router performs a lookup in its routing table to
find the best match for the destination IP address. Routers use the
longest prefix match rule: if a destination matches multiple routes, the router will choose the most
specific route (the one with the longest subnet mask). If no specific route is found, the packet is sent
to the
6. Subnetting
A network is defined by a
network prefix (the network portion of an IP address) and a network mask (which specifies how
many bits are in the network portion). For example, in
192.168.1.100 with a mask of /24 (or 255.255.255.0), the first 24 bits (192.168.1) are the network
portion, and the last 8 bits (.100) are the host portion.
• Network Address: The address where all host bits are zero (e.g., 192.168.1.0). This address
represents the network itself.
• Broadcast Address: The address where all host bits are one (e.g., 192.168.1.255). This
address is used to send a packet to all hosts on the network.
• Host Addresses: All addresses between the network and broadcast addresses can be
assigned to devices.
• Calculating Available Hosts: The number of usable host addresses in a network is 2^h - 2,
where h is the number of host bits. The "-2" accounts for the reserved network and
broadcast addresses.
What is Subnetting?
Subnetting is the process of taking a single, large network and dividing it into multiple smaller
networks, called subnets. This is done by "borrowing" bits from the host portion of the address and
adding them to the network portion, thus extending the network mask.
Why Subnet?
1. Reduce Broadcast Domain Size: Each subnet is a separate broadcast domain, meaning
broadcasts are contained within that subnet and do not flood the entire organization's
network.
ARP operates at the boundary of Layer 2 and Layer 3 and is crucial for local network communication.
• Purpose: To resolve a known IP address to its corresponding MAC address. A device needs
the destination MAC address to create the Layer 2 Ethernet frame, but applications typically
only work with IP addresses.
• Process:
1. A device (Host A) wants to send a packet to another device (Host B) on the same
local network. It knows Host B's IP address but not its MAC address.
3. All devices on the LAN receive and process the request, but only Host B, whose IP
address matches the request, will respond.
4. Host B sends an
ARP Reply directly (unicast) to Host A, saying, "I have that IP address, and my MAC address is
yy:yy:yy:yy:yy:yy.".
5. Host A receives the reply and stores the IP-to-MAC mapping in its ARP cache for
future use. It can now create the Ethernet frame and send the packet.
ICMP is a network layer protocol used by devices to send control messages and report errors. It is not
used for end-user data transmission.
ping utility uses ICMP Echo Request and Echo Reply messages to test connectivity to another device
and measure round-trip time. The
traceroute (or tracert on Windows) utility uses ICMP to discover the path (the sequence of routers)
that packets take to a destination.
2. Network Logic: PC1 compares its IP and mask with the destination IP and determines they
are on the same local network.
3. ARP: PC1 checks its ARP cache for the MAC address of 192.168.1.7. If not found, it performs
an ARP request/reply process to learn it.
4. Encapsulation: PC1 creates the packet with a destination IP of 192.168.1.7 and then creates
the frame with the destination MAC of PC2.
5. Transmission: The frame is sent to the local switch, which forwards it directly to the port
connected to PC2.
2. Network Logic: PC1 determines that the destination IP 8.8.8.8 is on a different network.
Therefore, it knows it must send the packet to its
192.168.1.1.
3. ARP: PC1 needs the router's MAC address, not Google's. It checks its ARP cache for the MAC
of 192.168.1.1. If not found, it performs an ARP request for the router's MAC.
4. Encapsulation:
o Packet (Layer 3): The source IP is 192.168.1.5, and the destination IP is 8.8.8.8. This
o Frame (Layer 2): The source MAC is PC1's MAC, but the destination MAC is the
router's MAC.
5. Routing:
o The switch sends the frame to the router.
o The router receives the frame, sees its own MAC as the destination, and
decapsulates it to inspect the IP packet.
8.8.8.8 in its routing table and finds the next-hop router on the path to the destination.
o The router re-encapsulates the packet in a new frame. The new source MAC is the
router's outgoing interface MAC, and the new destination MAC is that of the next-
hop router.
ports to deliver data to the correct application on a device. It also provides reliability and flow
control.
• Multiplexing: On the sending device, the transport layer takes data from multiple
applications (e.g., a web browser, an email client, a music app), adds the appropriate TCP or
UDP headers, and passes the segments down to the network layer. This allows multiple
applications to share the same network connection.
• Demultiplexing: On the receiving device, the transport layer reads the destination port
number in the incoming segments and directs the data to the correct application waiting on
that port.
o Well-Known Ports (0-1023): Reserved for standard services (e.g., HTTP on port 80,
HTTPS on 443, SSH on 22).
TCP is a
reliable, connection-oriented protocol. It is used for applications that require guaranteed data
delivery, like web browsing, file transfers, and email.
• Three-Way Handshake (Connection Establishment): Before any data is sent, TCP establishes
a connection using a three-step process:
1. SYN: The client sends a segment with the SYN (synchronize) flag set to the server.
2. SYN-ACK: The server responds with a segment that has both the SYN and ACK
(acknowledgment) flags set.
3. ACK: The client sends a final segment with the ACK flag set, confirming the
connection is established.
• Reliability: TCP uses sequence numbers to track each byte of data sent and
acknowledgments from the receiver to confirm receipt. If an acknowledgment is not
received within a certain time, TCP will retransmit the data, ensuring no data is lost.
• Flow Control: TCP uses a window size to manage the rate of data transmission, preventing
the sender from overwhelming the receiver.
• Connection Teardown: When the data transfer is complete, a similar process using the FIN
(finish) flag is used to gracefully close the connection.
• TCP Header: The TCP header is complex, containing fields for source/destination ports,
sequence/acknowledgment numbers, flags (SYN, ACK, FIN, RST), window size, and a
checksum for error detection.
UDP is a
unreliable, connectionless protocol. It is used for applications that prioritize speed and low overhead
over reliability, such as live video/audio streaming, online gaming, and DNS.
• "Best-Effort" Delivery: UDP simply sends segments (called datagrams) without establishing a
connection or waiting for acknowledgments. There is no guarantee that the data will arrive,
or that it will arrive in order.
• UDP Header: The UDP header is very simple, containing only four fields: source port,
destination port, length, and a checksum.
Low (8-byte
Overhead High (20+ byte header)
header)
Flow
Yes (sliding window) No
Control
Export to Sheets
Autonomous System (AS) is a large network or a group of networks under a single administrative
control, such as a major ISP (e.g., Comcast, AT&T), a large tech company (e.g., Google, Amazon), or a
university. Each AS is assigned a unique
Routing protocols are used by routers to dynamically share information about reachable networks.
They are divided into two main categories:
1. Interior Gateway Protocol (IGP): Used for routing within a single Autonomous System. The
goal of an IGP is to find the fastest and most efficient path inside its own network. Examples
include:
o OSPF (Open Shortest Path First): A widely used link-state protocol that builds a
complete map of the network to calculate the best path.
2. Exterior Gateway Protocol (EGP): Used for routing between different Autonomous Systems.
The primary goal of an EGP is to enforce policies about which traffic can cross AS boundaries.
o BGP (Border Gateway Protocol): This is the one and only EGP used on the modern
Internet. BGP routers exchange reachability information for large blocks of public IP
addresses. BGP routers are configured to filter out and not advertise private IP
address ranges (RFC 1918).
• Distance-Vector: Routers only know about their directly connected neighbors. They advertise
their routes to their neighbors, telling them the "distance" (metric, e.g., hop count) to each
destination. This is sometimes called "routing by rumor" because routers trust the
information their neighbors give them without having a full picture of the network topology.
RIP and BGP are distance-vector protocols.
• Link-State: Each router builds a complete map (a topological database) of the entire network
within its area. They do this by flooding information about the status of their own links ("link-
states") to all other routers. With a full map, each router can independently calculate the
shortest path to every destination. OSPF is a link-state protocol. Link-state protocols converge
faster after a network change but require more CPU and memory.
• CIDR (Classless Inter-Domain Routing): The modern approach to IP addressing that ignores
the old "class" system (Class A, B, C) and instead uses variable-length subnet masks (e.g., /24,
/26, /12). This allows for much more flexible and efficient allocation of IP addresses. Every
route in a modern routing table is a CIDR prefix (network + mask).
• Route Summarization (or Aggregation): The process of combining multiple, more specific
network routes into a single, less specific (or "summary") route. For example, instead of
advertising sixteen separate
/16 networks, a router can advertise a single /12 route that encompasses all of them. This is crucial
for keeping routing tables on the Internet at a manageable size.