Notes: Networks, Subnets, and CIDR

About
Classful Networks
Classless Networks
Reserved IPv4 Address Spaces

About

There are networks known as classful and classless. The first plan adopted
and used widely by the Internet community were classful networks. So named
because three address classes: A, B, and C were defined with assignable IP
address space. These classes, however, disproportionately distributed the
number of available IP addresses. A new method to identify networks and
allocate IP addresses was needed to support the continued growth of the
Internet. The new method is named classless because it does away with the idea
of classes altogether. It is commonly known as Classless Inter-Domain Routing
(CIDR). It is much more flexible than classful networks and is what the
Internet uses today. Classful networks are still used by many devices, so
it is important to understand both classful and classless networking.

IPv4 Overview

An IPv4 address contains 32-bits. It is usually represented in dotted decimal
quad notation so it is easier to read and communicate. Computers, of course, read this
information in binary form. And in order to calculate subnet masks, network
addresses, and broadcast addresses, the binary value must be known.

Converting a dotted decimal IP address to binary is simple. Given that there
are 4 numbers, each decimal number is represented in binary as an octet. The high
order bits in binary are always the leftmost ones.

Counting in Binary

Binary
1
1
1
1
1
1
1
1

Powers of 2
2

7

2

6

2

5

2

4

2

3

2

2

2

1

2

0

Decimal
128
64
32
16
8
4
2
1

The largest single value an IP address may have in decimal is 255 since this
is the sum when all of the bits are added together, i.e.
27 + 26 + 25 +
24 + 23 + 22 +
21 + 20. When all of the bits are
turned off, the number is 0. The range of an IP address is therefore 0 – 255, 256
values.

The following is how the IP address 68.125.16.250 would be converted and
represented in binary form.

Decimal
Broken Down
Binary Addition
Binary

First Octet
68
64 + 4
2

6

+ 2

2

01000100

Second Octet
125
64 + 32 + 16 + 8 + 4 + 1
2

6

+ 2

5

+ 2

4

+ 2

3

+ 2

2

+ 2

0

01111101

Third Octet
16
16
2

4

00010000

Fourth Octet
250
128 + 64 + 32 + 16 + 8 + 2
2

7

+ 2

6

+ 2

5

+ 2

4

+ 2

3

+ 2

1

11111010

The end result looks like 01000100011111010001000011111010.

Classful Networks

Once an IP address is represented in binary format, the class of network can
be determined rather easily. Beginning from the left of the IP address, the
first bit that is not a “1” indicates whether it is a Class A, Class B, Class C,
Class D, or Class E network.

For class A networks, the high order (leftmost) bit is always a “0”. For
class B networks, the high order bits are always a “1” followed by a “0”. For
class C networks, the high order bits are always a “1” followed by a “1”
followed by a “0”.

First Bit
Start Address
End Address

Class A
0
0.0.0.0
127.255.255.255

Class B
10
128.0.0.0
191.255.255.255

Class C
110
192.0.0.0
223.255.255.255

Class D
1110
224.0.0.0
239.255.255.255

Class E
1111
240.0.0.0
255.255.255.255

Not all of the address ranges in the above table are assignable. The
IANA has
reserved several address spaces for special or private use. Some of the
most well-known reserved address spaces are listed in the
table below.

Subnet Masks

Subnet masks represent what part of an IP address is used to determine
network information versus host information. For a class B network, the
subnet mask uses 16 bits, allowing the remaining 16 bits to be used for
host information.

Subnet Mask
Binary Format
Decimal Format

Class A
8-bit
11111111.00000000.00000000.00000000
255.0.0.0

Class B
16-bit
11111111.11111111.00000000.00000000
255.255.0.0

Class C
24-bit
11111111.11111111.11111111.00000000
255.255.255.0

The total number of available hosts on a network can be determined from it’s
subnet mask. Since a class B network uses 16 bits for its subnet mask, it
leaves 16 bits available for host information. 216 = 65,536. All hosts need
a network address and a broadcast address. The network and broadcast addresses
are indicated by either all 1s or all 0s in the host information part of an
IP address. With those two addresses always reserved, the total number of
assignable hosts for a class B network is 216 – 2 = 65,534.

