IP Addressing and Subnetting
(Modified version of slides from Karim El Defrawy)
Sunimal Rathnayake
1
IP Addressing (IPv4)
• IP address: 32-bit identifier
for host, router interface
• interface: connection [Link]
between host/router and [Link]
physical link [Link]
[Link] [Link]
– router’s typically have
multiple interfaces
– host typically has one or two [Link]
[Link]
[Link]
interfaces (e.g., wired
Ethernet, wireless 802.11)
• IP addresses associated [Link] [Link]
with each interface
• Switches (layer 2) do not
have IPs associated with
interfaces 2
Subnets
• IP address: [Link]
–subnet part - high
order bits [Link] [Link]
[Link] [Link]
–host part - low order
[Link]
bits [Link] [Link]
• what’s a subnet ?
subnet
–device interfaces with
same subnet part of [Link] [Link]
IP address
–can physically reach
network consisting of 3 subnets
each other without
intervening router
3
IP Addressing: CIDR
CIDR: Classless InterDomain Routing
▪ subnet portion of address of arbitrary length
▪ address format: a.b.c.d/x, where x is # bits in
subnet portion of address
subnet host
part part
11001000 00010111 00010000 00000000
[Link]/23
4
Network Address and Broadcast Address
• Network Address is the first address of the IP block
– E.g. host IP: [Link]/24
– Network address is: [Link]
• Broadcast Address is the last address of the IP block
– E.g. Host IP: [Link]/24
– Broadcast address is: [Link]
5
Private IP Blocks
• The Internet Assigned Numbers Authority (IANA) has
assigned several address ranges to be used by private
networks.
• Class A: [Link] to [Link]
• Class B: [Link] to [Link]
• Class C: [Link] to [Link]
• An IP address within these ranges is therefore considered
non-routable, as it is not unique can use without any
coordination with IANA or an Internet registry. Addresses
within this private address space are only unique within a
given private network.
• All addresses outside these ranges are considered public. 6
More Information on Subnetting
Before subnetting:
• In any network (or subnet) one can use most of the IP
addresses for host addresses.
• One loses two addresses for every network or subnet.
1. Network Address - One address is reserved to that of the
network.
2. Broadcast Address – One address is reserved to address all
hosts in that network or subnet.
Subnet Example
Network address [Link] with /16 network mask
Network Network Host Host
172 19 0 0
Subnet Example
Network address [Link] with /16 network mask
Network Network Host Host
172 19 0 0
Using Subnets: subnet mask [Link] or /24
Network Network Subnet Host
Network Mask:
[Link] or /16 11111111 11111111 00000000 00000000
Subnet Mask:
[Link] or /24
11111111 11111111 11111111 00000000
• Applying a mask which is larger than the default subnet
mask, will divide your network into subnets.
• Subnet mask used here is [Link] or /24
Subnet Example
Network address [Link] with /16 network mask
Using Subnets: subnet mask [Link] or /24
Network Network Subnet Host
172 19 0 Host Subnets
172 19 1 Host
172 19 2 Host
255
172 19 3 Host Subnets
172 19 etc. Host 28 - 1
172 19 254 Host
Cannot use last
172 19 255 Host subnet as it
contains broadcast
address
Subnet Example
Network address [Link] with /16 network mask
Using Subnets: subnet mask [Link] or /24
Network Network Subnet Host
172 19 0 0 Subnets
Addresses
172 19 1 0
172 19 2 0
255
172 19 3 0 Subnets
172 19 etc. 0 28 - 1
172 19 254 0
Cannot use last
172 19 255 0 subnet as it
contains broadcast
address
Subnet Example
Class B address [Link] with /16 network mask
Using Subnets: subnet mask [Link] or /24
Network Network Subnet Hosts Hosts
Addresses
172 19 0 1 254
172 19 1 1 254
172 19 2 1 254
172 19 3 1 254
172 19 etc. 1 254
172 19 254 1 254
Each subnet has
172 19 255 Host 254 hosts, 28 – 2
Subnet Example
Network address [Link] with /16 network mask
Using Subnets: subnet mask [Link] or /24
Network Network Subnet Host
172 19 0 255 Broadcast
Addresses
172 19 1 255
172 19 2 255
255
172 19 3 255 Subnets
172 19 etc. 255 28 - 1
172 19 254 255
Cannot use last
172 19 255 255 subnet as it
contains broadcast
address
Subnet Example
Network address [Link] with /16 network mask
Using Subnets: subnet mask [Link] or /24
[Link]/24 [Link]/24
[Link]/24 [Link]/24
Important things to remember about Subnetting
• You can only subnet the host portion, you do not have control of the
network portion.
• Subnetting does not give you more hosts, it only allows you to divide your
larger network into smaller networks.
• When subnetting, you will actually lose host adresses:
– For each subnet you lose the address of that subnet
– For each subnet you lose the broadcast address of that subnet
– You “may” lose the first and last subnets
• Why would you want to subnet?
– Divide larger network into smaller networks
– Limit layer 2 and layer 3 broadcasts to their subnet.
– Better management of traffic.
Subnetting – Example
• Host IP Address: [Link]
• Network Mask: [Link] (or /16)
• Subnet Mask: [Link] (or /26)
Given the following Host IP Address, Network Mask and Subnet mask find the
following information:
• Major Network Information
– Major Network Address
– Major Network Broadcast Address
– Range of Hosts if not subnetted
• Subnet Information
– Subnet Address
– Range of Host Addresses (first host and last host)
– Broadcast Address
• Other Subnet Information
– Total number of subnets
– Number of hosts per subnet
Major Network Information
• Host IP Address: [Link]
• Network Mask: [Link]
• Subnet Mask: [Link]
• Major Network Address: [Link]
• Major Network Broadcast Address: [Link]
• Range of Hosts if not Subnetted: [Link] to [Link]
Step 1: Convert to Binary
128 64 32 16 8 4 2 1
138. 101. 114. 250
IP Address 10001010 01100101 01110010 11111010
Mask 11111111 11111111 11111111 11000000
255. 255. 255. 192
Step 1:
Translate Host IP Address and Subnet Mask into binary notation
Step 2: Find the Subnet Address
138. 101. 114. 250
IP Address 10001010 01100101 01110010 11111010
Mask 11111111 11111111 11111111 11000000
Network 10001010 01100101 01110010 11000000
138 101 114 192
Step 2:
Determine the Network (or Subnet) where this Host address lives:
1. Draw a line under the mask
2. Perform a bit-wise AND operation on the IP Address and the Subnet
Mask
Note: 1 AND 1 results in a 1, 0 AND anything results in a 0
3. Express the result in Dotted Decimal Notation
4. The result is the Subnet Address of this Subnet or “Wire” which is
[Link]
Step 2: Find the Subnet Address
138. 101. 114. 250
IP Address 10001010 01100101 01110010 11111010
Mask 11111111 11111111 11111111 11000000
Network 10001010 01100101 01110010 11000000
138 101 114 192
Step 2:
Determine the Network (or Subnet) where this Host address lives:
Quick method:
1. Find the last (right-most) 1 bit in the subnet mask.
2. Copy all of the bits in the IP address to the Network Address
3. Add 0’s for the rest of the bits in the Network Address
Step 3: Subnet Range / Host Range
G.D. S.D.
IP Address 10001010 01100101 01110010 11 111010
Mask 11111111 11111111 11111111 11 000000
Network 10001010 01100101 01110010 11 000000
subnet → host →
counting range counting
range
Step 3:
Determine which bits in the address contain Network (subnet)
information and which contain Host information:
• Use the Network Mask: [Link] and divide (Great Divide) the
from the rest of the address.
• Use Subnet Mask: [Link] and divide (Small Divide) the
subnet from the hosts between the last “1” and the first “0” in the
subnet mask.
Step 4: First Host / Last Host
G.D. S.D.
IP Address 10001010 01100101 01110010 11 111010
Mask 11111111 11111111 11111111 11 000000
Network 10001010 01100101 01110010 11 000000
subnet → host →
counting range counting
range
First Host 10001010 01100101 01110010 11 000001
138 101 114 193
Last Host 10001010 01100101 01110010 11 111110
138 101 114 254
Broadcast 10001010 01100101 01110010 11 111111
138 101 114 255
Host Portion
• Subnet Address: all 0’s
• First Host: all 0’s and a 1 in rightmost bit
• Last Host: all 1’s and a 0 in rightmost bit
• Broadcast: all 1’s
Step 5: Total Number of Subnets
G.D. S.D.
IP Address 10001010 01100101 01110010 11 111010
Mask 11111111 11111111 11111111 11 000000
Network 10001010 01100101 01110010 11 000000
subnet → host →
counting range counting
range
• TotalFirst
number
Host of 10001010
subnets 01100101 01110010 11 000001
138 101 114 193
– Number of subnet bits 10
Last Host 10001010 01100101 01110010 11 111110
– 2 = 1,024
10
138 101 114 254
– 1,024 total subnets
Broadcast 10001010 01100101 01110010 11 111111
138 101 114 255
• Subtract one “if” all-zeros subnet cannot be used
• Subtract one “if” all-ones subnet cannot be used
Step 6: Total Number of Hosts per Subnet
G.D. S.D.
IP Address 10001010 01100101 01110010 11 111010
Mask 11111111 11111111 11111111 11 000000
Network 10001010 01100101 01110010 11 000000
subnet → host →
counting range counting
range
• TotalFirst
number
Host of 10001010
hosts per subnet
01100101 01110010 11 000001
138 101 114 193
– Number of host bits 6
Last Host 10001010 01100101 01110010 11 111110
– 2 = 64
6
138 101 114 254
– 64Broadcast
host per subnets
10001010 01100101 01110010 11 111111
138 101 114 255
• Subtract one for the subnet address
• Subtract one for the broadcast address
– 62 hosts per subnet