IP Addressing & Subnetting
Imran Hossen
Adj. Lecturer, Dept. of CSE
Sonargaon University
E-mail: [email protected]
Contact: 01521234690/01729154878
IP Addresses
32 bits
version header Type of Service/TOS Total Length (in bytes)
(4 bits) length (8 bits) (16 bits)
flags
Identification (16 bits) Fragment Offset (13 bits)
(3 bits)
TTL Time-to-Live Protocol
Header Checksum (16 bits)
(8 bits) (8 bits)
Source IP address (32 bits)
Destination IP address (32 bits)
Ethernet Header IP Header TCP Header Application data Ethernet Trailer
Ethernet frame
2
What is an IP Address?
• An IP address is a unique global address for a network interface
• An IP address:
- is a 32 bit long identifier
- encodes a network number (network prefix)
and a host number
3
The address space of IPv4 is
232 or 4,294,967,296.
4
Number System
• You can probably work with decimal numbers much easier than with
the binary numbers needed by the computer.
• Working with binary numbers is time-consuming & error-prone.
5
Octets
• The 32-bit IP address is broken up into 4 octets, which are arranged
into a dotted-decimal notation scheme.
• An octet is a set of 8 bits & not a musical instrument.
• Example of an IP version 4:
172.64.126.52
6
Thinking in Binary
•The binary system uses only 2 values “0
& 1” to represent numbers in positions
representing increasing powers of 2.
•We all are accustomed to thinking &
working in the decimal system, which is
based on the number 10.
7
Thinking in Binary (Cont.)
•To most humans, the number 124
represents 100 + 20 + 4.
•To the computer, this number is
1111100, which is 64 (26) + 32 (25) + 16
(24) + 8 (23) + 4 (22) + 0 + 0
8
Converting to Decimal
• You’ll need to convert binary to decimal & vice versa to compute
subnets & hosts.
• So, it’s time for a quick review lesson in binary-to-decimal
conversion.
• There are 8 bits in an octet & each bit can only be a 1 or a 0.
9
Converting to Decimal (Cont.)
• What then do you suppose is the largest decimal number that can be
expressed in an octet?
Eight 1’s (1111 1111)
10
Converting to Decimal (Cont.)
• Now, for double the money, what is its equivalent decimal
value?
27 26 25 24 23 22 21 20
1 1 1 1 1 1 1 1
128 64 32 16 8 4 2 1
The binary number 1111 1111 converts into the decimal
number:
128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255
11
Dotted Decimal Notation
• IP addresses are written in a so-called dotted decimal notation
• Each byte is identified by a decimal number in the range [0..255]:
Example:
10000000 10001111 10001001 10010000
1st Byte 2nd Byte 3rd Byte 4th Byte
= 128 = 143 = 137 = 144
128.143.137.144
12
Network prefix and Host number
• The network prefix identifies a network and the host number
identifies a specific host (actually, interface on the network).
network prefix host number
• How do we know how long the network prefix is?
• The network prefix is implicitly defined (see class-based addressing)
• The network prefix is indicated by a netmask.
13
Example
• Example: ellington.cs.virginia.edu
128.143 137.144
• Network id is: 128.143.0.0
• Host number is: 137.144
• Network mask is: 255.255.0.0 or ffff0000
• Prefix notation: 128.143.137.144/16
• Network prefix is 16 bits long
14
Classful and Classless IP Addressing
17
Network mask
18
Classify and Define IPv4 Addresses
• Identify the historic method for assigning
addresses and the issues associated with the
method
19
Example
Find the class of each address:
a. 227.12.14.87
b. 193.14.56.22
c. 14.23.120.8
d. 252.5.15.111
20
Example
Find the class of each address:
a. 227.12.14.87
b. 193.14.56.22
c. 14.23.120.8
d. 252.5.15.111
Solution
a. The first byte is 227 (between 224 and 239); the class is D.
b. The first byte is 193 (between 192 and 223); the class is C.
c. The first byte is 14 (between 0 and 127); the class is A.
d. The first byte is 252 (between 240 and 255); the class is E.
21
Finding a network address using the default mask
22
Example
A router receives a packet with the destination address
201.24.67.32. Show how the router finds the network address of
the packet.
Solution
Since the class of the address is C, we assume that the router
applies the default mask for class C, 255.255.255.0 to find the
network address.
23
Problem
• I have 2 departments in my organization
• Each has about 125 hosts
• I would like to keep them in separate NWs
Abu Said Md. Rezoun, Lecturer, CSE, SU 24
Subnetting
25
Subnetting: Advantages
• Improved Network Performance: By breaking a large network into smaller
subnets, traffic is localized, reducing congestion and improving overall
performance.
• Improves efficiency of IP addresses by not consuming an entire address
space for each physical network. IPv4's limited address space.
• Reduces router complexity. Since external routers do not know about
subnetting, the complexity of routing tables at external routers is reduced.
• Enhanced Security: Different subnets can be isolated from each other,
providing an additional layer of security. Sensitive parts of the network can
be segmented, minimizing access to critical data.
26
Subnetting
• With subnetting, IP addresses use a 3-layer hierarchy:
• Network
• Subnet
• Host
27
Network mask and subnetwork mask
28
Challenge with IPv4 address
• I have 2 departments in my organization
-Each has about 125 hosts
-I would like to keep them in separate NWs
-I have been assigned an IP network address space of 192.168.1.0 /24
-This is one NW, and I need 2
-I cannot change the IP address NW portion
- But I can change the host portion
• Solution = Subnetting (dividing network into separate networks)
- Borrowing bits from the Host portion
30
Subnetting
• 192.168.1.0 /24
-24 bit is NW portion
-8 bits is Host portion
-I can borrow from the Host portion
• How many bits?
-2n ≥ # of subnets required
-n = # of bits to borrow
• So for our example we need to borrow:
-2n ≥ 2
-Therefore n=1 (we need to borrow 1 bit)
31
Subnetting
• The borrowed bits become part of my subnet mask/prefix (we borrowed
1 bit)
• Before subnetting /24 (255.255.255.0)
• After subnetting /25 (255.255.255.128)
-25 bit is NW portion & 7 bits is Host portion
• How many hosts can I have per subnet?
-2n – 2
-n = # of bits in the Host portion
• So for our example:
-2n – 2
-n=7
-Therefore we can have 126 hosts (128 – 2)
-(We needed 125)
32
Subnetting
• Our previous network was 192.168.1.0 /24
• How does our new networks look like?(two types
can be possible)
-192.168.1.00000000 /25 or 192.168.1.0 /25
-192.168.1.10000000 /25 or 192.168.1.128 /25
• And there special addresses?
- Network/subnet 192.168.1.0 /25
-Broadcast 192.168.1.01111111 or 192.168.1.127
-Host range 192.168.1.00000001 – 01111110 or .1 - .126
• So how about the other subnet – you calculate:
-Network/subnet 192.168.1.128 /25
-Broadcast 192.168.1.11111111 or 192.168.1.255
-Host range 192.168.1.10000001 – 11111110 or .129 - .254
33
Another Subnetting exercise
• You have 192.168.1.0 /24 and want 6 subnets
• Calculate
-6 subnets with prefix
-Broadcast address for each subnet
-Host range for each subnet
34
Acknowledgement
1. Data Communication and Networking, B. A. Forouzan et. al., Tata McGraw-Hill, 2nd
Edition, 2000.
2. Data and Computer Communication, W. Stallings, Prentice Hall of India, 5th Edition,
1997.
3. Prof. Dr. Md. Al Mehedi Hasan, Dept. of CSE, RUET
4. Abu Said Md. Rezoun, Lecturer, CSE, SU
35