A bit is a BInary digiT. It uses base 2.
A byte is 8 bits.
An IPv4 address is 4 bytes (32 bits) long. It is usually expressed in decimal notation, i.e.
0-255.0-255.0-255.0-255
.IP addresses comprise 2 parts:
- network prefix (left most)
- host/interface identifier (right most)
The size of the two parts can vary [1] , depending on the subnet mask / CIDR prefix used. For a standard home network, you would have:
192.168.0.n/24
(CIDR notation), or
192.168.0.n
with subnet mask 255.255.255.0
[1] | That is, now that the hierarchal class system is obsolete (see below). CIDR (Classless Inter-Domain Routing) was developed as an alternative due to the inflexibiltiy of the class system, which also caused scaling problems, esp. with regard to exhausting Ipv4 addresses. CIDR/subnetting allows for (sub)networks of any size. |
Therefore, a site can divide its block of addresses / address space in any way that makes sense. This ranges from:
- 1 network with over 2,000,000 hosts (all 16 bits used for host identifier)
- 16,384 networks of 2 hosts each (only lowest 2 bits for host identifier, other 14 for network prefix)
- Subnetting:
- > standard number of bits for network prefix. More subnets, less hosts.
- Supernetting:
- < standard number of bits for network prefix. Less subnets, more hosts.
The subnet mask is a 32-bit value constructed by placing 1 in each bit location for the network prefix in the IP address, and 0 in each bit location for the host identifier. E.g.
For an address 192.168.0.1
subnet mask 255.255.255.0
, which means
subnet mask 11111111 11111111 11111111 00000000
, which means
the first 3 bytes are the network prefix.
- You can calculate the number of hosts per subnet using:
2**n - 2
where
n
= no. of bits used for host identifier (-2
excludes invalid host addresses consisting of all 0's and all 1's).Therefore, a standard home network would have
2**8 - 2
= 254 hosts available / subnet.All computers participating in a TCP/IP network have a subnet mask assigned to them.
Computers and other devices on the same subnet always use the same subnet mask.
CIDR notation is the more common way of expressing the subnet mask these days. CIDR notation appends a suffix comprising the number of bits in the network prefix of the IP address. E.g.
For an address 192.168.0.1
subnet mask 255.255.255.0
, which means
subnet mask 11111111 11111111 11111111 00000000
, which means
3 bytes (24 bits) are used for the network prefix, which means the CIDR
notation is:
192.168.0.1/24
Subnets of 192.168.0.n/27
11111111 11111111 11111111 11100000
3 additional network bits = 2^3 = 8 subnets of network 192.168.0.n 5 host bits = 2^5 - 2 (network addr and broadcast addr) = 30 hosts each
subnet | network addr | host range | broadcast addr |
1 | 192.168.0.0 | 192.168.0.1 - 192.168.0.30 | 192.168.0.31 |
2 | 192.168.0.32 | 192.168.0.33 - 192.168.0.62 | 192.168.0.63 |
3 | 192.168.0.64 | 192.168.0.65 - 192.168.0.94 | 192.168.0.95 |
4 | 192.168.0.96 | 192.168.0.97 - 192.168.0.126 | 192.168.0.127 |
5 | 192.168.0.128 | 192.168.0.129 - 192.168.0.158 | 192.168.0.159 |
6 | 192.168.0.160 | 192.168.0.161 - 192.168.0.190 | 192.168.0.191 |
7 | 192.168.0.192 | 192.168.0.193 - 192.168.0.222 | 192.168.0.223 |
8 | 192.168.0.224 | 192.168.0.225 - 192.168.0.254 | 192.168.0.255 |
Supernet of 192.168.0.0/22
11111111 11111111 11111100 00000000
2^10 -2 = 1022 hosts / subnet
subnet | network addr | host range | broadcast addr |
1 | 192.168.0.0 | 192.168.0.1 - 192.168.3.254 | 192.168.3.255 |
2 | 192.168.4.0 | 192.168.4.1 - 192.168.7.254 | 192.168.7.255 |
Introduced in 1981 to introduce range of network sizes, discontinued in 1993 when CIDR was introduced as a superior alternative. However, still worth knowing the CIDR notation for the 3 main classes (they're sometimes used), and about multicast addresses.
[2] | Used to address a group of hosts as a single entity - designed for applications such as video conferencing. Assigned on a temporary basis. Normal IP addresses are therefore unicast addresses. |
Where 192.168.0.0/24
is the network used:
192.168.0.0
- host identifier of all 0's refers to the network itself.192.168.0.255
- host identifier of all 1's defines the **broadcast- address** for the network (used when query needs to be sent to every host on the network)
0.0.0.0
- address used to refer to the local network127.0.0.1
- always assigned to loopback interface. (The remainder of- the 127.0 network is reserved).
- 10.0.0.0 - 10.255.255.255
- 172.16.0.0 - 172.31.255.255
- 192.168.0.0 - 192.168.255.255