IPv4 addressing and subnetting
This article presents a general introduction to IPv4 and subnet addressing concepts.
You will have the basic information needed to configure and troubleshoot IPv4 addresses on a router. Such as address allocation, subnet operation and finally troubleshooting IPv4 network problems.
Understanding IPv4 addresses
An IP (Internet Protocol) address is an address used to uniquely identify a device on an IP network.
The IPv4 address is therefore composed of 32 bits, which can be divided into a network part and a host part using a subnet mask. The 32 bits are divided into four bytes (1 byte = 8 bits). Therefore, each byte is converted to decimal and separated by a dot (.). For this reason, an IP address is said to be expressed in decimal format, for example, 192.168.10.100.
The value in each byte is therefore between 0 and 255 in decimal, or 00000000 – 11111111 in binary.
Here is how the binary bytes are then converted to decimal:
The rightmost or least significant bit of a byte contains a value of 20. The bit just to the left of it contains a value of 21.
This continues until the leftmost bit, or the most significant bit, which contains a value of 27. So if all the binary bits are 1, the decimal equivalent would be 255, as shown here:
128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255
Here is an example of byte conversion when all bits are not set to 1.
For: 0 1 0 0 0 0 0 1
0 + 64 + 0 + 0 + 0 + 0 + 0 + 1 = 65
And so this example shows an IP address represented in both binary and decimal.
10. 1. 23. 19 (decimal)
These bytes are therefore decomposed to provide an addressing scheme that can accommodate large and small networks.
Indeed, there are five different IPv4 address classes, from A to E.
IPv4 address classes
In a class A address, the first byte is the network part, so in the class A example, the main network address goes from :
188.8.131.52 to 127.255.255.255.
Bytes 2, 3 and 4 (the next 24 bits) are therefore for the network manager to divide into subnets and hosts as he sees fit.
This class can have up to 23×8-2, or 16,777,214 addresses.
For the class B address, the first two bytes are the network part, so the class B example, the main network address goes from :
184.108.40.206 – 220.127.116.11.
Bytes 3 and 4 (16 bits) are for local subnets and hosts. However, Class B addresses are used for networks that have between 256 and 65534 hosts.
This class can have up to 22×8-2, or 65,534 addresses.
In a class C address, the first three bytes are the network part. In the example of class C, the main network address goes from :
192.0.0.0 – 18.104.22.168.
Byte 4 (8 bits) is for local subnets and hosts, perfect for networks with less than 254 hosts.
This class can have up to 28-2, or 254 addresses.
Class D addresses are therefore used for multicast communications.
The first IP address byte of a class D always starts with the bit sequence 1110, so it is between 224 and 239.
The networks available in class D are therefore the networks from IP address 22.214.171.124 to 126.96.36.199 (multicast addresses)
And finally, Class E addresses which are reserved by IANA (Internet Assigned Numbers Authority) for an undetermined use.
Class E addresses always start with the bit sequence 1111, so they start at 240.0.0.0 and end at 255.255.255.255.
Summary of IPv4 address classes
A 0 0.0.0.0 – 127.255.255.255 255.0.0.0
B 10 188.8.131.52 – 184.108.40.206 255.255.0.0
C 110 192.0.0.0 – 220.127.116.11 255.255.255.0
D 1110 18.104.22.168 – 22.214.171.124 pas défini
E 1111 240.0.0.0 – 255.255.255.255 Not defined
IPv4 network masks
A network mask helps you know which part of the address identifies the network and which part of the address identifies the host. Class A, B and C networks have default masks as shown here:
Class A: 255.0.0.0
Then Class B: 255.255.0.0
And Class C: 255.255.255.0
An IPv4 address on a Class A network that has not been divided into subnets would have an address/mask pair similar to: 126.96.36.199/ 255.0.0.0
To see how the mask helps you identify the network and host parts of the address, convert the address and mask into binary numbers.
188.8.131.52 = 00001000.00010100.000011111.00000001
255.0.0.0 = 1111111.00000000.000000000.000000000
Once you have the address and mask represented in binary, then the network and host part is easier.
All address bits whose corresponding mask bits are set to 1 represent the network part. All address bits whose corresponding mask bits are set to 0 represent the host part.
184.108.40.206 = 00001000.00010100.000011111.00000001
255.0.0.0 = 1111111. 00000000.000000000.000000000
Network | Host Part
Network part = 00001000 = 8
Host = 00010100 00001111.00000001 = 20.15.1
Understanding the subnet
The subnet allows you to create multiple logical networks that exist within the same Class A, B, or C network. If you don’t create a subnet, you can only use one network in your Class A, B or C network, which is unrealistic.
Each data link on a network must have a unique network identifier, with each host on that link being a member of the same network.
If you divide a main network (class A, B or C) into smaller subnets, this allows you to create a network of interconnected subnets. Each data link on this network would then have a unique network/subnetwork identifier.
However, any device, or gateway, that connects to n networks/subnets has n separate IP addresses, one for each network/subnet it interconnects.
To create a subnet of a network, extend the natural mask with some of the bits of the host part of the address to create a subnet ID.
For example, given a Class C network of 220.127.116.11 that has a natural mask of 255.255.255.0, you can create subnets like this:
Convert to binary the address and the mask…
18.104.22.168 = 11001100.00010001.00000101.00000000
255.255.255.224 = 11111111.11111111.11111111.11100000
By extending the mask to 255.255.255.224, you have taken three bits (shown in red) from the original host portion of the address and used them to create subnets.
With these three bits, it is therefore possible to create eight subnets (23= 8). With the remaining five host ID bits (green), each subnet can have up to 32 host addresses, of which 30 can be assigned to a device (25-2 = 30). 2 addresses less because one is reserved for the address of the subnet itself and the other for the diffusion of the subnet (“broadcast”).
And that’s how these sub-networks were created.
Here are the ranges of the subnets
- 22.214.171.124 255.255.255.224 host address range 1 to 30
- 126.96.36.199 255.255.255.224 host address range 33 to 62
- 188.8.131.52 255.255.255.224 host address range 65 to 94
- 184.108.40.206 255.255.255.224 host address range 97 to 126
- 220.127.116.11 255.255.255.224 host address range 129 to 158
- 18.104.22.168 255.255.255.224 host address range 161 to 190
- 22.214.171.124 255.255.255.224 host address range 193 to 222
- 126.96.36.199 255.255.255.224 host address range 225 to 254
IPv4 address types
While most IPv4 addresses are public addresses used on networks accessible via the Internet, other address blocks are assigned to networks that require little or no Internet access. These addresses are called private addresses.
Here are these private address ranges:
- 10.0.0.0 to 10.255.255.255 (10.0.0.0/8)
- 172.16.0.0 to 172.31.255.255 (172.16.0.0/12)
- 192.168.0.0 to 192.168.255.255 (192.168.0.0/16)
Private space IPv4 address blocks, as illustrated above, are used on private networks.
Hosts that do not need to access the Internet can use private addresses.
Unlike private IPv4 addresses, public IPv4 addresses are not used in a local network but only on the Internet.
A public IPv4 address is unique in the world, which is not the case for private addresses that must be unique in the same local network; but not at the global level since these addresses cannot be routed on the Internet.
Public IPv4 addresses represent all IPv4 addresses of classes A, B and C that are therefore not part of the private address range of these classes or the exceptions of class A.
If a computer on an IP network needs to communicate with a host on another network, then it will usually communicate through a device called a router. In fact, a router is specified as a host that connects the host’s subnet to other networks, called a default gateway.
When a host tries to communicate with another device via the IP network, it performs a comparison process using the defined subnet mask and the destination IP address against the subnet mask and its own IP address. The result of this comparison tells the computer whether the destination is a local host or a remote host.
If the result of this process determines that the destination is a local host, the computer will send the packet on the local subnet. If the result of the comparison determines that the destination is a remote host, the computer will forward the packet to the default gateway (router) defined in its TCP/IP properties. It is then the responsibility of the router to forward the packet to the appropriate subnet.
IP network troubleshooting
IP network problems are therefore often caused by incorrect configuration of the three main entries in the TCP/IP properties of a host.
So by understanding how IP network configuration errors affect network operations, you can solve many common TCP/IP problems.
Incorrect subnet mask
If a network uses a subnet mask other than the default mask for its address class and a client is always configured with the default subnet mask for the address class, communication will fail with some nearby networks but not to remote networks.
For example, if you create four subnets but use the subnet mask 255.255.255.0 in your TCP/IP configuration, hosts will not be able to determine that some computers are on different subnets than theirs.
In this situation, packets destined for hosts on different physical networks that are part of the same Class C address will therefore not be sent to a default gateway for delivery.
A common symptom of this problem is when a host can communicate with hosts on its local network and can communicate to all remote networks except for nearby networks with the same class A, B or C address.
To solve this problem, simply enter the correct subnet mask in the TCP/IP configuration of this host.
Incorrect IP address
And if you place hosts with IP addresses that should be on separate subnets on the same LAN with each other, they will not be able to communicate.
They will therefore try to send packets to each other via a router that cannot transmit them properly. A symptom of this problem is a computer that can communicate with hosts on remote networks, but cannot communicate with some or all hosts on their local network.
So, to correct this problem, make sure that all computers on the same physical network have IP addresses on the same IP subnet.
Incorrect default gateway
A host configured with an incorrect default gateway can therefore communicate with hosts on its own local network. But it will fail to communicate with hosts on some or all remote networks.
A host can communicate with some remote networks, but not with others if the following conditions are met:
- The same physical network therefore has several routers.
- And the wrong router is configured as the default gateway.
This problem is common if a company has a router to an internal IP network and another router connected to the Internet.