Host Bits
Host Formula
Available Hosts

Class A
24-bit
2

24

– 2
16,777,214

Class B
16-bit
2

16

– 2
65,534

Class C
8-bit
2

8

– 2
254

The total number of networks a class address may have is calculated by
subtracting the number of bits in the subnet mask from the number of bits used
to determine which class of network it is. For example, a class A network has
an 8-bit subnet mask. Only 1 bit is used to determine that it is a class A
network. Subtract 8 from 1 and that leaves 7 bits available for networks.
27 is 128. So, there is only room for 128 class A
networks.

Subnet Mask
Network ID
Network Formula
Available Networks

Class A
8-bit
1-bit
2

8-1

128

Class B
16-bit
2-bit
2

16-2

16,384

Class C
24-bit
3-bit
2

24-3

2,097,152

Classless Networks

Forget class A, B, and C now. Classless networks don’t use it at all, hence
the name. Instead, CIDR networks are identified with a trailing “/” slash
and a number that indicates how many bits are used to identify the network
portion of the address. Like a class C address in classful networking, a /24
would indicate that 24-bits are used to identify the network and the remaining
8-bits are used to identify the host. Unlike classful networking, CIDR provides
much more flexibility than 8, 16, and 24-bit network masks. Under CIDR, the
number of bits used to indicate the network portion of the address can be from
/8 to /30 although more commonly only /13 to /29 are used. This gives network
administrators the flexibility to assign addresses from 6 – 524,286 to match
the needs of an organization.

CIDR Available Hosts

The formula to calculate the number of assignable IP address to CIDR
networks is similar to classful networking. Subtract the number of network
bits from 32. Raise 2 to that power and subtract 2 for the network and broadcast
addresses. For example, a /24 network has 232-24 – 2
addresses available for host assignment.

CIDR Notation
Host Formula
Available Hosts

/8
2

32-8

– 2
16,777,214

/9
2

32-9

– 2
8,388,606

/10
2

32-10

– 2
4,194,302

/11
2

32-11

– 2
2,097,150

/12
2

32-12

– 2
1,048,574

/13
2

32-13

– 2
524,286

/14
2

32-14

– 2
262,142

/15
2

32-15

– 2
131,070

/16
2

32-16

– 2
65,534

/17
2

32-17

– 2
32,766

/18
2

32-18

– 2
16,382

/19
2

32-19

– 2
8,190

/20
2

32-20

– 2
4,094

/21
2

32-21

– 2
2,046

/22
2

32-22

– 2
1,022

/23
2

32-23

– 2
510

/24
2

32-24

– 2
254

/25
2

32-25

– 2
126

/26
2

32-26

– 2
62

/27
2

32-27

– 2
30

/28
2

32-28

– 2
14

/29
2

32-29

– 2
6

/30
2

32-30

– 2
2

As the table indicates, two /29 networks equals a /28 network. Two /28
networks equals a /27 network. Two /27 networks equals a /26 network. And so
on, and so on. The notion of combining two smaller networks into a larger one
is another benefit of classless networks named supernetting. In order
to create a supernet the smaller networks must be contiguous. For example,
192.0.2.240/29 and 192.0.2.248/29 can form a supernet 192.0.2.240/28,
but 192.0.2.240/29 and 192.0.2.8/29 could not.

CIDR Available Networks (subnetting)

How many /29 networks can fit into a /24 network? Or how many /21 networks
can fit into a /17 network? The best way to explain the formula is to show it.
The following illustrates how many /21 networks can fit into a /17 network.

  1. Subtract the network bits from 32.

    /17 = 32-17 and /21 = 32-21

  2. Raise 2 to that power.

    2

    32-17

    and 2

    32-21

  3. Divide the larger network by the smaller one.

    2

    32-17

    / 2

    32-21

    =
    2

    15

    / 2

    11

    = 2

    15-11

    = 2

    4

    = 16

As the example shows, a /17 network could be divided into sixteen /21 networks.
Spot the shortcut in the steps? How many /29 networks in a /24?

  • 28-3 = 25 = 32

