Sub topic 6
IPv4 Addressing, Subnet Masks and Gateways
This chapter assumes you know what a network is, can read decimal numbers and simple binary, and can open a Windows command prompt. You should also know the basic idea of the TCP/IP model from the earlier chapter. Here you will learn how an IPv4 address is built, how a subnet mask splits it, what a default gateway does, and which address ranges the A+ Core 1 exam expects you to recognize.
What an IPv4 Address Is
An IPv4 address is a 32-bit number that identifies a network interface at the network layer. People write it as four decimal numbers separated by dots, called dotted-decimal notation. Each number is one octet (8 bits), so each ranges from 0 to 255.
Decimal: 192 .168 .1 .25
Binary: 11000000 .10101000 .00000001 .00011001Every address has two parts:
- The network portion identifies which network the device is on.
- The host portion identifies the device within that network.
Devices on the same network share the same network portion. The subnet mask tells you where the split falls.
Subnet Masks
A subnet mask is a 32-bit value that marks which bits of an address belong to the network. Where the mask has a 1, the matching address bit is part of the network portion. Where it has a 0, the bit is part of the host portion. The mask always has all its 1s first, then all its 0s.
| Mask | Binary (last octets) | CIDR prefix | Typical use |
|---|---|---|---|
| 255.0.0.0 | 11111111.00000000... | /8 | Large networks (Class A default) |
| 255.255.0.0 | 11111111.11111111.00000000.00000000 | /16 | Medium networks (Class B default) |
| 255.255.255.0 | 11111111.11111111.11111111.00000000 | /24 | Most home and small office networks (Class C default) |
CIDR notation (Classless Inter-Domain Routing) writes the mask as a slash and the count of 1 bits. So 192.168.1.25/24 means the first 24 bits are the network portion.
Worked Example: Same Network or Not?
A computer has the address 192.168.1.25 and the mask 255.255.255.0. The first three octets are the network portion, so its network is 192.168.1.0. The host portion is 25.
Now compare it with two other addresses that use the same mask:
- 192.168.1.80 has network 192.168.1.0. It is on the same network, so the computer can reach it directly.
- 192.168.2.80 has network 192.168.2.0. It is on a different network, so the computer must send traffic through a router.
The computer makes this decision by applying the mask to both addresses. If the network portions match, the destination is local. If they differ, the traffic goes to the default gateway.
Special Addresses in Every Network
Two host values in each network are reserved, which is why usable hosts are two fewer than the total.
- The network address has all host bits set to 0 (for example 192.168.1.0). It names the network itself.
- The broadcast address has all host bits set to 1 (for example 192.168.1.255). A packet sent to it reaches every host on that network.
On a /24 network, the host portion has 8 bits, which gives 256 values. Subtract two, and 254 addresses (.1 to .254) are usable for devices.
The Default Gateway
The default gateway is the router address a host uses to reach any network other than its own. On a home or small office network it is usually the router's LAN address, often the first or last usable address, such as 192.168.1.1.
A host needs three settings to communicate beyond its own network:
- A unique IP address.
- A subnet mask that matches its network.
- A default gateway on the same network as the host.
The gateway must be inside the host's own network. A host with the address 192.168.1.25/24 cannot use 192.168.2.1 as its gateway, because it could not reach that address directly in the first place.
Public and Private Addresses
A public address is routable on the internet and is assigned by an internet service provider (ISP). A private address is reserved for use inside local networks and is not routed on the internet. Many different organizations reuse the same private ranges. A router performs network address translation (NAT) so private hosts can reach the internet. NAT is covered in the SOHO router chapter.
Memorize these three private ranges (defined in RFC 1918):
| Range | CIDR | Class |
|---|---|---|
| 10.0.0.0 to 10.255.255.255 | 10.0.0.0/8 | A |
| 172.16.0.0 to 172.31.255.255 | 172.16.0.0/12 | B |
| 192.168.0.0 to 192.168.255.255 | 192.168.0.0/16 | C |
The second range is the one people most often get wrong. It starts at 172.16 and ends at 172.31. An address such as 172.32.4.9 is public.
Address Classes
Older documentation divides addresses into classes by the first octet. Modern networks use CIDR instead, but the exam still uses class names.
| Class | First octet | Default mask | Notes |
|---|---|---|---|
| A | 1 to 126 | 255.0.0.0 | Very large networks |
| B | 128 to 191 | 255.255.0.0 | Medium networks |
| C | 192 to 223 | 255.255.255.0 | Small networks |
| D | 224 to 239 | None | Multicast |
| E | 240 to 255 | None | Experimental |
The first octet 127 sits between classes A and B and is not part of either.
Other Reserved Addresses
- Loopback: 127.0.0.0/8, usually 127.0.0.1. Traffic sent to it never leaves the computer. It tests the local TCP/IP stack.
- APIPA (link-local): 169.254.0.0/16. Windows assigns one of these when it is set to use DHCP and no DHCP server answers. APIPA is covered in the next chapter. It works only on the local network and has no default gateway.
- 0.0.0.0: means "this host" or "any address" and appears in unconfigured states and routing tables.
- 255.255.255.255: the limited broadcast address.
Viewing and Checking Settings on Windows
Run ipconfig /all to see the address, mask, gateway, DHCP server and DNS servers for every adapter.
ipconfig /allTypical output for a working wired adapter includes lines like these:
IPv4 Address. . . . . . . . . . . : 192.168.1.25
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.1.1To test each layer in order, use ping:
ping 127.0.0.1
ping 192.168.1.1
ping example.comThe first command tests the local TCP/IP stack. The second tests the path to the gateway. The third tests name resolution and internet reachability.
Static and Dynamic Addressing
A static address is typed in by hand and stays the same. A dynamic address is leased from a DHCP server and may change. Use static addresses for devices that others must find reliably, such as printers or servers. DHCP is better for most clients because it avoids typing mistakes and duplicate addresses. The next chapter covers DHCP in detail.
Common Errors and Symptoms
| Symptom | Likely cause |
|---|---|
| Can reach local devices but not the internet | Missing or wrong default gateway |
| Can reach some local devices but not others | Wrong subnet mask, so the host thinks local devices are remote |
| "IP address conflict" message | Two devices share the same static address |
| Address begins with 169.254 | DHCP failed and Windows used APIPA |
| Can ping by IP address but not by name | DNS problem, not an addressing problem |
Exercise
A computer has the address 172.16.5.40, mask 255.255.255.0 and default gateway 172.16.6.1. It can ping other devices on 172.16.5.0 but cannot reach the internet. What is wrong, and is its address public or private?
Show answer
The default gateway 172.16.6.1 is on a different network (172.16.6.0) than the host (172.16.5.0), so the host cannot reach it directly. The gateway must be on 172.16.5.x, for example 172.16.5.1. The address 172.16.5.40 is private because it falls in 172.16.0.0 to 172.31.255.255.
Exercise
How many usable host addresses does a /24 network have, and what are the network and broadcast addresses for 192.168.10.77/24?
Show answer
A /24 network has 254 usable host addresses (256 minus the network and broadcast addresses). For 192.168.10.77/24 the network address is 192.168.10.0 and the broadcast address is 192.168.10.255.
Exercise
A technician finds that a Windows laptop shows the address 169.254.18.6. What does this indicate, and which commands would you try first?
Show answer
It is an APIPA address, which means the laptop was set for DHCP but received no reply from a DHCP server. First check the cable or Wi-Fi connection, then run ipconfig /release and ipconfig /renew. If the problem remains, check that the router or DHCP server is working.