Chapter 3 - Internet Protocol and IP Addressing
Chapter 3 - Internet Protocol and IP Addressing
September 2020
1
Chapter Four
Internet Protocol and IP
Addressing
2
IPv4 Address
• IPv4 addresses are unique.
• They are unique in the sense that each address defines one, and only
one, connection to the Internet.
• Two devices on the Internet can never have the same address at the
same time.
• However, if a device has two connections to the Internet, via two
networks, it has two IPv4 addresses.
• The IPv4 addresses are universal in the sense that the addressing
system must be accepted by any host that wants to be connected to the
Internet.
3
Address Space
• A protocol like IPv4 that defines addresses has an address space.
• An address space is the total number of addresses used by the protocol.
• If b protocol uses b bits to define an address, the address space is 2b because
each bit can have two different values (0 or 1).
• IPv4 uses 32-bit addresses, which means that the address space is 232 or
4,294,967,296 (more than four billion).
• Theoretically, if there were no restrictions, more than 4 billion devices could be
connected to the Internet.
• There are three common notations to show an IPv4 address: binary notation (base
2), dotted-decimal notation (base 256), and hexadecimal notation (base 16).
• The most prevalent, however, is base 256.
4
Address Space - Binary Notation: Base 2
5
Address Space - Dotted-Decimal Notation: Base 256
• To make the IPv4 address more compact and easier to read, an IPv4
address is usually written in decimal form with a decimal point (dot)
separating the bytes.
• This format is referred to as dotted-decimal notation.
• because each byte (octet) is only 8 bits, each number in the dotted-
decimal notation is between 0 and 255.
6
Address Space - Hexadecimal Notation: Base 16
0X810B0BEF
810B0BEF16
7
Range of Addresses
• We often need to deal with a range of addresses instead of one single
address.
• We sometimes need to find the number of addresses in a range if the
first and last address is given.
• Other times, we need to find the last address if the first address and the
number of addresses in the range are given.
• In this case, we can perform subtraction or addition operations in the
corresponding base (2, 256, or 16).
• Alternatively, we can covert the addresses to decimal values (base 10)
and perform operations in this base.
8
Classfull Addressing
• IP addresses, when started a few decades ago, used the concept of
classes.
• This architecture is called classful addressing.
• In the mid-1990s, a new architecture, called classless addressing, was
introduced that supersedes the original architecture.
• In classful addressing, the IP address space is divided into five classes:
A, B, C, D, and E.
• Each class occupies some part of the whole address space.
9
Classfull Addressing
10
Cont’d…
• We can find the class of an address when the address is given either in binary or
dotted decimal notation.
• In the binary notation, the first few bits can immediately tell us the
class of the address; in the dotted-decimal notation, the value of the first byte can
give the class of an address.
224 - 239
240 - 255
11
Cont’d…
1 1 1 1
Start
0 0 0 0
13
Classes and Blocks - Blocks in Class A
• One problem with classful addressing is that each class is divided into a fixed number of blocks
with each block having a fixed size.
• Since only 1 byte in class A defines the netid and the leftmost bit should be 0, the next 7 bits can
be changed to find the number of blocks in this class.
• Therefore, class A is divided into 27 = 128 blocks that can be assigned to 128 organizations (the
number is less because some blocks were reserved as special blocks).
• However, each block in this class contains 16,777,216 addresses, which means the organization
should be a really large one to use all these addresses.
• Many addresses are wasted in this class.
14
Classes and Blocks - Blocks in Class B
• Since 2 bytes in class B define the class and the two leftmost bit should be 10 (fixed), the next 14
bits can be changed to find the number of blocks in this class.
• Therefore, class B is divided into 214 = 16,384 blocks that can be assigned to 16,384 organizations
(the number is less because some blocks were reserved as special blocks).
• However, each block in this class contains 65,536 addresses.
• Not so many organizations can use so many addresses.
• Many addresses are wasted in this class.
15
Classes and Blocks - Blocks in Class C
• Since 3 bytes in class C define the class and the three leftmost bits should be 110
(fixed), the next 21 bits can be changed to find the number of blocks in this class.
• Therefore, class C is divided into 221=2,097,152 blocks, in which each block
contains 256 addresses, that can be assigned to 2,097,152 organizations (the
number is less because some blocks were reserved as special blocks).
• Each block contains 256 addresses.
• However, not so many organizations were so small as to be satisfied with a class
C block.
16
Classes and Blocks - Blocks in Class D
• There is just one block of class D addresses.
• It is designed for multicasting.
• Each address in this class is used to define one group of hosts on the
Internet.
• When a group is assigned an address in this class, every host that is a
member of this group will have a multicast address in addition to its
normal (unicast) address.
17
Classes and Blocks - Blocks in Class E
• There is just one block of class E addresses.
• It was designed for use as reserved addresses
18
Two-Level Addressing
• The whole purpose of IPv4 addressing is to define a
destination for an Internet packet (at the network layer).
• When classful addressing was designed, it was assumed that
the whole Internet is divided into many networks and each
network connects many hosts.
The range of addresses allocated to an
organization in classful addressing
was a block of addresses in
Class A, B, or C.
19
Cont’d…
• Since all addresses in a network belonged to a single block, each
address in classful addressing contains two parts: netid and hostid.
• The netid defines the network; the hostid defines a particular host
connected to that network.
20
Information extraction in classful addressing
• Given any address in the block, we normally like to know three pieces
of information about the block: the number of addresses, the first
address, and the last address.
• Before we can extract these pieces of information, we need to know
the class of the address.
• After the class of the block is found, we know the value of n, the
length of netid in bits.
21
Cont’d…
1. The number of addresses in the block, N, can be found using N =232−n
2. To find the first address, we keep the n leftmost bits and set the (32 − n)
rightmost bits all to 0s.
3. To find the last address, we keep the n leftmost bits and set the (32 − n)
rightmost bits all to 1s.
22
Cont’d…
Example
An address in a block is given as 73.22.17.25. Find the number of
addresses in the block, the first address, and the last address.
Solution
1. The number of addresses in this block is N = 232−n = 16,777,216.
2. To find the first address, we keep the leftmost 8 bits and set the rightmost 24
bits all to 0s. The first address is 73.0.0.0/8, in which 8 is the value of n.
3. To find the last address, we keep the leftmost 8 bits and set the rightmost 24
bits all to 1s. The last address is 73.255.255.255.
23
Cont’d…
24
Cont’d…
Example
An address in a block is given as 180.8.17.9. Find the number of
addresses in the block, the first address, and the last address.
Solution
1. The number of addresses in this block is N = 232−n = 65,536.
2. To find the first address, we keep the leftmost 16 bits and set the
rightmost 16 bits all to 0s. The first address is 180.8.0.0/16, in which 16
is the value of n.
3. To find the last address, we keep the leftmost 16 bits and set the
rightmost 16 bits all to 1s. The last address is 180.8.255.255.
25
Cont’d…
26
Cont’d…
Example
An address in a block is given as 200.11.8.45. Find the number of
addresses in the block, the first address, and the last address.
Solution
1. The number of addresses in this block is N = 232−n = 256.
2. To find the first address, we keep the leftmost 24 bits and set the
rightmost 8 bits all to 0s. The first address is 200.11.8.0/24, in which
24 is the value of n.
3. To find the last address, we keep the leftmost 24 bits and set the
rightmost 8 bits all to 1s. The last address is 200.11.8.255
27
Cont’d…
28
Network Address
• The network address is actually the identifier of the network; each
network is identified by its network address.
29
Network Mask
• The routers in the Internet normally use an algorithm to extract the network
address from the destination address of a packet.
• To do this, we need a network mask.
• A network mask or a default mask in classful addressing is a 32-bit number with
n leftmost bits all set to 1s and (32 − n) rightmost bits all set to 0s.
• Since n is different for each class in classful addressing, we have three default
masks in classful addressing
30
Cont’d…
• To extract the network address from the destination address of a packet, a router uses the
AND operation.
• When the destination address (or any address in the block) is ANDed with the default
mask, the result is the network address.
• The router applies the AND operation on the binary (or hexadecimal representation) of
the address and the mask.
• The default mask can also be used to find the number of addresses in the block and the
last address in the block, but we discuss these applications in classless addressing.
31
Cont’d…
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.
255
67
32
Cont’d…
Example
• A router receives a packet with the destination address 172.20.55.13.
Show how the router finds the network address of the packet.
Solution
• Since the class of the address is B, we assume that the router applies
the default mask for class B, 255.255.0.0 to find the network address.
172 20 55 13
0
172 20 0
33
Three-Level Addressing: Subnetting
• The IP addresses were originally designed with two levels of addressing.
• To reach a host on the Internet, we must first reach the network and then the
host.
• It soon became clear that we need more than two hierarchical levels, for two
reasons.
First, an organization that was granted a block in class A or B needed to divide its large
network into several subnetworks for better security and management.
Second, since the blocks in class A and B were almost depleted and the blocks in class C
were smaller than the needs of most organizations, an organization that has been granted a
block in class A or B could divide the block into smaller subblocks and share them with
other organizations.
• The idea of splitting a block to smaller blocks is referred to as subnetting.
• In subnetting, a network is divided into several smaller subnetworks (subnets)
with each subnetwork having its own subnetwork address. 34
Cont’d…
Example
35
Cont’d…
36
How to Create Subnets
To create a subnet follow these steps:
1. Determine the number of required network IDs:
• One for each subnet
• One for each wide area network connection
2. Determine the number of required host IDs per subnet:
• One for each TCP/IP host
• One for each router interface
3. Based on the above requirements, create the following:
• One subnet mask for your entire network
• A unique subnet ID for each physical segment
• A range of host IDs for each subnet
37
Subnet Mask
• The network mask is used when a network is not subnetted.
• When we divide a network to several subnetworks, we need to create a
subnetwork mask (or subnet mask) for each subnetwork.
• A subnetwork has subnetid and hostid
38
Subnetting Class C Addresses
• In a Class C address, only 8 bits are available for defining the hosts.
• This means that the only Class C subnet masks can be the following:
• We can’t use a /31 or /32 because we have to have at least 2 host bits for assigning IP addresses to
hosts. 39
Subnetting a Class C Address: The Fast Way!
• When you’ve choosen a possible subnet mask for your network and
need to determine the number of subnets, valid hosts, and broadcast
addresses of a subnet that the mask provides, all you need to do is
answer five simple questions:
How many subnets does the chosen subnet mask produce?
How many valid hosts per subnet are available?
What are the valid subnets?
What’s the broadcast address of each subnet?
What are the valid hosts in each subnet?
40
Cont’d…
Here’s how you get the answers to those five big questions:
• How many subnets? 2x = number of subnets. x is the number of masked bits, or the
1s. For example, in 11000000, the number of 1s gives us 22 subnets. In this example,
there are 4 subnets.
• How many hosts per subnet? 2y – 2 = number of hosts per subnet. y is the number
of unmasked bits, or the 0s. For example, in 11000000, the number of 0s gives us 26
– 2 hosts. In this example, there are 62 hosts per subnet. You need to subtract 2 for
the subnet address and the broadcast address, which are not valid hosts.
• What are the valid subnets? 256 – subnet mask = block size, or increment number.
An example would be 256 – 192 = 64. The block size of a 192 mask is always 64.
Start counting at zero in blocks of 64 until you reach the subnet mask value and
these are your subnets. 0, 64, 128, 192.
41
Cont’d…
• What’s the broadcast address for each subnet? Now here’s the really easy
part. Since we counted our subnets in the last section as 0, 64, 128, and 192,
the broadcast address is always the number right before the next subnet. For
example, the 0 subnet has a broadcast address of 63 because the next subnet
is 64. The 64 subnet has a broadcast address of 127 because the next subnet
is 128. And so on. And remember, the broadcast address of the last subnet is
always 255.
• What are the valid hosts? Valid hosts are the numbers between the subnets,
omitting the all 0s and all 1s. For example, if 64 is the subnet number and
127 is the broadcast address, then 65–126 is the valid host range—it’s always
the numbers between the subnet address and the broadcast address.
42
Practice Example #1C: 255.255.255.128 (/25)
43
Cont’d…
• What’s the broadcast address for each subnet? The number right before the value
of the next subnet is all host bits turned on and equals the broadcast address. For
the zero subnet, the next subnet is 128, so the broadcast of the 0 subnet is 127.
• What are the valid hosts? These are the numbers between the subnet and
broadcast address. The easiest way to find the hosts is to write out the subnet
address and the broadcast address. This way, the valid hosts are obvious. The
following table shows the 0 and 128 subnets, the valid host ranges of each, and the
broadcast address of both subnets:
44
Practice Example #2C: 255.255.255.192 (/26)
• Network address = 192.168.10.0
• Subnet mask = 255.255.255.192
Now, let’s answer the big five:
• How many subnets? Since 192 is 2 bits on (11000000), the answer would
be 22 = 4 subnets.
• How many hosts per subnet? We have 6 host bits off (11000000),
so the equation would be 26 – 2 = 62 hosts.
• What are the valid subnets? 256 – 192 = 64. Remember, we start at zero
and count in our block size, so our subnets are 0, 64, 128, and 192.
45
Cont’d…
• What’s the broadcast address for each subnet? For the zero subnet, the
next subnet is 64, so the broadcast address for the zero subnet is 63.
• What are the valid hosts? The valid hosts are obvious. The following
table shows the 0, 64, 128, and 192 subnets, the valid host ranges of
each, and the broadcast address of each subnet:
The subnets (do this first) 0 64 128 192
47
Cont’d…
• To answer the last two questions, first just write out the subnets, then
write out the broadcast addresses—the number right before the next
subnet. Last, fill in the host addresses. The following table gives you
all the subnets for the 255.255.255.224 Class C subnet mask:
48
What Do We Know?
/25 What do we know about a /25?
/28 What do we know about a /28?
• 128 mask
• 240 mask
• 1 bits on and 7 bits off (10000000)
• 4 bits on and 4 bits off
• Block size of 128
• Block size of 16
• 2 subnets, each with 126 hosts
• 16 subnets, each with 14 hosts
/26 What do we know about a /26?
/29 What do we know about a /29?
• 192 mask
• 248 mask
• 2 bits on and 6 bits off (11000000)
• 5 bits on and 3 bits off
• Block size of 64
• Block size of 8
• 4 subnets, each with 62 hosts
• 32 subnets, each with 6 hosts
/27 What do we know about a /27?
/30 What do we know about a /30?
• 224 mask
• 252 mask
• 3 bits on and 5 bits off (11100000)
• 6 bits on and 2 bits off
• Block size of 32
• Block size of 4
• 8 subnets, each with 30 hosts
• 64 subnets, each with 2 hosts 49
Subnetting Class B Addresses
• all the possible Class B subnet masks
50
Practice Example #1B: 255.255.128.0 (/17)
52
Practice Example #2B: 255.255.192.0 (/18)
• Network address = 172.16.0.0
• Subnet mask = 255.255.192.0
• Subnets? 22 = 4.
• Hosts? 214 – 2 = 16,382 (6 bits in the third octet, and 8 in the fourth).
• Valid subnets? 256 – 192 = 64. 0, 64, 128, 192. Remember that the
subnetting is performed in the third octet, so the subnet numbers are
really 0.0, 64.0, 128.0, and 192.0, as shown in the next table.
• Broadcast address for each subnet?
• Valid hosts?
53
Cont’d..
• The following table shows the four subnets available, the valid host
range, and the broadcast address of each:
54
Practice Example #3B: 255.255.240.0 (/20)
• The following table shows the first four subnets, valid hosts, and
broadcast addresses in a Class B 255.255.240.0 mask:
56
Subnetting Class A Addresses
• Class A subnetting is not performed any differently than Classes B and C, but
there are 24 bits to play with instead of the 16 in a Class B address and the 8 in a
Class C address.
57
Practice Example #1A: 255.255.0.0 (/16)
• Class A addresses use a default mask of 255.0.0.0, which leaves 2 2 bits for subnetting
since you must leave 2 bits for host addressing.
• Network Address = 10.0.0.0
• Subnet Mask = 255.255.0.0
• Subnets? 28 = 256.
• Hosts? 216 – 2 = 65,534.
• Valid subnets? What is the interesting octet? 256 – 255 = 1. 0, 1, 2, 3, etc. (all in the
second octet). The subnets would be 10.0.0.0, 10.1.0.0, 10.2.0.0, 10.3.0.0, etc., up to
10.255.0.0.
• Broadcast address for each subnet?
• Valid hosts?
58
Cont’d…
• The following table shows the first two and last two subnets, valid
host range, and broadcast addresses for the private Class A 10.0.0.0
network:
59
Practice Example #2A: 255.255.240.0 (/20)
61
Practice Example #3A: 255.255.255.192 (/26)
• Let’s do one more example using the second, third, and fourth octets for
subnetting.
• Network Address = 10.0.0.0
• Subnet Mask = 255.255.255.192
• Subnets? 218 = 262,144.
• Hosts? 26 – 2 = 62.
• Valid subnets? In the second and third octet, the block size is 1, and in the
fourth octet, the block size is 64.
• Broadcast address for each subnet?
• Valid hosts?
62
Cont’d…
• The following table shows the first four subnets and their valid hosts and
broadcast addresses in the Class A 255.255.255.192 mask:
• The following table shows the last four subnets and their valid hosts and broadcast
addresses:
63