CIDR Networks

Since CIDR address spaces can overlap byte boundaries, the method to tell
which address is a part of which network is a little trickier than with
classful networking. Everything that needs to be known is indicated by the
“/” number, however. Given a network address 172.16.0.0/21, it is known that
the first 21 bits of that address represent the network portion. That leaves
11 bits for host information, about 2,000 host addresses. To easier see what
that range looks like, convert 172.16.0.0 into binary. In binary, the number
looks like 10101100.00010000.00000000.00000000. The bold numbers
show the /21 network mask. No modification can be done to network portion of the
address. The remaining 11 bits are available for host assignment on the network.
After the bold section, the remaining 3 bits in the third octet can be added up
for a maximum value of decimal 7 (22 +
21 + 20). All of the bits in the
last octet are available and when converted to decimal equal 255. With all of
the bits turned on (all 1s), the decimal number turns out to be 172.16.7.255.
This is the end range of the 172.16/21 network, 172.16.0.0 – 172.16.7.255.

CIDR Subnet Mask

The process to determine the subnet mask for a CIDR address is straight
forward. The number of bits in the network portion of the address are converted
to 1s and right padded with 0s until there are 32 numbers. The sequence of
numbers is then divided into 4 octets. From then, it is a matter of converting
the 4 octets from binary to decimal.

CIDR Notation
Convert to 1s and Right Pad
Subnet Mask

/8
11111111.00000000.00000000.00000000
255.0.0.0

/9
11111111.10000000.00000000.00000000
255.128.0.0

/10
11111111.11000000.00000000.00000000
255.192.0.0

/11
11111111.11100000.00000000.00000000
255.224.0.0

/12
11111111.11110000.00000000.00000000
255.240.0.0

/13
11111111.11111000.00000000.00000000
255.248.0.0

/14
11111111.11111100.00000000.00000000
255.252.0.0

/15
11111111.11111110.00000000.00000000
255.254.0.0

/16
11111111.11111111.00000000.00000000
255.255.0.0

/17
11111111.11111111.10000000.00000000
255.255.128.0

/18
11111111.11111111.11000000.00000000
255.255.192.0

/19
11111111.11111111.11100000.00000000
255.255.224.0

/20
11111111.11111111.11110000.00000000
255.255.240.0

/21
11111111.11111111.11111000.00000000
255.255.248.0

/22
11111111.11111111.11111100.00000000
255.255.252.0

/23
11111111.11111111.11111110.00000000
255.255.254.0

/24
11111111.11111111.11111111.00000000
255.255.255.0

/25
11111111.11111111.11111111.10000000
255.255.255.128

/26
11111111.11111111.11111111.11000000
255.255.255.192

/27
11111111.11111111.11111111.11100000
255.255.255.224

/28
11111111.11111111.11111111.11110000
255.255.255.240

/29
11111111.11111111.11111111.11111000
255.255.255.248

/30
11111111.11111111.11111111.11111100
255.255.255.252

The IANA is
“dedicated to preserving the central coordinating functions of the global
Internet for the public good.” Among their other tasks, they coordinate and
allocate IP address space.

This table represents the most common reserved or special use address
spaces for IPv4. A full list
of IPv4 classifications can be found on the IANA website.

Network
Description

10.0.0.0/8
For private internal networks. IP addresses from this space should never be seen
on the public Internet.

127.0.0.0/8
This address range is reserved for the loopback address of a host, commonly implemented as
127.0.0.1. No addresses from this space should appear on the public Internet.

169.254.0.0/16
This address space is used for communication on a single host. It is most
often seen when a host is trying to obtain an IP-address but is unable to
reach a DHCP server.

172.16.0.0/12
For private internal networks. IP addresses from this space should never be seen
on the public Internet.

192.0.2.0/24
This address range is set aside to be used with example code and documentation. The
common “example.com” used frequently in technical books is most often associated with
an IP address in this range. IP addresses from this space should never be seen on the
public Internet.

192.168.0.0/16
For private internal networks. IP addresses from this space should never be seen
on the public Internet.