3.4 KiB
title | tags | created | ||
---|---|---|---|---|
IP_addresses |
|
Friday, August 16, 2024 |
IP addresses
IPv4 vs IPv6
IP addresses come in two formats and bit-lengths depending on which version of the Internet Protocol is being used.
- IPv4 addresses are 32-bits in length
- IPv6 addresses are 128-bits in length
The larger the bit-length, the more unique addresses that can be generated. Thus IPv6 can create more addresses that IPv4.
This entry focuses on IPv4 addresses.
Anatomy of an IPv4 address
Each of the 32 bits are divided into four groups which are each 8 bits in length. Each group therefore comprises an octet and is separated by dots.
The decimal number system, rather than binary is used to represent the values. This means each binary octet is three decimal digits in length.
The 32 bits comprise two major groupings
- the network prefix
- the host
Devices connected to the same network share the same network prefix. They are said to be on the same subnet. However each device will have a unique value for the host octet.
(This account is somewhat idealised. The length of the prefix does not always align with the octet boundary. For instance, the prefix could be 25 bits in length, rather than 24. In this case it would "steal" one bit from the host section making it 23 bits in length.)
Identifying the network and host groupings
Given that the network prefix and host identifier do not always stick to set boundaries, we require a way of distinguishing the two values. There are two dominant methods.
CIDR notation
This stands for Classless Inter-Domain Routing. An example:
192.168.1.23/24
The value after the forward slash is the number of bits that specify the network address. In the example, it is the standard 24-bits. Thus 192.168.1.23 stands for the network.
Subnet masking
The subnet mask is another number in addition to the network address. It is a kind of superimposed map on top of the address.
Here is an example of a subnet mask:
11111111.11111111.11111111.00000000
The denary form would be as follows (as 255 is the maximal decimal number that can be represented with a single 8-bit number and 0 is the smallest):
255.255.255.0
In the binary form, the 1 values represent the bits which designate the network address and the 0 values represent the bits that designate the host.
In the example above this corresonds to the idealised 32-bit/8-bit ratio.
There is a clever consequence of the subnet mask: if you apply a bitwise AND operator against the IP address and mask (both in their binary form) you can determine whether two addresses are on the same network.
To compare the IP address 192.168.1.23 against 192.168.1.100 to demonstrate:
192.168.1.23;
IP: 11000000.10101000.00000001.00010111
Mask: 11111111.11111111.11111111.00000000
Result: 11000000.10101000.00000001.00000000
___________________________________
192.168.1.100:
IP: 11000000.10101000.00000001.00010111
Mask: 11111111.11111111.11111111.00000000
Result: 11000000.10101000.00000001.00000000
After applying the bitwise AND logic we see that the result is identical for both IPs indicating they are on the same network (share the same network prefix), whilst the host value is "masked".
// Example of not matching
// Are there masks other than 255.255.255.0?