MarzleyTech Learn

Home / Learn / Networking / IPv4 addresses: structure, network and host parts, classes, private and public ranges, special addresses

IPv4 addresses: structure, network and host parts, classes, private and public ranges, special addresses

Every device that talks on an IP network needs an IP address, just as every house needs a postal address for letters to reach it. When you send a WhatsApp message, stream a video or pay with M-Pesa, the data is packed into packets stamped with a source IP address and a destination IP address, and routers across the internet read those addresses to deliver them.

IPv4 (Internet Protocol version 4) is the addressing system most networks still use daily. This unit explains how an IPv4 address is built, how to read it, which ranges are private or public, and the special addresses every technician must recognise on sight.

Structure

An IPv4 address is 32 bits, written as four octets (8 bits each) in decimal, separated by dots: dotted-decimal notation.

192     .168     .1       .25
11000000.10101000.00000001.00011001

Each octet ranges from 0 to 255 (8 bits). So 192.168.1.256 or 10.300.1.1 are invalid addresses.

Total possible IPv4 addresses: 2³² = 4,294,967,296 (about 4.3 billion). That seemed huge in the 1980s, but with billions of phones, computers and IoT devices, the free pool ran out: the global registry (IANA) handed out its last blocks in 2011, and the African registry AFRINIC has been rationing its remaining space since. That's why we use private addresses with NAT, and why IPv6 exists.

Network part and host part

Every IPv4 address has two parts:

PartMeaningPostal analogy
Network partWhich network the device is onThe street name
Host partWhich device on that networkThe house number

Devices with the same network part are on the same local network and talk directly (through a switch). To reach a device with a different network part, traffic must go through a router (the default gateway).

The subnet mask or prefix tells you where the split is:

AddressPrefixNetwork partHost part
192.168.1.25/24192.168.1.25
10.5.20.7/1610.5.20.7
172.16.40.3/8172.16.40.3

The next lessons teach masks and prefixes in full.

Address classes (the old system)

Before 1993, addresses were divided into fixed classes. Modern networks use CIDR instead, but classes still appear in exams, default settings and conversations ("a class C network").

ClassFirst octetFirst bitsDefault maskPrefixHosts per network
A1–1260255.0.0.0/816,777,214
B128–19110255.255.0.0/1665,534
C192–223110255.255.255.0/24254
D224–2391110——Multicast groups
E240–2551111——Reserved / experimental

127.x.x.x is technically in the class A range but reserved for loopback.

The class system wasted addresses: an organisation needing 300 hosts got a class B (65,534 addresses), wasting over 65,000. CIDR (1993) fixed this by allowing any prefix length.

Python · runs live in the interactive lesson
def ip_class(ip):
    first = int(ip.split(".")[0])
    if first == 127: return "Loopback"
    if 1 <= first <= 126: return "A"
    if 128 <= first <= 191: return "B"
    if 192 <= first <= 223: return "C"
    if 224 <= first <= 239: return "D (multicast)"
    if 240 <= first <= 255: return "E (reserved)"
    return "Invalid/special"

for ip in ["10.0.0.1", "172.20.5.9", "192.168.1.25", "224.0.0.5", "127.0.0.1", "41.90.64.10"]:
    print(ip, "-> class", ip_class(ip))

Private vs public addresses

Public addresses are unique on the whole internet and are assigned by registries (AFRINIC for Africa) to ISPs and organisations. Private addresses (defined in RFC 1918) can be reused inside any home or office, because routers on the internet don't route them.

RangeCIDR blockAddressesTypical use
10.0.0.0 – 10.255.255.25510.0.0.0/816.7 millionLarge companies, ISPs, cloud networks
172.16.0.0 – 172.31.255.255172.16.0.0/121 millionMedium networks, Docker
192.168.0.0 – 192.168.255.255192.168.0.0/1665,536Homes and small offices

Your home router gives your devices private addresses like 192.168.100.x and uses NAT (Network Address Translation) to share the single public address your ISP gave it. Every packet leaving your home appears to come from that public address. The NAT lesson explains how.

Python · runs live in the interactive lesson
import ipaddress
for ip in ["192.168.100.5", "10.20.30.40", "172.20.5.9", "172.40.5.9", "41.90.64.10", "8.8.8.8"]:
    a = ipaddress.ip_address(ip)
    print(f"{ip:15} private={a.is_private}")

