Network layer
Network layer
BY TRUPTI SISODE.
What is the Network Layer?
The main responsibility of the Network layer is to carry the data packets from
the source to the destination without changing or using them.
If the packets are too large for delivery, they are fragmented i.e., broken down
into smaller packets.
It decides the route to be taken by the packets to travel from the source to the
destination among the multiple routes available in a network (also called
routing).
The source and destination addresses are added to the data packets inside the
network layer.
Services Offered by Network Layer
1. Packetizing
Packetizing is the process of putting data into a packet at the source and
taking it out of the packet at the destination.
• At the Source: The source puts a header with the source and destination
addresses onto the data, then sends the packet to the next layer.
• At the Destination: The destination receives the packet, removes the
header, and sends the data to the appropriate place.
• Routers: They don’t change the addresses in the packet. They only handle
the packet if it needs to be split into smaller pieces.
1. Packetizing
2. Routing
Routing is the process of directing data packets from one place to another across a network.
Example
Imagine sending a letter from your home to a friend’s house in a different city. Here’s how routing works:
1. Starting Point (Your Home):
1. You write the letter and address it with your friend’s location.
2. Route Taken:
1. The letter is sent to a post office, then to several intermediate locations (like other post offices or sorting centers), each of which figur
2. es out the next destination based on the address.
Forwarding in the network layer is the process of moving data packets from one network device to another along
the path to their final destination.
Simple Example
Think of forwarding as a delivery service:
1. Receiving Device (Router): A router receives a packet of data.
2. Checking Destination: The router looks at the packet’s destination address.
3. Sending to Next Device: Based on the address, the router forwards the packet to the next device or router on the
path to the destination.
4. Continuing the Journey: The packet continues to be forwarded from router to router until it reaches its destination.
In Short: Forwarding is the action of directing data packets to their next hop or device based on their destination
address, helping them travel through the network.
Forwarding
Other Services Expected from Network Layer
Error Control
• Purpose: Detects and manages errors that occur during data transmission.
• How: Uses techniques like checksums or acknowledgments to identify corrupted or lost packets and request
retransmission if needed.
2. Flow Control
• Purpose: Ensures that data is sent at a rate that the receiving device can handle.
• How: Adjusts the rate of data transmission based on the receiver’s ability to process and store incoming
packets, preventing data overload.
3. Congestion Control
• Purpose: Prevents network congestion by managing the amount of data entering the network.
• How: Monitors network traffic and adjusts the data flow to avoid excessive load that could slow down or
block the network.
IPv4 addressing
The IPv4 address is a 32-bit number that uniquely identifies a network interface on a
machine. An IPv4 address is typically written in decimal digits, formatted as four 8-bit
fields that are separated by periods.
1. Address Format:
32-bit Address: An IPv4 address consists of 32 bits. This is divided into four 8-
bit octets. Each octet is represented as a decimal number ranging from 0 to
255.
•Example: 192.168.1.1
Binary Representation: The address can also be represented in binary format,
such as 11000000.10101000.00000001.00000001
Address space
The address space of IPv4 is 32 bits, which means it can provide approximately
2³² or about 4.3 billion unique addresses. This limitation has led to the adoption
of IPv6, which uses 128 bits and can provide a vastly larger address space.
Binary Notation In binary notation, the IPv4 address is displayed as 32 bits. Each octet is
often referred to as a byte. So it is common to hear an IPv4 address referred to as a 32-bit
address or a 4-byte address. The following is an example of an IPv4 address in binary
notation:
01110101 10010101 00011101 00000010
Dotted-Decimal Notation To make the IPv4 address more compact and easier to read,
Internet addresses are usually written in decimal form with a decimal point (dot)
separating the bytes.
The following is the dotted decimal notation of the above address: 117.149.29.2
binary notation to dotted-decimal notation
Example
Change the following IPv4 addresses from binary notation to dotted-
decimal notation.
Classful addressing is an old method used in IP networking to divide the IP address space
into distinct classes, each catering to different network sizes. This method was part of
IPv4 and helped in allocating IP addresses based on the size of the network.
In classful addressing, the address space is divided into five classes: A, B, C, D, and E.
•1. 00001000 00101000 00001111 11000011 → Class A (first bit 0)
•2. 10101100 00010000 00001101 00101011 → Class B (first 2 bits 10)
•3. 23.45.67.89 → Class A (first byte 23)
•4. 240.100.200.250 → Class E (first byte 240)
Finding the classes in binary and dotted-decimal notation
Class A
Class A is one of the classes in the IPv4 addressing scheme, used in early network design for IP
addressing.
1. Range of IP Addresses
•First Octet Range: 1.0.0.0 to 126.0.0.0
•Complete Address Range: 1.0.0.0 to 126.255.255.255
•Default Subnet Mask: 255.0.0.0 (or /8 in CIDR notation)
2. Structure
•First Octet (Network Part): The first 8 bits (1st octet) are designated as the network identifier.
•Remaining Octets (Host Part): The remaining 24 bits (2nd, 3rd, and 4th octets) are used for host
identification.
Example:
•An IP address like 10.1.2.3 would belong to the 10.0.0.0 network, with 1.2.3 as the host
identifier.
3. Number of Networks and Hosts
•Number of Networks: 128 (2^7, as the first bit is fixed as 0)
•Number of Hosts per Network: 16,777,214 (2^24 - 2, since two addresses are reserved—network and
broadcast)
4. Special Addresses
•0.0.0.0: Used to represent a default route or an unknown network.
•127.0.0.0 to 127.255.255.255: Reserved for loopback testing (localhost).
5. Usage
•Class A addresses are typically assigned to large organizations or Internet Service Providers (ISPs) with a
large number of hosts on their network.
•Due to their large size, they are less commonly used today for public networks but may be utilized in
private networks.
Class B is one of the classes in the original IPv4 addressing scheme, designed to accommodate
medium to large-sized networks.
1. Range of IP Addresses
•First Octet Range: 128.0.0.0 to 191.255.0.0
•Complete Address Range: 128.0.0.0 to 191.255.255.255
•Default Subnet Mask: 255.255.0.0 (or /16 in CIDR notation)
2. Structure
•First Two Octets (Network Part): The first 16 bits (1st and 2nd octets) are designated as the network
identifier.
•Last Two Octets (Host Part): The remaining 16 bits (3rd and 4th octets) are used for host
identification.
Host Address
Example:
•An IP address like 172.16.50.100 would belong to the 172.16.0.0 network, with 50.100 as the host
identifier.
Network Address
Number of Networks and Hosts
•Number of Networks: 16,384 (2^14, as the first two bits are fixed as 10)
•Number of Hosts per Network: 65,534 (2^16 - 2, since two addresses are reserved—
network and broadcast)
4. Special Addresses
•Network Address: The first address in a given network, used to identify the network itself.
For example, 172.16.0.0 in the 172.16.0.0/16 network.
•Broadcast Address: The last address in a given network, used to send data to all hosts in
the network. For example, 172.16.255.255 in the 172.16.0.0/16 network.
5. Usage
•Class B addresses were intended for medium to large-sized organizations or universities
with a sizable number of hosts.
•These addresses offer a balance between the number of networks and the number of hosts
per network.
Class C is one of the classes in the IPv4 addressing scheme, designed for small-sized
networks.
1. Range of IP Addresses
•First Octet Range: 192.0.0.0 to 223.255.255.255
•Complete Address Range: 192.0.0.0 to 223.255.255.255
•Default Subnet Mask: 255.255.255.0 (or /24 in CIDR notation)
2. Structure
•First Three Octets (Network Part): The first 24 bits (1st, 2nd, and 3rd octets) are designated as
the network identifier.
•Last Octet (Host Part): The remaining 8 bits (4th octet) are used for host identification.
Example:
•An IP address like 192.168.1.10 would belong to the 192.168.1.0 network, with 10 as the host
identifier.
3. Number of Networks and Hosts
•Number of Networks: 2,097,152 (2^21, as the first three bits are fixed as 110)
•Number of Hosts per Network: 254 (2^8 - 2, since two addresses are reserved—network
and broadcast)
4. Special Addresses
•Network Address: The first address in a given network, used to identify the network itself.
For example, 192.168.1.0 in the 192.168.1.0/24 network.
•Broadcast Address: The last address in a given network, used to send data to all hosts in
the network. For example, 192.168.1.255 in the 192.168.1.0/24 network.
5. Usage
•Class C addresses are primarily intended for small-sized networks, such as small
businesses or home networks.
•Because of the limited number of hosts per network, they are ideal for environments where
fewer than 254 devices are needed.
2. Structure
•First Four Bits (1110): The first four bits of a Class D address are fixed as 1110, which determines that the
address is within the multicast range.
•Remaining 28 Bits: The remaining 28 bits identify the specific multicast group.
Example:
•An IP address like 224.0.1.1 is a multicast address, with the specific group identified by the remaining 28 bits.
•Class D addresses are reserved for multicast groups, not for individual hosts or networks.
•They allow efficient data distribution to multiple recipients simultaneously, making them ideal for applications like live
streaming, online gaming, and real-time data feeds.
•Class D addresses span the range 224.0.0.0 to 239.255.255.255 and are managed differently from the traditional
unicast addresses in Classes A, B, and C.
Class E
❑ Class E IP addresses are reserved for experimental purposes and are not used in regular network
operations.
❑ The address range 240.0.0.0 to 255.255.255.255 is not available for public or private network
assignments.
❑ These addresses are generally ignored by networking devices and protocols, except for specific
research and experimental use cases.
1. Range of IP Addresses
•First Octet Range: 240.0.0.0 to 255.255.255.255
•Complete Address Range: 240.0.0.0 to 255.255.255.255
2. Structure
•First Four Bits (1111): The first four bits of a Class E address are fixed as 1111, which places the
address within the reserved range.
•Remaining 28 Bits: The remaining 28 bits could theoretically be used for network and host
identification, but Class E addresses are not defined for use in standard networking.
Subnetting
• What is Subnetting?
• Subnetting is the process of dividing a large network into smaller sub-networks
(subnets).
• Helps in better network management, security, and IP address utilization.
• Benefits of Subnetting:
• Improved Security: Different subnets can have different security settings.
• Better Organization: Helps in organizing large networks into manageable
sections.
• Efficient IP Usage: Reduces the waste of IP addresses.
Example 1 Network:
•Borrowing Bits:
•We need to borrow bits from the host portion to create subnets.
•From the 8 host bits, we borrow the first 2 bits, leaving 6 bits for hosts.
Subnet Addresses in Binary:
•Subnet 1: •Subnet 3:
•Binary: • Binary:
11000000.10101000.00000001.00000000 11000000.10101000.00000001.10000000
•Range: • Range:
11000000.10101000.00000001.00000000 to
11000000.10101000.00000001.10000000 to
11000000.10101000.00000001.00111111
•Decimal: 192.168.1.0 to 192.168.1.63 11000000.10101000.00000001.10111111
•Decimal: 192.168.1.128 to 192.168.1.191
•Subnet 2:
•Binary: •Subnet 4:
11000000.10101000.00000001.01000000 •Binary:
Range: 11000000.10101000.00000001.11000000
11000000.10101000.00000001.01000000 to •Range:
11000000.10101000.00000001.01111111
11000000.10101000.00000001.11000000 to
•Decimal: 192.168.1.64 to 192.168.1.127
11000000.10101000.00000001.11111111
•Decimal: 192.168.1.192 to 192.168.1.255
Example 2 Network:
•Number of Subnets: 2
•How Many Bits to Borrow:
•Since you need 2 subnets, you borrow 1 bit from the
host portion.
•2^1 = 2 (this gives you the number of subnets).
Calculate the Subnet Addresses
Since you borrowed 1 bit, you can create 2 subnets. Here's how they look:
1.Subnet 1:
•Network Address: 192.168.1.0
•Binary Representation: 11000000.10101000.00000001.00000000
•Range of Usable IP Addresses: 192.168.1.1 to 192.168.1.126
•Broadcast Address: 192.168.1.127
2.Subnet 2:
•Network Address: 192.168.1.128
•Binary Representation: 11000000.10101000.00000001.10000000
•Range of Usable IP Addresses: 192.168.1.129 to 192.168.1.254
•Broadcast Address: 192.168.1.255
To divide a Class B network (e.g., 172.16.0.0/16) into 4 subnets, follow
these steps:
Supernetting is the opposite of Subnetting. In subnetting, a single big network is divided into
multiple smaller subnetworks. In Supernetting, multiple networks are combined into a bigger
network termed a Supernetwork or Supernet.
If you have Class C addresses and want to supernet them, the goal is to combine multiple
smaller Class C networks into a larger network.
Step 1: Identify the Class C Networks to Combine
Suppose you have the following Class C networks:
• 192.168.1.0/24
• 192.168.2.0/24
• 192.168.3.0/24
• 192.168.4.0/24
Step 2: Convert Network Addresses to Binary
Convert the network addresses to binary format to see the common bits:
•192.168.1.0: 11000000.10101000.00000001.00000000
•192.168.2.0: 11000000.10101000.00000010.00000000
•192.168.3.0: 11000000.10101000.00000011.00000000
•192.168.4.0: 11000000.10101000.00000100.00000000
Summary
By supernetting, you've combined multiple Class C networks into a single network:
•Original Networks: 192.168.1.0/24, 192.168.2.0/24, 192.168.3.0/24,
192.168.4.0/24
•Supernet: 192.168.0.0/22
Classless Addressing
CIDR Notation:
•Address blocks are often represented using CIDR (Classless Inter-Domain Routing)
notation, which includes an IP address followed by a slash (/) and a prefix length
(e.g., 192.168.1.0/24).
3. The First Address in the Block Must Be Divisible by the Number of Addresses:
•Explanation: The starting IP address in the block should be divisible by the total number of addresses in that
block.
•Example: For an address block with 8 addresses (/29), the block starts at 192.168.1.0. Since 8 is the number of
addresses, the first address (192.168.1.0) must be divisible by 8 (which it is, as 192.168.1.0 is 0 in binary, and 0 ÷
8 = 0).
All Rules Example:
Example :
Instead of using default masks like 255.0.0.0 (Class A) or 255.255.255.0 (Class C), CIDR uses a notation
like 192.168.1.0/24 where /24 indicates the number of bits used for the network portion.
ANS:
i. Subnet mask
•CIDR Notation: /28
•This means the first 28 bits are used for the network portion.
A /28 subnet mask means 28 bits are set to 1.
11111111.11111111.11111111.11110000
•Split the binary mask into four octets and convert each to decimal:
•11111111 = 255
•11111111 = 255
•11111111 = 255
•11110000 = 240
So, the subnet mask in decimal notation is: 255.255.255.240
ii. Find first address of the block
•Convert the last octet of the IP address to binary: 39 in decimal is 00100111 in binary.
•00100111 (39 in binary) becomes 00100000 (32 in binary) ,when the last 4 bits are set to 0. (32-n)bits to 0
•So, the network address for the IP block is 205.16.37.32.
•The first address or network address for the 205.16.37.39/28 subnet is 205.16.37.32. This address represents
the beginning of the subnet block.
•Another method is perform (AND Operation) with IP address and mask
An IPv4 datagram is a packet of data that is used in the IPv4 protocol to transmit information across networks. It consists o f
a header and a payload.
• Header:
• Version (4 bits): Indicates the IP version, which is 4 for IPv4.
• Header Length (IHL) (4 bits): Specifies the length of the header in 32-bit words.
• It is a 4-bit field, meaning it can represent values from 0 to 15.
• Since the IHL field is 4 bits long, the minimum value it can represent is 5 (for a header without options), and the
maximum is 15 (for a header with maximum options).
• The standard IPv4 header is 20 bytes long. Since each 32-bit word is 4 bytes(Scaling Factor), the minimum IHL value
is 20 bytes / 4 bytes = 5.
• The maximum IHL value is 15, which means the header can be 15 words * 4 bytes = 60 bytes long.
3.Type of service: Low Delay, High Throughput, Reliability (8 bits)
Voice calls (VoIP) and video calls require quick, reliable data transmission to ensure clear communication. The TOS field
in the IPv4 header can prioritize these packets, reducing delays and ensuring smooth audio and video quality.
4.Total Length: Length of header + Data (16 bits), which has a minimum value 20 bytes and the maximum is 65,535
bytes.
•Field Size: The Total Length field is 16 bits long.
•Maximum Value: In binary, a 16-bit field can represent values from 0000000000000000 (0) to 1111111111111111
(65535).
•Total Length = Header Length + Payload Size Header Length: This varies depending on whether there are additional
options included. The minimum header length is 20 bytes (IHL = 5).
•Payload Size: The actual data being transmitted, which can vary in size.
5. Identification: Unique Packet Id for identifying the group of fragments of a single IP datagram (16 bits)
6. Flags: 3 flags of 1 bit each : reserved bit (must be zero), do not fragment flag, more fragments flag (same order)
7. Fragment Offset: Represents the number of Data Bytes ahead of the particular fragment in the particular Datagram.
Specified in terms of number of 8 bytes, which has the maximum value of 65,528 bytes.
8.Time to live: TTL is a value in an IP packet that controls how long the packet can stay in the
network before it’s discarded.
10. Header Checksum: 16 bits header checksum for checking errors in the datagram header.
How It Works:
1.Calculation: The sender calculates the checksum value based on the header content.
2.Verification: The receiver recalculates the checksum to check for errors. If the calculated checksum matches the
one in the header, the header is considered intact. If not, the packet is likely corrupted and discarded.
Solution
Because the M bit is 1, it is either the first fragment or a
middle one. Because the offset value is 0, it is the first
fragment.
Example
Solution
To find the number of the first byte, we multiply the offset
value by 8. This means that the first byte number is 800. We
cannot determine the number of the last byte unless we
know the length.
Example
The network layer protocol in the TCP/IP protocol suite is currently IPv4. Although
IPv4 is well designed , data communication has evolved since the inception of
IPv4 in the 1970s. IPv4 has some deficiencies that make it unsuitable for the fast-
growing Internet.
IPv6 datagram header and payload
• Base Header in IPv6 refers to the fixed 40-byte header that appears at the start of every IPv6 packet. This header is
simpler and more efficient compared to the IPv4 header, with fewer fields and fixed size, making processing faster.
• Extension Headers: Optional headers used for additional features like routing, fragmentation, security (e.g.,
Authentication Header, Encapsulation Security Payload), and options.
• Upper Layer Protocol Data: This is the actual data from the upper-layer protocols (like TCP, UDP) or
applications. The size of the payload is defined in the Payload Length field in the header.
Format of an IPv6 datagram
•Version (4 bits):
•Identifies the IP version. For IPv6, this value is always 6.
PRI stands for Primary Rate Interface. It's a type of phone line used by businesses to handle many calls at the
same time.
It has multiple channels: 23 for voice or data (in North America) or 30 (in Europe).
These channels allow companies to make or receive many phone calls simultaneously over a single line.
•Flow Label (20 bits):Used for identifying flows of packets that require special handling, such as real-time traffic
(e.g., voice or video streams). It helps route packets belonging to the same flow efficiently.
•Payload Length (16 bits): Specifies the size of the data in the payload, excluding the base header. It can hold
values from 0 to 65,535 bytes. If the payload is larger than 64 KB, a separate jumbo payload extension can be
used.
•Next Header (8 bits):Identifies the type of header that immediately follows the IPv6 base header. It could
point to a higher-layer protocol like TCP/UDP or an IPv6 extension header (such as Routing, Fragmentation, or
Authentication headers).
•Hop Limit (8 bits):Similar to the Time to Live (TTL) field in IPv4. It specifies the maximum number of hops
the packet can take before being discarded. Each router that forwards the packet decreases this value by one.
When it reaches zero, the packet is discarded.
Comparison between IPv4 and IPv6 packet headers
Extension header types
TRANSITION FROM IPv4 TO IPv6
•Both old (IPv4) and new (IPv6) systems work together on the same network.
•Your device can talk to both IPv4 and IPv6 systems without a problem.
Tunneling strategy
•Imagine sending a letter in an envelope through a post office that only handles old-style letters (IPv4).
•The new letter (IPv6) is placed inside an old-style envelope (IPv4) so it can go through, and at the end,
it’s taken out.
Header translation strategy