Each IP host or node on a network is identified by an IP address. The IP address is a network layer address and has relationship to data link layer address (such as a MAC address of a network interface card). An IP address is a 32 bit binary number. Usually this number is represented by 4 decimal values in the range 0 to 255 (known as octets) separated by decimal points. This is known as "dotted decimal" notation.

Example: 216.109.112.135

Here is the IP address in its binary form:
216 .109 .112 .135
11011000.01101101.01110000.10000111

So for example The number 216 can be expressed as:
128 + 64 + 16 + 8

## Classful routing

Every IP address consists of two parts, one identifying the network (Network Number) and one identifying the node (Node Number).[1] The Class of the address and the subnet mask determine which part belongs to the network address and which part belongs to the node address.

In classful routing, the remainder of the IP address is the Host ID. There are two special values: all zeros = network id all ones = broadcast id

### Class A Network

In a Class A Network, binary address start with 0, therefore the decimal number can be anywhere from 1 to 126. The first 8 bits identify the network and the remaining 24 bits indicate the host within the network.

1 .X .X .X
00000001.XXXXXXXX.XXXXXXXX.XXXXXXXX
to
126 .X .X .X
01111110.XXXXXXXX.XXXXXXXX.XXXXXXXX

127.X.X.X - is reserved for loopback
01111111.XXXXXXXX.XXXXXXXX.XXXXXXXX

### Class B Network

In a Class B Network, binary addresses start with 10, therefore the decimal number can be anywhere from 128 to 191. The first 16 bits (the first two octets) identify the network and the remaining 16 bits indicate the host within the network.

128.0.X.X
10000000.00000000.XXXXXXXX.XXXXXXXX
to
191.255.X.X
10111111.11111111.XXXXXXXX.XXXXXXXX

### Class C Network

In a Class C Network, binary addresses start with 110, therefore the decimal number can be anywhere from 192 to 223. The first 24 bits (the first three octets) identify the network and the remaining 8 bits indicate the host within the network.

192.0.0.X
11000000.00000000.00000000.XXXXXXXX
to
223.255.255.X
11011111.11111111.11111111.XXXXXXXX

### Class D Network

In a Class D Network, binary addresses start with 1110, therefore the decimal number can be anywhere from 224 to 239. Class D networks are used to support multicasting.

224.0.0.X
11100000.00000000.00000000.XXXXXXXX
to
239.255.255.X
11101111.11111111.11111111.XXXXXXXX

### Class E Network

In a Class E Network, binary addresses start with 1111, therefore the decimal number can be anywhere from 240 to 255. Class E networks are reserved.

240.0.0.X
11110000.00000000.00000000.XXXXXXXX
to
255.255.255.X
11111111.11111111.11111111.XXXXXXXX

## Number of Networks and Hosts

Class Leading Bits Size of Network
Number
Bit field
Size of Host
Number
Bit field
Number of Networks Addresses Per Network
Class A     0     7     24     126     16,277,214
Class B     10     14     16     16,384     65,534
Class C     110     21     8     2,097,152     254
Class D (multicast)     1110     20     8     1,048,576     254
Class E (reserved)     1111     20     8     1,048,576     254

The number of valid networks and hosts available is always 2N - 2 (where N is the number of bits used, and the 2 adjusts for the invalidity of the first and last addresses). Thus, for a class C address with 8 bits available for hosts, the number of hosts is 254.

The larger network number field allowed a larger number of networks, thereby accommodating the continued growth of the Internet.

The IP address netmask (which is so commonly associated with an IP address today) was not required because the mask length was part of the IP address itself. Any network device could inspect the first few bits of a 32-bit IP address to see which class the address belonged to.

The method of comparing two IP address's physical networks did not change, however (see subnetwork). For each address, the network number field size and its subsequent value were determined (the rest field was ignored). The network numbers were then compared. If they matched, then the two addresses were on the same network.

## Classless Routing

Classless Inter-Domain Routing (CIDR, pronounced "cider") was introduced in 1993 and is the latest refinement to the way IP addresses are interpreted. It replaced the previous generation of IP address syntax, classful networks. Specifically, rather than allocating address blocks on eight-bit (i.e., octet) boundaries forcing 8, 16, or 24-bit prefixes, it used the technique of variable-length subnet masking (VLSM) to allow allocation on arbitrary-length prefixes. CIDR encompasses:

