You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Every device that communicates over the Internet needs an IP address so that packets can be routed to and from it. An IP address is the logical address used at the network layer of the TCP/IP stack — distinct from the physical MAC address burnt into a network interface. This lesson examines how IPv4 addresses are structured, how a subnet mask splits an address into a network portion and a host portion, the role of ports, the differences between public and private addressing, the part played by DHCP and NAT, and finally IPv6 and why it was needed.
The single most examined skill here is the ability to take an IP address and a subnet mask and reason out the network address, the host portion, the number of usable hosts, and which addresses belong to which subnet. We work a full example below.
This lesson addresses the Communication and networking area of the AQA A-Level Computer Science (7517) specification, specifically IP addressing. It covers the structure of an IPv4 address in dotted-decimal form, the network and host portions, subnet masks, the purpose of IPv6, the distinction between public and private IP addresses, the role of DHCP in assigning addresses dynamically, NAT for sharing public addresses, and the role of ports in identifying processes. It connects closely to the TCP/IP protocol stack content (the network layer) and to the number systems content (binary and hexadecimal).
IPv4 (Internet Protocol version 4) uses a 32-bit address, written in dotted-decimal notation — four decimal numbers (octets, each 0–255) separated by dots. Each octet is one byte (8 bits).
| Format | Value |
|---|---|
| Dotted-decimal | 192.168.1.100 |
| Binary | 11000000.10101000.00000001.01100100 |
To convert, take each octet as an 8-bit binary number: 192 = 11000000, 168 = 10101000, 1 = 00000001, 100 = 01100100. Being fluent at this conversion is essential — subnetting questions live or die on it.
Each octet is 8 bits, so the place values from left to right are 128, 64, 32, 16, 8, 4, 2, 1 (the powers of two). To convert a decimal octet to binary, repeatedly subtract the largest place value that fits:
Convert 168 to binary:
168 >= 128 ? yes -> bit = 1, remainder 168 - 128 = 40
40 >= 64 ? no -> bit = 0
40 >= 32 ? yes -> bit = 1, remainder 40 - 32 = 8
8 >= 16 ? no -> bit = 0
8 >= 8 ? yes -> bit = 1, remainder 0
0 >= 4 ? no -> bit = 0
0 >= 2 ? no -> bit = 0
0 >= 1 ? no -> bit = 0
Result: 1 0 1 0 1 0 0 0 = 10101000
To convert back, sum the place values where a 1 appears: 10101000 = 128 + 32 + 8 = 168. Because each octet ranges 0–255, an octet value above 255 (e.g. "192.300.1.1") is invalid — a common spot-the-error exam item. Confidence with this in both directions is the single most useful skill for the rest of the lesson.
The arithmetic is worth seeing: 232=4,294,967,296. With the world population already exceeding this, and most people owning several connected devices, it is clear that a one-address-per-device world is impossible under IPv4 alone. Worse, large early allocations were handed out wastefully (whole /8 blocks of 16 million addresses to single organisations), so the usable free pool ran dry well before the theoretical limit. This scarcity is the recurring theme that explains private addressing, NAT, CIDR and IPv6 all at once.
An IPv4 address is split into two parts:
Routers use the network portion to deliver a packet to the right network; the final network then uses the host portion to deliver it to the right device. The split is defined by the subnet mask. This two-level structure is what makes routing across the whole internet scalable: a distant router need only know how to reach the right network, not the location of every individual host on the planet. Only the final, local network has to know about individual hosts. Without this network/host separation, routers would need a table entry for every device on the internet — utterly impractical. The same idea explains why addresses on one network share a common prefix: it lets them be summarised as a single routing entry.
A subnet mask is a 32-bit value in which the 1-bits mark the network portion and the 0-bits mark the host portion. The 1-bits are always contiguous and at the front.
| IP Address | Subnet Mask | Network Portion | Host Portion |
|---|---|---|---|
192.168.1.100 | 255.255.255.0 | 192.168.1 | .100 |
10.0.0.50 | 255.0.0.0 | 10 | .0.0.50 |
The mask 255.255.255.0 in binary is 11111111.11111111.11111111.00000000 — the first 24 bits are network, the last 8 bits are host.
CIDR notation writes the mask as a prefix length (the count of network 1-bits):
192.168.1.100/24 → first 24 bits network, last 8 bits host (mask 255.255.255.0).10.0.0.50/8 → first 8 bits network, last 24 bits host (mask 255.0.0.0).The network address of a host is found by performing a bitwise AND of the IP address with the subnet mask. This is a favourite exam technique:
IP address : 192.168 . 1 . 100 = 11000000.10101000.00000001.01100100
Subnet mask : 255.255 . 255 . 0 = 11111111.11111111.11111111.00000000
AND result : 192.168 . 1 . 0 = 11000000.10101000.00000001.00000000
^^^^^^^^ network portion ^^ | host = 0
So 192.168.1.100/24 lies on the network 192.168.1.0. Every host whose network address ANDs to 192.168.1.0 is on the same network and can communicate directly without a router.
| Address | Purpose |
|---|---|
127.0.0.1 | Loopback (localhost) — a device addressing itself |
0.0.0.0 | Default route / unspecified address |
| Network address (host bits all 0) | Identifies the network itself — not assignable to a host |
| Broadcast address (host bits all 1) | Reaches all hosts on the network — not assignable to a host |
This is why a network of 2h addresses has only 2h−2 usable host addresses: the all-zeros host part is the network address and the all-ones host part is the broadcast address.
The network address is not merely a label — a host uses it on every outgoing packet to decide whether the destination is reachable directly or must go via a router. The host ANDs both its own address and the destination address with the subnet mask and compares the results:
my_network = my_ip AND subnet_mask
dest_network = dest_ip AND subnet_mask
IF my_network == dest_network THEN
deliver directly on the local network (ARP for the destination's MAC)
ELSE
send the packet to the DEFAULT GATEWAY (router) for forwarding
ENDIF
So if host 192.168.1.40/24 wants to reach 192.168.1.200, both AND to 192.168.1.0 — same network — so it delivers directly. To reach 8.8.8.8, the networks differ, so it hands the packet to its gateway. This single comparison, performed constantly and invisibly, is the practical reason the network/host split exists at all.
Subnetting divides one network into smaller sub-networks by borrowing bits from the host portion to create extra network bits. This contains broadcast traffic, improves security and allocates addresses efficiently.
Task: Start with 192.168.1.0/24 (256 addresses, 254 usable hosts). Divide it into four equal subnets.
To create 4 subnets we need log24=2 extra network bits, so we extend the prefix from /24 to /26.
// New mask /26 = 255.255.255.192 (last octet 11000000)
block size = 2 ^ (host bits) = 2 ^ 6 = 64
subnet 0: network 192.168.1.0 broadcast 192.168.1.63
subnet 1: network 192.168.1.64 broadcast 192.168.1.127
subnet 2: network 192.168.1.128 broadcast 192.168.1.191
subnet 3: network 192.168.1.192 broadcast 192.168.1.255
| Subnet | Network Address | Usable Host Range | Broadcast | Usable Hosts |
|---|---|---|---|---|
| 1 | 192.168.1.0/26 | 192.168.1.1 – 192.168.1.62 | 192.168.1.63 | 62 |
| 2 | 192.168.1.64/26 | 192.168.1.65 – 192.168.1.126 | 192.168.1.127 | 62 |
| 3 | 192.168.1.128/26 | 192.168.1.129 – 192.168.1.190 | 192.168.1.191 | 62 |
| 4 | 192.168.1.192/26 | 192.168.1.193 – 192.168.1.254 | 192.168.1.255 | 62 |
Benefits of subnetting: contains broadcast traffic within each subnet (less congestion); allows different access-control/security policies per subnet; and uses the address space efficiently by sizing subnets to demand.
Exam Tip: The reliable method is: (1) work out host bits = 32 − prefix; (2) hosts = 2host bits−2; (3) block size = 2host bits in the relevant octet; (4) list networks by adding the block size; the broadcast of each is one below the next network. Show the binary AND for the network address — examiners award method marks even if the final number slips.
Subnetting questions often run the other way: you are told how many hosts are needed and must choose the prefix. Suppose a department needs subnets that each support at least 25 hosts, starting from 172.16.5.0/24.
Find the smallest host-bit count h with 2h−2≥25. Try h=4: 24−2=14 — too few. Try h=5: 25−2=30≥25 — sufficient. So we need 5 host bits, giving a prefix of 32−5=/27 (mask 255.255.255.224, last octet 11100000).
host bits = 5 -> block size = 2^5 = 32 -> 30 usable hosts per subnet
subnet 0: network 172.16.5.0 range .1 - .30 broadcast .31
subnet 1: network 172.16.5.32 range .33 - .62 broadcast .63
subnet 2: network 172.16.5.64 range .65 - .94 broadcast .95
... and so on in steps of 32, up to 172.16.5.224
A /24 split into /27s yields 2(27−24)=23=8 subnets of 30 usable hosts each. Notice the deliberate slight waste — 30 usable when only 25 are needed — because subnet sizes must be powers of two. Choosing /28 instead (14 hosts) would have been too small, so /27 is the correct minimum. This "size up to the next power of two" reasoning is exactly what examiners look for in a justification.
Exam Tip: When a question gives a required number of hosts, solve 2h−2≥required for the smallest whole h, then the prefix is 32−h. When it gives a required number of subnets, find the smallest s with 2s≥required and add s to the original prefix. Mixing these two up is the commonest subnetting mistake.
A third common task: given an address and a prefix, identify which subnet it falls in. Take 172.16.5.100/27 from the example above (block size 32). Find the largest multiple of the block size not exceeding the relevant octet value (100):
block size = 32
multiples of 32: 0, 32, 64, 96, 128, ...
largest multiple <= 100 is 96
=> network address = 172.16.5.96
=> broadcast = 96 + 32 - 1 = 172.16.5.127
=> usable range = 172.16.5.97 to 172.16.5.126
So 172.16.5.100 is a valid host on the subnet 172.16.5.96/27. The same divide-by-block-size logic identifies any address's subnet quickly, without writing out all eight subnets — a real time-saver under exam conditions.
Certain ranges are reserved for private networks (LANs) and are not routable on the public Internet — routers on the Internet deliberately discard them.
| Range | CIDR | Typical Use |
|---|---|---|
10.0.0.0 – 10.255.255.255 | 10.0.0.0/8 | Large organisations |
172.16.0.0 – 172.31.255.255 | 172.16.0.0/12 | Medium organisations |
192.168.0.0 – 192.168.255.255 | 192.168.0.0/16 | Home networks, small businesses |
A public IP address is globally unique and routable on the Internet; a private IP address is unique only within its own local network and may be reused in millions of other private networks. Your home router typically has one public address on its Internet side and hands out private 192.168.x.x addresses inside.
Manually configuring an IP address, subnet mask, gateway and DNS server on every device would be tedious and error-prone. DHCP (Dynamic Host Configuration Protocol) automates it: when a device joins a network, a DHCP server leases it an IP address and the rest of its configuration for a set period. Devices that come and go (laptops, phones) thus reuse a finite pool of addresses. Servers and printers, by contrast, are usually given static addresses so they can always be found at the same location.
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.