Lesson 3 of 8 · 80 minutes

IP addresses, subnets, and gateways

Recognise IPv4 ranges, distinguish historical classes from CIDR, and calculate masks, subnet boundaries, and host capacity from binary bits.

What you will learn

  • Recognise private, loopback, link-local, multicast, and documentation ranges.
  • Explain historical address classes without using them to infer a modern subnet mask.
  • Convert between binary masks, dotted-decimal masks, and CIDR prefixes.
  • Calculate a subnet’s network address, broadcast address, host range, and capacity.
  • Choose a prefix for a host requirement and distinguish local delivery from routing.

Build an IPv4 address from bits

An IPv4 address is 32 bits, written as four eight-bit octets. Each octet ranges from 0 to 255. From left to right, the eight bit positions have values 128, 64, 32, 16, 8, 4, 2, and 1. Add the values whose bits are 1 to convert binary to decimal; leading zero bits still occupy positions.

For decimal to binary, work from the largest value down. Subtract a place value when it fits and write 1; otherwise write 0. For 192, subtract 128 and then 64, leaving zero: 11000000. Do this independently for each octet. The binary value of an address and the binary value of its subnet mask have different jobs.

Historical classes and modern CIDR

Early IPv4 unicast addressing used classes A, B, and C, selected by leading address bits. Their default network boundaries were /8, /16, and /24. This history explains older training material, but modern routing uses Classless Inter-Domain Routing (CIDR): an explicit prefix length defines the boundary.

Do not infer today’s mask from the first octet. A 10.x.x.x host can be on a /24, /20, or another configured prefix even though 10 falls in the old Class A region. Class labels also do not mean private or public: only specific blocks are reserved for private use. D and E describe multicast and reserved regions, not ordinary unicast subnets with default host masks.

  • Class A: leading bit 0; first octet 0–127; historical default /8 (255.0.0.0). Ordinary historical network assignments used 1–126; 0/8 and 127/8 have special purposes.
  • Class B: leading bits 10; first octet 128–191; historical default /16 (255.255.0.0).
  • Class C: leading bits 110; first octet 192–223; historical default /24 (255.255.255.0).
  • Class D: leading bits 1110; 224.0.0.0–239.255.255.255 (224.0.0.0/4), used for multicast.
  • Class E: leading bits 1111; 240.0.0.0–255.255.255.255 (240.0.0.0/4), reserved. 255.255.255.255 has the specific role of limited broadcast.

Recognise private and special IPv4 ranges

Learn a range’s purpose before treating it as a normal internet destination. Private addresses can be routed inside organisations but are not globally reachable as ordinary public addresses. The entire 172/8 region is not private: the private block only spans second octets 16 through 31.

Not private does not automatically mean publicly usable: other special-purpose blocks exist. A public address also needs appropriate allocation, routing, and access policy to be reachable. The list below is a practical starting point, not the complete IANA registry. A listed block’s endpoints describe its full range, not a guarantee that every address is assignable to a host.

  • Private: 10.0.0.0/8 → 10.0.0.0–10.255.255.255; 172.16.0.0/12 → 172.16.0.0–172.31.255.255; 192.168.0.0/16 → 192.168.0.0–192.168.255.255.
  • Loopback: 127.0.0.0/8 → 127.0.0.0–127.255.255.255; 127.0.0.1 is the familiar example. Tests stay on the local host.
  • IPv4 link-local: 169.254.0.0/16 → 169.254.0.0–169.254.255.255. It is limited to the local link, not routed onward.
  • Shared carrier address space: 100.64.0.0/10 → 100.64.0.0–100.127.255.255; used for carrier-grade NAT, distinct from RFC 1918 private space.
  • Documentation: 192.0.2.0/24, 198.51.100.0/24, and 203.0.113.0/24; each runs from .0 through .255 and is used for examples in this course.
  • Unspecified address: 0.0.0.0 can represent a host without an assigned address in relevant protocol contexts. Route 0.0.0.0/0 means the default IPv4 route, not a host address.
  • Limited broadcast: 255.255.255.255 reaches the local broadcast domain and is not forwarded by routers. A subnet-directed broadcast, such as 192.0.2.191 for a /26 below, is a different concept.

Calculate a CIDR prefix from mask bits

A CIDR prefix /n counts the contiguous network bits at the left of the 32-bit mask. Write n ones followed by 32 − n zeros. Ones retain network bits; zeros identify host positions. For /26, write three full octets of ones and then 11000000. That final octet equals 128 + 64 = 192, giving mask 255.255.255.192.

To reverse the calculation, convert each decimal mask octet to eight bits and count the leading ones. In 255.255.240.0, the first two octets contribute 16 ones and 240 is 11110000, adding four: /20. Count bits in the mask, not ones in the host IP address. A CIDR mask cannot return to 1 after its first 0; 255.0.255.0 is therefore not a valid contiguous CIDR mask.

Count addresses and choose a prefix