• The VLSM technique of specifying arbitrary length prefix boundaries. A CIDR-compliant address is written with a suffix indicating the number of bits in the prefix length, such as 192.168.0.0/16. This permits more efficient use of increasingly scarce IPv4 addresses.
• The aggregation of multiple contiguous prefixes into supernets, and, wherever possible in the Internet, advertising aggregates, thus reducing the number of entries in the global routing table. Aggregation hides multiple levels of subnetting from the Internet routing table, and reverses the process of "subnetting a subnet" with VLSM.
• The administrative process of allocating address blocks to organizations based on their actual and short-term projected need, rather than the very large or very small blocks required by classful addressing schemes.

## Subnetting

In computer networks, a subnetwork or subnet is a range of logical addresses within the address space that is assigned to an organization. Subnetting is a hierarchical partitioning of the network address space of an organization (and of the network nodes of an autonomous system into several subnets). Routers constitute borders between subnets. Communication to and from a subnet is mediated by one specific port of one specific router, at least momentarily.

A typical subnet is a physical network served by one router, for instance an Ethernet network (consisting of one or several Ethernet segments or local area networks, interconnected by switches and bridges) or a Virtual Local Area Network (VLAN). However, subnetting allows the network to be logically divided regardless of the physical layout of a network, since it is possible to divide a physical network into several subnets by configuring different host computers to use different routers.

The address to all nodes in a subnet starts with the same binary sequence, which is its network id and subnet id. In IPv4, the subnet may be identified by its base address and subnet mask.

Subnetting simplifies routing, since each subnet typically is represented by one row in the routing tables in each connected router.

Subnetting was originally introduced before the introduction of classful network addresses in IPv4, to allow a single larger network to have a number of smaller networks within it, controlled by several routers. Subnetting made Classless Inter-Domain Routing (CIDR) possible.

In order for computers to communicate on one network, they will all need their own IP address. However, if you have two or more networks, instead of purchasing different numbers for each network, subnetting provides the ability to easily divide one IP address range amongst all the hosts in your network. Subnetting is used in IP networks to break up larger networks into a smaller network. Subnetting involves manually calculating the bits of an IP address and taking them from the host side of bits and adding them to the network side.

While subnet masks are often represented in dot-decimal form their use becomes clearer in binary. Looking at a network address and a subnet mask in binary a device can determine which part of the address is the network address and which part is the host address. To do this, it performs a bitwise "AND" operation.

Example

Network Portion 192.168.5.0 11000000.10101000.00000101.00000000
Host Portion 0.0.0.10 00000000.00000000.00000000.00001010

Subnet masks consist of a series of 1s in binary followed by 0s. The 1s designate that part of the address as being part of the network portion and the 0s designate that part as being part of the host address. Subnet masks do not have to fill a given octet. This allows a classful network to be broken down into subnets. A classful network is a network that has a subnet mask of 255.0.0.0, 255.255.0.0 or 255.255.255.0. Subnet masks can also be expressed in a shorter form, known as Classless Inter-Domain Routing (CIDR) notation, which gives the network number followed by a slash ("/") and the number of 'one' bits in the binary notation of the netmask (i.e. the number of relevant bits in the network number). For example, 192.0.2.96/24 indicates an IP address where the first 24 bits are used as network address (same as 255.255.255.0).

### IPv4 classes

IPv4 addresses are broken down into three parts: the network part, the subnet part, and the host part. There are three classful network classes of IP address which determine how much is which

Class Leading bits Start End Default Subnet Mask in dotted decimal CIDR notation
A 0 0.0.0.0 126.255.255.255 255.0.0.0 /8
B 10 128.0.0.0 191.255.255.255 255.255.0.0 /16
C 110 192.0.0.0 223.255.255.255 255.255.255.0 /24
D 1110 224.0.0.0 239.255.255.255
E 1111 240.0.0.0 255.255.255.0

The 127.0.0.1 network is left out because it is designated for loopback and cannot be assigned to a network

Class D multicasting

Class E reserved

Subnetting is the process of allocating bits from the host portion as a network portion. The above example shows the bitwise "AND" process being performed on a classful network. The following example shows bits being borrowed to turn a classful network into a subnet.

Example

Network Portion 192.168.5.128 11000000.10101000.00000101.10000000

