Free tech learning for everyone, from basics to pro

Network FundamentalsNetworking SecurityIntermediate

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.

An IPv4 address in decimal and binary, split into network and host parts19211000000.16810101000.1000001010.3700100101Network part (first 24 bits)Host part4 octets × 8 bits = 32 bits · mask 255.255.255.0 = /24
Figure 1. 192.168.10.37 with a /24 mask: the first three octets name the network, the last octet names the host.

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.

Network and host octets in classes A, B and CClass Afirst octet 1–126NetworkHostHostHostClass Bfirst octet 128–191NetworkNetworkHostHostClass Cfirst octet 192–223NetworkNetworkNetworkHost
Figure 2. In classful addressing, the class sets how many octets belong to the network.
ClassFirst octetLeading bitsDefault maskNetworksHosts per networkUse
A1–1260255.0.0.0 (/8)12616,777,214Very large networks
B128–19110255.255.0.0 (/16)16,38465,534Medium networks
C192–223110255.255.255.0 (/24)2,097,152254Small networks
D224–2391110noneNot for hostsMulticast
E240–2551111noneNot for hostsReserved, 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:

ABA AND B
000
010
100
111
ANDing an IP address with a subnet mask gives the network addressIP address206.175.162.2111001110.10101111.10100010.00010101Subnet mask255.255.255.011111111.11111111.11111111.00000000AND result206.175.162.011001110.10101111.10100010.000000001 AND 1 = 1 · every other combination = 0
Figure 3. A device ANDs the destination address with the mask to find the destination network.

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.

ClassPrivate rangeCIDR
A10.0.0.0 – 10.255.255.25510.0.0.0/8
B172.16.0.0 – 172.31.255.255172.16.0.0/12
C192.168.0.0 – 192.168.255.255192.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:

SubnetNetworkUsable hostsBroadcast
1192.168.10.0/26.1 – .62.63
2192.168.10.64/26.65 – .126.127
3192.168.10.128/26.129 – .190.191
4192.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.
175 = 10101111; 27 = 00011011; 10110 = 16 + 4 + 2 = 22.
Give the class, default mask, network and host portion of 192.168.100.10.
Class C, 255.255.255.0; network 192.168.100, host .10.
Give the class, default mask, network and host portion of 130.15.1.2.
Class B, 255.255.0.0; network 130.15, host 1.2.
Give the class, default mask, network and host portion of 12.12.2.8.
Class A, 255.0.0.0; network 12, host 12.2.8.
Is 172.20.5.9 public or private?
Private: it is inside 172.16.0.0 – 172.31.255.255.

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.
Tracks your learning on this device only. See your progress on the learning paths.

About the author

Mohamed Fayas

Founder of FM TecHub. CCNA certified, with a BTEC HND in Network Engineering, and BEng (Hons) in Computer Networking and Cloud Security. He writes practical, plain-English guides on networking, security and cloud.

More about the author

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.

Stay up to date by email

New notes, tools and security news from FM TecHub, explained simply. Free.

We only use your email to send these updates. See our privacy policy.