With h host bits, there are 2^h total addresses because every host-bit position has two possible values. In a conventional IPv4 broadcast subnet with prefix /30 or shorter, reserve the all-zero host part for the network address and the all-one host part for broadcast. The usual assignable capacity is 2^h − 2. A gateway consumes one of those host addresses; it is not an extra address outside the subnet.

For a requirement of H assignable addresses, find the smallest h for which 2^h − 2 ≥ H, then calculate the prefix as 32 − h. For 50 endpoints plus one gateway, H = 51: five host bits give 30 usable addresses, while six give 62. Choose /26. Include infrastructure, reservations, and planned growth in H before sizing the subnet.

Do not apply subtract two blindly. On an IPv4 point-to-point link using /31, both addresses identify endpoints and there is no directed broadcast. A /32 identifies one address, commonly a host route. /0 represents the full IPv4 address space, normally used for a default route, rather than a practical single LAN.

Calculate a network and host range

Bitwise AND the IP address with its mask to obtain the network address. AND gives 1 only when both input bits are 1. Set all host bits to 1 for the broadcast address. For an ordinary subnet, the first assignable host is network + 1 and the last is broadcast − 1.

For 192.0.2.130/26, the first three octets are entirely network bits. In the final octet, 130 is 10000010 and mask 192 is 11000000. AND produces 10000000, or 128. Six host bits remain; setting them all to 1 produces 10111111, or 191. The network is 192.0.2.128/26, with hosts .129–.190 and broadcast .191.

A useful decimal shortcut is block size = 256 − mask value in the boundary octet. For /26, 256 − 192 = 64, so last-octet blocks start at 0, 64, 128, and 192. Find the block containing the host and stop one address before the next block. Always use the prefix: an address ending in .0 or .255 is not automatically a network or broadcast address for every subnet size.

Work across an octet boundary

The block-size shortcut also works when the prefix ends before the last octet. For 172.20.35.77/20, the mask is 255.255.240.0 and the boundary octet is the third. Its block size is 256 − 240 = 16. Third-octet blocks begin at 0, 16, 32, 48, and so on; 35 is in the 32–47 block.

Keep the first two octets fixed. Set all bits after the /20 boundary to zero for network 172.20.32.0, and to one for broadcast 172.20.47.255. The conventional host range is 172.20.32.1–172.20.47.254. There are 12 host bits, so 4,096 total addresses and 4,094 assignable addresses. This whole subnet lies inside the private 172.16.0.0/12 range.

Split a network into smaller subnets

Subnetting borrows host positions to extend a parent network prefix. Splitting a /24 into /26 networks borrows two bits, giving 2^2 = 4 equal subnets. Each has 64 total addresses and 62 assignable addresses. Do not subtract two from the number of child subnets: all four are usable in modern subnetting.

Variable Length Subnet Masking (VLSM) uses different prefix lengths within one parent allocation to fit different requirements. Allocate larger blocks first and respect their alignment. A /26 boundary must start on a multiple of 64 in the final octet of a /24; writing 192.0.2.70/26 does not create a new block starting at .70. It identifies a host in 192.0.2.64/26.

Choose local delivery or a gateway

A host uses its routes to decide how to reach a destination. In a simple LAN with one connected subnet and a default route, a same-subnet destination can be reached directly; a remote destination is sent to the default gateway. The gateway is an address on the local network belonging to a router, not the address of every remote server.

A wrong subnet mask can make a host mistakenly treat a remote address as local. A wrong gateway can allow local traffic while breaking remote access. Before blaming DNS or an application, check the address, prefix, gateway, and relevant route. More specific routes take precedence over the default route.

Carry the prefix idea into IPv6

IPv6 uses 128 bits, written as eight hexadecimal groups. Each hexadecimal digit represents four bits and each full group represents 16. Leading zeros within a group may be omitted; one consecutive run of zero groups may be replaced by ::. Thus 2001:db8::10 expands to 2001:0db8:0000:0000:0000:0000:0000:0010.

A /64 fixes the first four full groups and leaves 64 bits for addresses within that prefix. IPv6 prefixes are written in slash notation, not dotted-decimal masks, and IPv6 has no broadcast. Do not transfer IPv4’s usual minus-two host rule to IPv6. IPv6 address assignment has its own reserved-address and interface-identifier rules.

  • ::/128 is the unspecified address; ::1/128 is loopback.
  • fe80::/10 is link-local; routers do not forward it onto another link.
  • fc00::/7 is unique-local space; locally assigned unique-local prefixes use fd00::/8.
  • ff00::/8 is multicast. 2001:db8::/32 is reserved for documentation.

IPv4 calculators

Check your paper calculations, then change one value to see how the network changes. These tools run in your browser and cover IPv4 only.

Address, mask, and CIDR

Enter an IPv4 address and a prefix, decimal mask, or binary mask. Results update as you type. The network is normalised even when you enter a host address.

For example, 192.0.2.130. Enter the prefix in the next field.

For example, /26, 255.255.255.192, or 11111111.11111111.11111111.11000000.

