IP addressing and Subnetting
IP addressing and Subnetting
IP addressing
For each IPv4 address, some portion of the high-order bits represents
the network address. At Layer 3, we define a network as a group of
hosts that have identical bit patterns in the network address portion
of their addresses.
Although all 32 bits define the IPv4 host address, we have a variable
number of bits that are called the host portion of the address. The
number of bits used in this host portion determines the number of
hosts that we can have within the network.
Within the address range of each IPv4 network, we have three types of
addresses:
Network Address
Broadcast Address
The IPv4 broadcast address is a special address for each network that
allows communication to all the hosts in that network. To send data to
all hosts in a network, a host can send a single packet that is
addressed to the broadcast address of the network.
The broadcast address uses the highest address in the network range.
This is the address in which the bits in the host portion are all 1s.
For the network 10.0.0.0 with 24 network bits, the broadcast address
would be 10.0.0.255. This address is also referred to as the directed
broadcast.
Host Addresses
Network Prefixes
How do we know how many bits represent the network portion and how
many bits represent the host portion? When we express an IPv4 network
address, we add a prefix length to the network address. The prefix
length is the number of bits in the address that gives us the network
portion. For example, in 172.16.4.0 /24, the /24 is the prefix length
- it tells us that the first 24 bits are the network address. This
leaves the remaining 8 bits, the last octet, as the host portion.
Networks are not always assigned a /24 prefix. Depending on the number
of hosts on the network, the prefix assigned may be different. Having
a different prefix number changes the host range and broadcast address
for each network.
Although most IPv4 host addresses are public addresses designated for
use in networks that are accessible on the Internet, there are blocks
of addresses that are used in networks that require limited or no
Internet access. These addresses are called private addresses.
Public Addresses
The vast majority of the addresses in the IPv4 unicast host range are
public addresses. These addresses are designed to be used in the hosts
that are publicly accessible from the Internet. Even within these
address blocks; there are many addresses that are designated for other
special purposes.
Private Addresses
Private space address blocks, as shown above, are set aside for use in
private networks. The use of these addresses need not be unique among
outside networks. Hosts that do not require access to the Internet at
large may make unrestricted use of private addresses. However, the
internal networks still must design network address schemes to ensure
that the hosts in the private networks use IP addresses
that are unique within their networking environment.
Many hosts in different networks may use the same private space
addresses. Packets using these addresses as the source or destination
should not appear on the public Internet. The router or firewall
device at the perimeter of these private networks must block or
translate these addresses. Even if these packets were to make their
way to the Internet, the routers would not have routes to forward them
to the appropriate private network.
NAT allows the hosts in the network to "borrow" a public address for
communicating to outside networks. While there are some limitations
and performance issues with NAT, clients for most applications can
access services over the Internet without noticeable problems.
1. Class A Blocks
2. Class B Blocks
3. Class C Blocks
The class C address space was the most commonly available of the
historic address classes. This address space was intended to provide
addresses for small networks with a maximum of 254 hosts. Class C
address blocks used a /24 prefix. This meant that a class C network
used only the last octet as host addresses with the three high-order
octets used to indicate the network address.
Class C address blocks set aside address space for class D (multicast)
and class E (experimental) by using a fixed value of 110 for the three
most significant bits of the high-order octet. This restricted the
address block for class C to 192.0.0.0 /16 to 223.255.255.0/16.
Although it occupied only 12.5% of the total IPv4 address space, it
could provide addresses to 2 million networks.
• Address
172.16.20.35
10101100.00010000.00010100.00100011
• subnet mask
255.255.255.224
11111111.11111111.11111111.11100000
• network address
172.16.20.32
10101100.00010000.00010100.00100000
Because the high order bits of the subnet masks are contiguous 1s,
there are only a limited number of subnet values within an octet. You
will recall that we only need to expand an octet if the network and
host division falls within that octet. Therefore, there are a limited
number 8 bit patterns used in address masks.
• 00000000 = 0
• 10000000 = 128
• 11000000 = 192
• 11100000 = 224
• 11110000 = 240
IP addressing-8
• 11111000 = 248
• 11111100 = 252
• 11111110 = 254
• 11111111 = 255
If the subnet mask for an octet is represented by 255, then all the
equivalent bits in that octet of the address are network bits.
Similarly, if the subnet mask for an octet is represented by 0, then
all the equivalent bits in that octet of the address are host bits. In
each of these cases, it is not necessary to expand this octet to
binary to determine the network and host portions.
The IPv4 host address is logically AND ed with its subnet mask to
determine the network address to which the host is associated. When
this AND ing between the address and the subnet mask is performed, the
result yields the network address.
Basic subnetting
For each subnet, examine the last octet in binary. The values in these
octets for the two networks are:
Subnet 1: 00000000 = 0
Subnet 2: 10000000 = 128
* END *
IP addressing-10
Lab Exercise
3. Find which of the following IPs are private IPs and which are
public IPs
IP addressing-12
* END *
Subnetting-1
> What is IP Address
It is a number containing 4 octets (bytes) separated by dots. Each octet can have a total of
256 values (0 - 255). It is used to identify the source and destination machine when
transmitting data through the internet.
Example:
192.168.0.1 [ Dotted Decimal Notation – Base 256 ]
10.1.0.255
255.255.255.0
2^1= 2
2^2= 4
2^3= 8
2^4= 16
2^5= 32
2^6= 64
2^7= 128
2^8= 256
128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255
1 0 0 0 0 0 0 0 = 128
1 1 0 0 0 0 0 0 = 192 [ 128 + 64 ]
1 1 1 0 0 0 0 0 = 224 [ 128 + 64 + 32 ]
1 1 1 1 0 0 0 0 = 240 [ 128 + 64 + 32 + 16 ]
0 1 1 1 1 1 1 1 = 127
0 0 0 0 1 1 1 1 = 15 [ 8 + 4 + 2 + 1 ]
0 = 255
-1 = 254
-2 = 252
-4 = 248
-8 = 240
One it can handle a large number of addresses(4.3 billion). Second is related to routing.
If every address were unique all routers on the internet would need to store address of
each and every machine on the internet. This would make effecient routing impossible.
Subnetting-2
The solution to this problem is to use a two or three level, heirarchical addressing
scheme that is structured by network and host or network, subnet and host. Rather than
all 32 bits being treated as a unique identifier as in flat addressing, a part of the address is
designated as network address and the other is designated as either the subnet or just the
node address.
There are three usable IP address classes - A, B and C. The first byte identifies the class.
Class to which a network belongs can be identified from the value of the first octet.
Class A - [ 0 - 127 ]
Class B - [ 128 - 191 ]
Class C - [ 192 - 223 ]
Class D - [ 224 - 239 ]
Class E - [ 240 - 255 ]
Class A network [ 1N + 3H ]
NOTE: Network address of all Zeroes and 127 is reserved. Host address of all Zeroes
and all ones is also reserved.
Class B network [ 2N + 2H ]
Class C network [ 3N + 1H ]
Reserved Addresses
127.0.0.1 – 127.255.255.255
> Subnetting
Imagine an organization that has 500 employees connected to single network. Each
employee is assigned a unique IP address. All the employees use the network for both
official and personal use. In this scenario, due to heavy traffic(transfer of data), the
packets become slow resulting in collision and retransmission. As there is no security
critical data can be accessed by any employee.
Subnet is a portion of network that uses bits from the host portion of the IP address and
reserves them to define a subnet address. The more the subnets, the less the bits available
for defining hosts.
The result of a bit-wise logical 'AND' operation between the IP address and the subnet
mask is a Network Address or Subnet Address.
Subnetting-5
There are three default subnet masks :
Subnetting is the process of splitting a single large network into a group of small
connected networks. Benefits of subnetting are:
- Reduced Network traffic : Routers create broadcast domains. Smaller the broadcast
domain you create lesser the network traffic on that network segment.
Subnets are created by taking bits from the host portion of the IP address and reserve
them to define Subnets. More the subnets, fewer the bits available for defining hosts.
Based on details above, determine Subnet Mask for entire network, Subnet ID for each
subnet and range of host IDs for each Subnet.
Subnetting-6
To correctly subnet a given network address into subnet addresses, ask
yourself the following questions:
- How many bits do I need to borrow ?
- What’s the subnet mask ?
- What’s the “magic number” or Blocksize ?
- What are the first three subnetwork addresses ?
Remember: you must borrow at least 2 bits for subnets and leave at
least 2 bits for host addresses.
2 bits borrowed allows 2^2 - 2 = 2 subnets
A simple formula:
Total Bits = Bits Borrowed + Bits Left
TB = BB + BL
Remember: we need to subtract two to provide for the subnetwork and broadcast
addresses.
Subnet Mask is a 32-bit value composed of 1s and 0s, which allows the
host to determine which part of the IP address represents network ID
and which part represents Host ID. The 1s in the Subnet mask
represent the positions that refer to network address.
In class C address only 8 bits are available for defining hosts. So the only class C subnet
masks possible are:
NOTE:
Assigning only 1 bit for Subnet is called Subnet Zero. Although it is used in production
environment, for CCNA exam it is invalid.
Maximum value of Subnet mask can only be /30, because atleast two bits must be kept
for host.
Subnet bits cannot be All Zero or All One at the same time.
Host Bits = 6
Hosts Possible = 2 ^ 6 = 64
Valid hosts = 64 - 2 = 62
Each Subnet will have 62 valid host IDs
Subnet bits = 3
Subnets Possible = 2 ^ 3 - 2 = 6
Host bits = 5
Host Possible = 2 ^ 5 - 2 = 30
Create the table below by writing down all the subnets by adding block size:
Class B network address has 16 bits available for host addressing. We can use upto 14
bits for subnetting.
Class A network address has 24 bits available for host addressing. We can use upto 22
bits for subnetting.
Subnet bits = x
Subnets possible = 2 ^ x - 2
Host bits = y
Block Size = 2 ^ y (or 256 - mask)
Valid Hosts = 2 ^ y - 2
For each class of IP Addresses, there is a set of IP addresses reserved for private
networks. They are :
Class A - 10.0.0.0/8
Class B - 172.16.0.0/12
Class C - 192.168.0.0/16
These IP addresses can be used for setting up internal IP networks at Home, Labs and
LANs behind a NAT or proxy server or router. They are always safe to use because
routers on the Internet will never forward packets coming from these addresses.
> How does the use of Private IP address saves valuable IP address space ?
If every host on the network had to have real routable IP addresses, we would have run
out of IP addresses years ago. But by using private IP addresses - ISPs, corporations and
home users only need a small group of real routable IP address to connect their network
to the internet. But when using private IP address for internal network it needs to be
translated to a routable IP address for connecting to the internet. To accomplish this task
we use NAT, which takes a private IP address and convert it for use on the internet.
NAT is a software which takes a private IP address and translates it into a real routable IP
address. NAT operates on a Cisco router. There are different flavors of NAT :
- Static NAT
- Dynamic NAT
- Overloading NAT (PAT)
> Exercise
To get the network address, we have to find the subnet mask, because it separates the
network portion and host portion of the IP address. Since it is a class A IP address, the
default subnet mask is 255.0.0.0. Applying subnet mask, network address becomes
12.0.0.0
> You have been assigned a class C network number of 200.133.175.0. Break the
network into 14 subnets of 14 nodes each.
2 ^ n - 2 = 14
2 ^ n = 16
n=4
255.255.255.11110000
255.255.255.240
256 - 240 = 16
Subnets : 16 32 48 64 80 .. .. ..
First Host : 17 33 49 65 81 .. .. ..
Last Host : 30 46 62 78 94 .. .. ..
Broadcast : 31 47 63 79 95 .. .. ..
> What is the maximum number of subnets that can be assigned to networks when
using the address 131.107.0.0 with a subnet mask of 255.255.240.0
131.107.0.0 is a class B IP address. Its default subnet mask is 255.255.0.0. But the given
subnet mask is 255.255.240.0. So no of subnet bits used is 4. No of possible subnets are:
2 ^ 4 - 2 = 14 Subnets
> Using the address 192.64.10.0/28 how many subnets and hosts are available.
It is a class C IP address. So default subnet mask is 255.255.255.0 Here 4 subnet bits are
used which leaves 4 bits for host. So no of possible subnets and host are:
Subnetting-11
2 ^ 4 - 2 = 14 Subnet and
2 ^ 4 - 2 = 14 host.
If somebody needs more than 254 hosts, they were automatically given a class B address
block which consist of 65534 host addresses. Most of them are simply not used.
Companies and organizations were allocated class A address block of over 16 million
host addresses. Only a tiny percentage of the allocated class A and class B address space
has ever been actually assigned to a host computer on the internet.
By eliminating class system addresses can be conserved. Accurately allocating only the
amount of address space that is actually needed to address can avoid space crisis for
many years.
VLSM networking is the process of taking one network and create many networks from it
using subnet masks of different length. Usually in classful routing all hosts and router
interfaces in a network have the same subnet mask. With VLSM we can have different
subnet masks for different subnets.
The problem with classful routing is that if you use subnet masks of different length in a
network running RIP.v1 and IGRP the network won't work. Also use of classful routing
protocols wastes valuable IP address space.
NOTE: In classful routing all hosts and router interfaces in a network have the same
subnet mask.
Classless routing allow us to use VLSM in a network running classless routing protocols.
RIP.v2, EIGRP and OSPF are classless routing protocols. These protocols support
advertisement of subnet information. Also use of VLSMs saves valuable IP address
space.
> Supernetting
Although internet is running out of Class B addresses, there are still class C addresses
available. With Supernetting it is possible to combine multiple class C addresses into the
equivalent of a class B. CIDR(Classless Inter Domain routing) was invented to keep the
internet from running out of IP addresses. Under CIDR, the subnet mask notation is
simplified, listing only 1s bits that start the mask. Classful addresses can easily be written
in CIDR notation.
Class A = /8
Class B = /16
Class C = /24
If you need about 1000 addresses, you could supernet 4 class C networks together:
The subnet 192.60.128.0 includes all the addresses from 192.60.128.0 to 192.60.131.255.
Network portion of the address is 22 bits long and the host portion is 10 bits long.
According to CIDR notation, instead of writing the address and subnet mask as
192.60.128.0 and 255.255.252.0 respectively, the network address can be written as
192.60.128.0/22.
> Example
.68 = 01000100
/28 = 11110000 (last octet)
AND ing = 01000000 = .64 [ OR use Blocksize Technique ]
Answer: 123.200.8.64
OR
> 4 Troubleshooting steps Cisco uses in a situation when a host cannot communicate
with the remote server.
2. Ping the IP address of localhost. It it works then your NIC card is functioning and the
TCP/IP stack on the host can communicate with the NIC. If it fails, there is a problem
with NIC card.
3. Ping the default gateway(router interface). If it works then your NIC can communicate
on the local network. It it fails then there is a physical network problem happening
anywhere from the NIC to the router.
4. Ping the remote server. If it works then there is IP communication between localhost
and remote server. If it fails then you have some type of remote physical network
Subnetting-14
problem. To troubleshoot it you must go to the server and work through steps 1 through 3
until you find the snag.
If user still can't communicate with the server after steps 1 through 4 are successful, then
you probably have some form of name resolution problem. Check your DNS settings.
Check for IP configuration errors.
Allows for more efficient use of IP space. Defined in RFC 1818. Less waste on smaller
subnets where fewer addresses are necessary. Used frequently if public address are used
internally.
2^n - 2 >= 90
2^n >= 92 [ 2^6 = 64, 2^7 = 128]
n = 7 host bits [remaining 25 network bits]
2^n – 2 >= 2
2^n >= 4
n = 2 host bits [remaining 30 network bits]
Using network 10.0.0.0. Create a mask for a subnet containing 300 hosts.
Blocks of Contiguous Addresses (4, 8,16, etc) are assigned to ISPs. ISPs assign IP
addresses to Customers in contiguous blocks. Blocks are summarized to reduce router
advertisements and route table size.
* END *
Exercises-1
1.. Which of the following hardware devices can be used to segment your network.
a. Repeater
b. Switch
c. Router (Answer)
d. Media converter
2. Using a class C Address range 192.168.21.12, your network needs twenty eight
subnets. Which subnet mask should you use ?
2^n - 2 >= 28
2^n >= 30
n=5
Subnet mask(last octet) = 11111000 = 248
Subnet mask = 255.255.255.248
3. You have been assigned a Class C network address. Your manager has asked to
create 30 subnets with at least 5 hosts per subnet for the different departments in
your organization. What should the subnet mask be to create 30 subnets.
2^n - 2 >= 28
2^n >= 30
n=5
Subnet mask(last octet) = 11111000 = 248
Subnet mask = 255.255.255.248 (Answer)
4. Your ISP has provided you the following Class B network range 131.107.0.0/24.
Which of the following statement is true regarding this network ? (Choose any two)
Answer: A and D
Exercises-2
5. Using the following address and subnet mask 195.106.14.0/24, what is the total
number of networks and the total number of hosts per network.
Solution
- Class C address [ Default subnet mask is 255.255.255.0 ]
- ie: 8 + 8 + 8 + 0
- 8 bits of last octet alone is left for subnetting.
Answer: 1 network with 254 hosts
6. How many usable host addresses are available on a class B, unsubnetted network
?
Answer: 2^16 - 2
Answer: 2^14
8. In a class A address where 4 bits have been borrowed for subnetting. How many
bits are left for host addresses.
Answer: 20 bits
9. What is the broadcast address of the second usable subnet in class C where 4 bits
were borrowed.
a. N.N.N.255
b. N.N.N.47 => Answer
c. N.N.N.95
d. N.N.N.63
Solution:
- Class C subnet mask [255.255.255.0]
- 4 bits are borrowed [255.255.255.11110000]
- ie: 255.255.255.240
- Block size = 256 - 240 = 16
- Subnets are:
N.N.N.16
N.N.N.32
N.N.N.48
N.N.N.64
.. .. ..
10. Hosts that reside on a network with the same network ID can communicate
directly with each other.
11. Given a class A address that has been subnetted(8 bits borrowed), what is the
subnet mask ?
Exercises-3
Answer: 255.255.0.0
12. Using a class C address you need 5 subnets with a maximum of 17 hosts on each
of these subnets. which subnet mask would you use ?
Solution:
- Class C address [Default mask : 255.255.255.0]
- 2^n - 2 = 5
- 2^n = 7
- n = 3 [ 1110 0000 ]
Answer: 255.255.255.224
13.
Class B address is used (172.16.0.0) . Class C cannot be used because we need 57 subnet,
each with approximately 200 hosts, which is not possible with a class C address. (If two
bits of last octet are used as subnet bits, only 6 bits are left for hosts)
255.255.0.0
2^n - 2 <= 57
Exercises-4
2^n <= 59
2^n ~ 64
n=6
- Allocate the Subnet, Host and Broadcast address using block size 4.
Answer
255.0.0.0
255.255.11111000.00000000
255.255.248.0
5. Allocate Subnets. Start incrementing by 8 until you come to the range the specified
host lives in:
10.48.8.0
10.48.16.0
Exercises-5
10.48.24.0
10.48.32.0 (Answer) [10.48.32.1 - 10.48.39.254] [10.48.39.255]
10.48.40.0
10.48.32.0
10.48.39.255
10.48.32.1 - 10.48.39.254
Any increment of 8.
256/8 = 32 (Total subnets)