In this example two bits were borrowed from the original host portion. This is beneficial because it allows a single network portion to be split into several smaller network portions. By design IPv4 address are limited in number and each classful network portion is capable of supporting a finite number of hosts. A classful C address for example has space for 254 hosts. If a network were to be split into four parts using classful address four different class C addresses would have to be used to serve those networks. Using the subnetting example above if each subnetwork were to have 62 hosts or less (see below for math) a single class C address could be split up to service the entire network while wasting the fewest host addresses.

## Subnets and host count

It is possible to determine the number of hosts and subnetworks available for any subnet mask. In the above example two bits were borrowed to create subnetworks. Each bit can take the value 1 or 0, giving 4 possible subnets (${\displaystyle 2^{2}=4}$)

192.168.5.0/26 11000000.10101000.00000101.00000000 192.168.5.63
192.168.5.64/26 11000000.10101000.00000101.01000000 192.168.5.127
192.168.5.128/26 11000000.10101000.00000101.10000000 192.168.5.191
192.168.5.192/26 11000000.10101000.00000101.11000000 192.168.5.255

According to the RFC 950 standard the subnet values consisting of all zeros and all ones are reserved, reducing the number of available subnets by 2. However due to the inefficiencies introduced by this convention it is generally no longer used and is only relevant when dealing with some legacy equipment.

The remaining bits after the subnet are used for addressing hosts within the subnet. In the above example the subnet mask consists of 26 bits, leaving 6 bits for the address (${\displaystyle 32-26}$). This allows for 64 possible combinations (${\displaystyle 2^{6}}$), however the all zeros value and all ones value are reserved for the network ID and broadcast address respectively, leaving 62 addresses.

In general the number of available hosts on a subnet can be calculated using the formula ${\displaystyle 2^{n}-2}$, where n is the number of bits used for the host portion of the address.

RFC 3021 specifies an exception to this rule when dealing with 31 bit subnet masks (i.e. 1 host bit). According to the above rule a 31 bit mask would allow for ${\displaystyle 2^{1}-2=0}$ hosts. The RFC makes allowances in this case for certain types of networks (point-to-point) to disregard the network and broadcast address, allowing two host addresses to be allocated.

Possible subnets for a Class C network:

CIDR notation Network Mask Available Networks Available Hosts per network Total usable hosts
/24 255.255.255.0 1 254 254
/25 255.255.255.128 2 126 252
/26 255.255.255.192 4 62 248
/27 255.255.255.224 8 30 240
/28 255.255.255.240 16 14 224
/29 255.255.255.248 32 6 192
/30 255.255.255.252 64 2 128
/31 255.255.255.254 128 2 * 256

* only applicable on point-to-point links

## CIDR notation

CIDR
/32 1/256 C 1 255.255.255.255
/31 1/128 C 2 255.255.255.254
/30 1/64 C 4 255.255.255.252
/29 1/32 C 8 255.255.255.248
/28 1/16 C 16 255.255.255.240
/27 1/8 C 32 255.255.255.224
/26 1/4 C 64 255.255.255.192
/25 1/2 C 128 255.255.255.128
/24 1 C 256 255.255.255.000
/23 2 C 512 255.255.254.000
/22 4 C 1024 255.255.252.000
/21 8 C 2048 255.255.248.000
/20 16 C 4096 255.255.240.000
/19 32 C 8192 255.255.224.000
/18 64 C 16384 255.255.192.000
/17 128 C 32768 255.255.128.000
/16 256 C, 1 B 65536 255.255.000.000
/15 512 C, 2 B 131072 255.254.000.000
/14 1024 C, 4 B 262144 255.252.000.000
/13 2048 C, 8 B 524288 255.248.000.000
/12 4096 C, 16 B 1048576 255.240.000.000
/11 8192 C, 32 B 2097152 255.224.000.000
/10 16384 C, 64 B 4194304 255.192.000.000
/9 32768 C, 128B 8388608 255.128.000.000
/8 65536 C, 256B, 1 A 16777216 255.000.000.000
/7 131072 C, 512B, 2 A 33554432 254.000.000.000
/6 262144 C, 1024 B, 4 A 67108864 252.000.000.000
/5 524288 C, 2048 B, 8 A 134217728 248.000.000.000
/4 1048576 C, 4096 B, 16 A 268435456 240.000.000.000
/3 2097152 C, 8192 B, 32 A 536870912 224.000.000.000
/2 4194304 C, 16384 B, 64 A 1073741824 192.000.000.000
/1 8388608 C, 32768 B, 128 A 2147483648 128.000.000.000
/0 16777216 C, 65536 B, 256 A 4294967296 000.000.000.000