Special addresses to recognise

AddressMeaningWhen you see it
127.0.0.1 (127.0.0.0/8)Loopback: "this computer"Testing local services, e.g. http://127.0.0.1:8000
169.254.x.xAPIPA / link-local: self-assignedThe device couldn't reach a DHCP server; a classic fault sign
0.0.0.0"This network / any address"Default route 0.0.0.0/0; a server listening on all interfaces
255.255.255.255Limited broadcast to everyone on the local networkDHCP discovery
100.64.0.0/10Carrier-grade NAT (CGNAT)Mobile and some fixed ISPs share one public IP among many customers
192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24Documentation examplesTutorials and books (like this one)
224.0.0.0/4MulticastIPTV, routing protocols (OSPF uses 224.0.0.5 and 224.0.0.6)

If your router's WAN address is in 100.64–100.127, your ISP uses CGNAT, which is why hosting a server or CCTV remote access at home may not work without help from the ISP.

Unicast, broadcast, multicast

TypeWho receivesExample
UnicastOne specific deviceLoading a web page
BroadcastAll devices on the local networkDHCP discover, ARP request
MulticastDevices that joined a groupIPTV channels, OSPF updates
AnycastThe nearest of several servers sharing an addressPublic DNS like 8.8.8.8 and 1.1.1.1

Routers don't forward broadcasts between networks, which keeps broadcast "noise" contained. That's one reason large networks are split into subnets and VLANs.

Static vs dynamic addresses

StaticDynamic (DHCP)
HowTyped in manuallyAssigned automatically by a DHCP server
Use forServers, printers, routers, CCTV recorders, access pointsLaptops, phones, guest devices
RiskTypos and duplicate addressesAddress may change (use reservations for fixed ones)

A device needs four settings to work on a network: IP address, subnet mask, default gateway, and DNS server(s). DHCP hands out all four.

Find your IP address

DeviceHow
Windowsipconfig (or ipconfig /all for gateway, DNS, MAC)
Linuxip a and ip r
macOSifconfig or System Settings → Network
AndroidSettings → Wi-Fi → tap the network → Advanced/IP address
iPhoneSettings → Wi-Fi → (i) next to the network
Your public IPSearch "what is my IP" or visit a site like ifconfig.me

Your private IP (e.g. 192.168.100.23) and your public IP (e.g. 41.90.x.x) are different: one is inside your home, the other is what the internet sees.

Think about it: A school lab PC shows IP 169.254.88.12, mask 255.255.0.0, and no default gateway. Other PCs work fine. What does this tell you, and what would you check?Show answer

The PC failed to get an address from DHCP, so it self-assigned an APIPA address. Check the cable and switch port (layer 1), that the port is in the right VLAN, then run ipconfig /release and ipconfig /renew. If others work, the DHCP server is probably fine; the problem is between this PC and the network.

Summary

  • IPv4 addresses are 32 bits written as four 0–255 octets; about 4.3 billion exist and they've run out.
  • Each address has a network part and a host part; the mask/prefix sets the split.
  • Classes A (1–126), B (128–191), C (192–223), D multicast, E reserved; CIDR replaced them.
  • Private ranges: 10/8, 172.16/12, 192.168/16; NAT shares a public address.
  • Recognise 127.0.0.1 loopback, 169.254 APIPA (DHCP failure), 0.0.0.0, 255.255.255.255, 100.64/10 CGNAT.
  • Devices need IP, mask, gateway and DNS: set statically or by DHCP.

Check yourself

  1. How many bits long is an IPv4 address?

    Show answer

    32

  2. Which class is the address 172.20.5.9 (A, B or C)?

    Show answer

    B

  3. Is 172.20.5.9 private or public?

    Show answer

    private

  4. Is 172.40.5.9 private or public?

    Show answer

    public · The private 172 range is only 172.16 to 172.31.

  5. A laptop shows the address 169.254.33.10. What service did it fail to reach?

    Show answer

    DHCP

  6. What is the default prefix of a Class C network?

    Show answer

    /24

  7. What address means "this computer" (loopback)?

    Show answer

    127.0.0.1

  8. Is 10.300.1.1 a valid IPv4 address? (yes/no)

    Show answer

    no

Learn more: RFC 1918: private address space · Cloudflare: What is my IP address?

Lesson 5 of 24 in Networking · Printable course notes