IPv4 addressing: classes, subnet masks, private ranges and subnetting
In short: An IPv4 address is 32 bits written as four decimal octets. Part of it identifies the network and the rest the host; the subnet mask marks the boundary. Private ranges are used inside organisations, and subnetting splits one network into smaller ones.
What an IPv4 address is
An IP address identifies a device's connection to an IP network, much as a postal address identifies a house. An IPv4 address is 32 bits long. To make it readable, the bits are split into four groups of 8 bits called octets, and each octet is written as a decimal number from 0 to 255, separated by dots. This is called dotted decimal notation.
Every address has two parts: the network portion, shared by every device on the same network, and the host portion, unique to each device on that network. With 32 bits there are 232 = 4,294,967,296 possible addresses, which is no longer enough for the world. That shortage is why IPv6 and NAT exist.
Binary in two minutes
Each bit in an octet has a place value: 128, 64, 32, 16, 8, 4, 2, 1. Add the values of the bits that are 1. For example, 10101000 = 128 + 32 + 8 = 168. To convert 37 to binary, subtract the biggest place values that fit: 37 = 32 + 4 + 1 = 00100101.
Address classes
Originally, IPv4 addresses were divided into five classes. The value of the first octet tells you the class.
| Class | First octet | Leading bits | Default mask | Networks | Hosts per network | Use |
|---|---|---|---|---|---|---|
| A | 1–126 | 0 | 255.0.0.0 (/8) | 126 | 16,777,214 | Very large networks |
| B | 128–191 | 10 | 255.255.0.0 (/16) | 16,384 | 65,534 | Medium networks |
| C | 192–223 | 110 | 255.255.255.0 (/24) | 2,097,152 | 254 | Small networks |
| D | 224–239 | 1110 | none | Not for hosts | Multicast | |
| E | 240–255 | 1111 | none | Not for hosts | Reserved, experimental | |
Two rules explain the numbers: hosts per network = 2host bits − 2 (the all-zeros address is the network itself and the all-ones address is the broadcast), and 127.x.x.x is reserved for loopback (testing your own machine, e.g. 127.0.0.1).
Today: classes are mostly history. Modern networks use CIDR (classless addressing), where any prefix length such as /26 or /29 can be used. Classes are still worth knowing for exams and for reading old documentation.
Subnet masks and the AND operation
A subnet mask is a 32-bit pattern of 1s followed by 0s. The 1s mark the network portion and the 0s mark the host portion. Devices use it to decide whether a destination is on their own network (send directly) or elsewhere (send to the default gateway). They find out using a bitwise AND:
| A | B | A AND B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
If the result matches the device's own network address, the destination is local. Otherwise the packet goes to the router.
Public and private addresses
A public IP address is unique on the whole internet. Your router receives one from your ISP, and every public website needs one. A private address is reserved for use inside homes and organisations and is never routed on the internet. Private addresses can be reused by everyone, and a NAT device translates them to a public address when traffic goes online.
| Class | Private range | CIDR |
|---|---|---|
| A | 10.0.0.0 – 10.255.255.255 | 10.0.0.0/8 |
| B | 172.16.0.0 – 172.31.255.255 | 172.16.0.0/12 |
| C | 192.168.0.0 – 192.168.255.255 | 192.168.0.0/16 |
Global allocation of public addresses is coordinated by IANA (the Internet Assigned Numbers Authority), which gives blocks to regional registries, which in turn give them to ISPs.
Subnetting: one network into many
Without subnetting, a whole Class A, B or C network would be one giant broadcast domain, which is slow and insecure. Subnetting borrows bits from the host portion to create several smaller networks (subnets). Every link then has its own network ID, and a router connecting n subnets has n interfaces, each with an address in a different subnet.
Example: split 192.168.10.0/24 into 4 subnets by borrowing 2 bits (/26). Each subnet has 26 − 2 = 62 usable hosts:
| Subnet | Network | Usable hosts | Broadcast |
|---|---|---|---|
| 1 | 192.168.10.0/26 | .1 – .62 | .63 |
| 2 | 192.168.10.64/26 | .65 – .126 | .127 |
| 3 | 192.168.10.128/26 | .129 – .190 | .191 |
| 4 | 192.168.10.192/26 | .193 – .254 | .255 |
Practise with the subnet calculator and learn the fast mental method in subnetting in your head.
Beyond equal-sized subnets
Real networks rarely need subnets of the same size. VLSM (variable length subnet masks) gives each subnet only the addresses it needs, for example a /25 for a large office, a /27 for guests and a /30 or /31 for each router link. Plan from the largest subnet to the smallest so every block starts on its own boundary. In the other direction, route summarisation combines contiguous networks such as 172.16.0.0/24 to 172.16.3.0/24 into one route, 172.16.0.0/22. Both are worked through step by step in VLSM, CIDR and route summarisation.
Practice
Convert 175 and 27 to binary, and 10110 to decimal.
Give the class, default mask, network and host portion of 192.168.100.10.
Give the class, default mask, network and host portion of 130.15.1.2.
Give the class, default mask, network and host portion of 12.12.2.8.
Is 172.20.5.9 public or private?
Key takeaways
- IPv4 addresses are 32 bits, written as four octets in dotted decimal.
- Each address has a network part and a host part; the subnet mask marks the boundary.
- Classes A, B and C set default masks /8, /16 and /24; D is multicast, E is reserved. Modern networks use CIDR.
- Hosts per network = 2^host bits − 2.
- Private ranges: 10/8, 172.16/12, 192.168/16, translated by NAT.
- Subnetting borrows host bits to create smaller networks.
Original content written by Mohamed Fayas for FM TecHub. © 2026 FM TecHub. You're welcome to share a link to this page; please don't copy the text elsewhere without permission.