Network / CIDR
192.0.2.128/26
Subnet mask
255.255.255.192
Wildcard mask
0.0.0.63
Network bits / host bits
26 / 6
Full address range
192.0.2.128 – 192.0.2.191
Broadcast
192.0.2.191
Conventional host range
192.0.2.129 – 192.0.2.190
Total addresses
64
Conventional host capacity
62

Host bits: 32 − 26 = 6. Total addresses: 2^6 = 64. Host capacity: 64 − 2 = 62.

Address:   11000000.00000000.00000010.10000010
Mask:      11111111.11111111.11111111.11000000
AND:       11000000.00000000.00000010.10000000
Wildcard:  00000000.00000000.00000000.00111111

Capacity assumes an ordinary broadcast subnet. A gateway uses one host address. Special-purpose ranges and reserved addresses may restrict actual assignment; this is address arithmetic, not an allocation check.

Choose a subnet for your hosts

Include endpoints, gateways, infrastructure, and spare capacity. Uses ordinary IPv4 broadcast subnets, not /31 links.

Smallest subnet that fits
/26
Subnet mask
255.255.255.192
Assignable capacity
62
Spare addresses
11

Choose 6 host bits: 2^6 − 2 = 62, enough for 51 addresses. Prefix = 32 − 6 = /26. This determines size; choose an available, aligned network separately.

Split a network into equal subnets

Parent: 192.0.2.0/24. Borrow 2 bits to create 4 equal subnets. Showing 1–4 of 4. /31 rows describe point-to-point endpoints; /32 rows describe single addresses.

NetworkFirst host / endpointLast host / endpointBroadcastCapacity
192.0.2.0/26192.0.2.1192.0.2.62192.0.2.6362
192.0.2.64/26192.0.2.65192.0.2.126192.0.2.12762
192.0.2.128/26192.0.2.129192.0.2.190192.0.2.19162
192.0.2.192/26192.0.2.193192.0.2.254192.0.2.25562
Page 1 of 1

Convert an address range to CIDR blocks

Enter inclusive start and end addresses. The result covers exactly that range with the fewest aligned CIDR blocks, without adding neighbouring addresses. This is an address range, not a usable-host pool.

32 addresses in 1 CIDR block(s)

  • 192.0.2.64/27192.0.2.64 – 192.0.2.95

Keep these points in mind

  • CIDR counts the contiguous leading 1 bits in a mask; it cannot be derived from an IP address alone.
  • Host bits = 32 − prefix; total IPv4 addresses = 2^(host bits).
  • Conventional IPv4 host capacity subtracts network and broadcast; /31 and /32 need different treatment.
  • Network = address AND mask; the broadcast sets every host bit to 1.
  • Historical classes do not determine modern prefixes or whether an address is private.
  • Use the boundary octet for block-size calculations and check alignment before allocating subnets.

Pause and practise

Work these out on paper before revealing the answer: (1) Convert 255.255.255.224 to binary and CIDR. (2) For 192.0.2.77 with that mask, find network, broadcast, host range, and capacity. (3) Size the smallest conventional subnet for 50 endpoints and one gateway. (4) For 172.20.35.77/20, find the network and broadcast. (5) Identify which of 172.15.1.1, 172.31.1.1, and 169.254.10.20 is RFC 1918 private and which is link-local. (6) How many /27 subnets fit in a /24? Finally, a host 192.0.2.77/27 has gateway 192.0.2.65: does it send directly to .90, and how does it reach .100?

Show a worked response

(1) 11111111.11111111.11111111.11100000 has 27 leading ones: /27. (2) Five host bits give 32 total and 30 assignable addresses. Block size 256 − 224 = 32 places 77 in 64–95: network 192.0.2.64, broadcast .95, hosts .65–.94. (3) H = 51; 2^5 − 2 = 30 is too small, but 2^6 − 2 = 62 fits, so /26. (4) /20 has mask 255.255.240.0: network 172.20.32.0 and broadcast 172.20.47.255. (5) 172.31.1.1 is private; 169.254.10.20 is link-local; 172.15.1.1 is outside RFC 1918 space. (6) Three borrowed bits give 2^3 = 8 subnets. In the simple connected-subnet/default-route setup, .90 is local; .100 is outside 192.0.2.64/27, so the host resolves gateway .65 to a MAC address and sends the frame there.

Check your understanding

Choose the best response to each scenario, then check your reasoning. These are course practice questions.

1. What prefix does mask 255.255.240.0 represent?
2. What is the network address of 192.0.2.77/27?
3. What is the smallest conventional subnet for 50 endpoints plus one gateway?
4. Which address belongs to RFC 1918 private space?
5. A host is configured as 10.1.2.3/24. Which mask should you use?
6. Which mask cannot represent a contiguous CIDR prefix?
7. How many /27 subnets fit exactly inside one /24?
8. How many endpoint addresses does a supported IPv4 /31 point-to-point link provide?

0 of 8 answered

Next lesson →
← Previous lesson