IP connectivityIntermediate24 min read

What Is Prefix length in Networking?

Reviewed byJohnson Ajibi· Senior Network & Security Engineer · MSc IT Security

This page mentions older exam versions. See the Current Exam Context and Legacy Exam Context sections below for the updated mapping.

On This Page

Quick Definition

A prefix length tells you how many bits in an IP address are used for the network part, and the rest are for individual devices. It is written as a slash followed by a number, like /24 or /64. This number helps routers decide where to send data and how many devices can be on a network. The larger the prefix length, the fewer the devices in that network.

Commonly Confused With

Prefix lengthvsSubnet mask

A subnet mask is a 32-bit number (like 255.255.255.0) that does the same job as a prefix length, but is written in dotted decimal format. The prefix length is a shorthand that shows the number of 1 bits in the mask. For example, /24 is the same as 255.255.255.0. They are two representations of the same concept.

In a configuration, you might see ip address 192.168.1.1 255.255.255.0. The prefix length equivalent is 192.168.1.1/24.

Prefix lengthvsCIDR notation

CIDR notation is the overall system of writing addresses with a prefix length, like 192.168.1.0/24. The prefix length is the number after the slash. So the prefix length is a part of CIDR notation, not a separate concept.

When you see 10.0.0.0/8, the /8 is the prefix length, and the whole string is CIDR notation.

Prefix lengthvsWildcard mask

A wildcard mask is used in access control lists (ACLs) and is the inverse of a subnet mask. For example, a /24 subnet mask (255.255.255.0) has a wildcard mask of 0.0.0.255. The wildcard mask has 0 bits where the subnet mask has 1, and 1 bits where the subnet mask has 0. They serve opposite purposes: subnet masks define network boundaries, wildcard masks define which bits to match in ACLs.

To match all addresses in the 192.168.1.0/24 subnet in an ACL, you would use the wildcard mask 0.0.0.255, not the subnet mask.

Must Know for Exams

Prefix length is a core topic in many IT certification exams, especially those focused on networking. In CompTIA Network+ (N10-008), the objective covers subnetting and the use of CIDR notation. You will be expected to calculate the number of hosts per subnet, identify the correct subnet mask from a prefix length, and determine the network address and broadcast address. Questions often present a scenario with a given number of hosts and ask you to choose the appropriate prefix length. You may also need to convert between dotted decimal subnet masks and CIDR notation.

In the Cisco CCNA 200-301 exam, prefix length is even more critical. One of the main exam objectives is to configure and verify IP addressing and subnetting. You will need to analyze a network diagram, assign IP addresses to interfaces, and ensure that the correct prefix length is used for each subnet. Troubleshooting questions may present a scenario where a device cannot communicate because the prefix length is misconfigured. You will need to check the routing table to see if the route matches the expected prefix length.

The Cisco CCNA includes questions on route summarization, where you must calculate the shortest prefix length that covers a set of networks. For example, given the networks 192.168.1.0/24, 192.168.2.0/24, and 192.168.3.0/24, the summary route is 192.168.0.0/22. Understanding how prefix length aggregates networks is essential.

In Juniper JNCIA-Junos exam, prefix length appears in the context of configuring static routes, dynamic routing protocols, and firewall filters. You might be asked to write a firewall filter that matches a specific prefix length, or to verify that a route in the routing table has the correct prefix length.

For AWS Certified Solutions Architect, you need to understand prefix length when designing VPC subnets. For example, you must choose a CIDR block (like 10.0.0.0/16) and then create smaller subnets (like /24) for public and private resources. A question might ask you to select the smallest prefix length that allows enough IP addresses for a given number of EC2 instances.

Exam questions on prefix length come in several forms. Multiple-choice questions might ask: What is the subnet mask for /27? Or: How many usable hosts are in a /29 network? Performance-based questions might ask you to drag and drop IP addresses into the correct subnets based on their prefix length. Lab simulations may require you to configure RIP or OSPF with a network statement that includes the prefix length.

To succeed in these exams, you must be able to quickly convert between prefix length and subnet mask, calculate number of hosts, and identify network and broadcast addresses. Practice with subnetting calculators and manual calculations until it becomes second nature.

prefix length is not just a theoretical concept; it is a practical skill that is tested extensively in IT certifications. Mastering it will help you answer both straightforward and complex questions correctly.

Simple Meaning

Think of an IP address like a mailing address for a large apartment building. The prefix length tells you how much of that address is the building number and how much is the specific apartment number. If the prefix length is large, like /30, you have a very short building number and a very long apartment number, which means the building can only have a few apartments. If the prefix length is small, like /8, you have a long building number and a short apartment number, allowing thousands of apartments.

In networking, every IP address has two parts: the network part and the host part. The prefix length tells you exactly where the split happens. For a standard home network, you might see a prefix length of /24. That means the first 24 bits of the IP address (like 192.168.1.x) are the network, and the last 8 bits (the x) are reserved for devices like computers, phones, and printers. With 8 bits, you can have up to 254 devices.

If you were to use a /16 prefix length, the network part would be the first 16 bits, leaving 16 bits for devices. That gives you over 65,000 possible addresses. A /8 prefix length gives you over 16 million addresses. Internet Service Providers use large prefix lengths like /8 or /16 to give them flexibility to distribute addresses to customers. Similarly, in IPv6, prefix lengths are usually /64, giving a huge number of addresses for each network.

The prefix length is often called the CIDR notation (Classless Inter-Domain Routing). It replaced the older class-based system (Class A, B, C) because it is much more flexible. Instead of being stuck with only three sizes of networks, you can choose any prefix length that matches your needs, from /0 (the entire Internet) to /32 (a single device in IPv4). This precision helps avoid wasting IP addresses, which is very important as the available addresses become scarce.

Full Technical Definition

A prefix length is a numeric value that represents the number of contiguous 1-bits in a subnet mask. In IPv4, the subnet mask is a 32-bit number that separates the network identifier from the host identifier. For example, a prefix length of /24 corresponds to a subnet mask of 255.255.255.0, where the first 24 bits are 1 bits and the remaining 8 bits are 0 bits. This notation is standardized in RFC 4632 for Classless Inter-Domain Routing (CIDR).

When an IP packet is sent, the router uses the prefix length to determine the destination network. The router takes the destination IP address, performs a logical AND operation with the subnet mask (derived from the prefix length), and obtains the network portion. Then it looks up that network in its routing table to find the next hop. For example, with an IP address 192.168.1.55 and a prefix length of /24, the router calculates the network address as 192.168.1.0.

In IPv6, the prefix length works similarly but with 128-bit addresses. The most common prefix length for a local network segment is /64, which provides a 64-bit network prefix and a 64-bit interface identifier. This allows for automatic address configuration using SLAAC (Stateless Address Autoconfiguration) and ensures that each subnet has enough addresses for all devices without conflict.

Prefix lengths are critical in routing protocols such as OSPF, EIGRP, and BGP. When networks are advertised, the prefix length is included so that other routers know the exact size of the network. In BGP, longer prefix lengths (more specific routes) are preferred over shorter ones, which is how traffic engineering and load balancing are achieved. A common practice is to use summarization – advertising a shorter prefix length to represent many smaller networks – to reduce the size of routing tables.

In real IT implementation, network administrators assign prefix lengths based on the number of hosts needed. A /30 prefix (255.255.255.252) is often used for point-to-point links between routers because it provides exactly two usable host addresses. A /29 (255.255.255.248) gives six usable hosts, suitable for small server segments. A /24 (255.255.255.0) is typical for local area networks because it supports up to 254 hosts, which is enough for most small-to-medium offices.

Prefix lengths are also used in access control lists (ACLs) and firewall rules to match traffic from a range of IP addresses. For example, a rule that blocks traffic from 10.0.0.0/8 will block all IP addresses starting with 10.x.x.x. This is much more efficient than listing every individual IP address.

It is important to remember that the prefix length affects both the network address and the broadcast address. In IPv4, the first address in a subnet (all host bits 0) is the network address, and the last address (all host bits 1) is the broadcast address. These cannot be assigned to devices. So a /24 network with 256 total addresses has only 254 usable addresses for hosts.

Real-Life Example

Imagine you are moving into a new city and you need to send a letter to your friend who lives in a large apartment complex. The city has many neighborhoods, and each neighborhood has many buildings. The prefix length is like telling the postal service how much of the address is the neighborhood and how much is the specific apartment. If you write the neighborhood name and then the building number and apartment number, you are giving a very specific address. That is like a long prefix length – it identifies a small group of apartments (or just one in extreme cases).

Now think about a huge office building with thousands of employees. You might just say the building name and then the floor and desk number. That is like a short prefix length – the building part takes up a lot of the address, but the rest is used to identify individual desks. In networking terms, if you have a small company with only 50 computers, you do not need a huge range of addresses. You can use a /26 prefix length, which gives 62 usable addresses. That is efficient and leaves no wasted space.

But if you are a large university with thousands of students and staff, you need a much larger block. You might get a /16 prefix from your ISP, which gives you over 65,000 addresses. That would be like giving the city name and the neighborhood for your address, and then each department and room gets its own portion. The prefix length tells the routers exactly how to split the address, just like the postal service knows to deliver to the correct neighborhood before looking for the specific house.

Another analogy is a telephone numbering system. The country code is like the shortest prefix – it covers the whole country. The area code is a bit longer, then the exchange code, then the local number. Each step pinpoints a smaller group of phones. In networking, the prefix length determines how many bits are used for the network (the big group) and how many for the host (the individual phone). This hierarchical structure makes routing on the global internet manageable.

Why This Term Matters

Understanding prefix length is essential for anyone working with computer networks, from home users to enterprise network engineers. The most practical reason is that it determines how many devices can be on a network. If you choose a prefix length that is too short, you will run out of IP addresses for new devices. If you choose one that is too long, you might waste addresses that could have been used elsewhere. For example, giving a /24 network to a small office that only needs 10 devices wastes over 240 addresses, which is wasteful in a world of IPv4 scarcity.

Prefix length also affects network performance and security. A network that is too large (with a short prefix length) can have excessive broadcast traffic, because broadcast messages are sent to all devices in the subnet. This can slow down the network and reduce efficiency. Enterprise networks often break their address space into smaller subnets (using longer prefix lengths) to limit broadcast domains and improve performance.

In routing, prefix length matters for route summarization. By advertising a shorter prefix length that covers many smaller networks, routers can reduce the size of their routing tables, which saves memory and speeds up routing decisions. This is a key skill for network engineers who manage large networks or ISPs.

From a security perspective, prefix length helps define the scope of firewall rules. A rule that blocks or permits traffic to a specific subnet uses the prefix length to match the range of addresses. Getting the prefix length wrong in a security rule could either block legitimate traffic (causing disruptions) or allow unwanted traffic (creating vulnerabilities).

For IT professionals studying for certifications like CompTIA Network+, Cisco CCNA, or Juniper JNCIA, prefix length is a foundational topic. You will be asked to calculate the number of hosts, determine the subnet mask, and identify the network and broadcast addresses. You might also need to design a subnet scheme for a given number of hosts or subnetworks.

prefix length is not just a technical detail; it is a fundamental tool for efficient, secure, and scalable network design. Without it, IP addressing would be rigid and wasteful, and the internet as we know it would not be possible.

How It Appears in Exam Questions

Prefix length appears in exam questions in several distinct patterns. The most common is the direct calculation question. For example: What is the subnet mask for a /26 prefix? The answer is 255.255.255.192. Or: How many usable host addresses are in a /28 network? The answer is 14 (since 2^(32-28) - 2 = 16 - 2 = 14). These questions test your arithmetic and your understanding of the relationship between prefix length, subnet mask, and host count.

Scenario-based questions are also frequent. For example: A network administrator needs to create a subnet that supports 30 devices. Which prefix length should be used? The correct answer is /27, because a /27 provides 30 usable hosts (2^5 - 2 = 30). A /28 only gives 14 hosts, which is insufficient. A /26 gives 62, which wastes addresses. These questions require you to think about the real-world requirement and choose the appropriate prefix length.

Configuration questions appear in simulation environments. For example, you may be given a router interface and asked to assign an IP address with the correct prefix length. You would use a command like ip address 192.168.1.1 255.255.255.0 (which is equivalent to /24). In Cisco IOS, you can also use the prefix length directly, like ip address 192.168.1.1 255.255.255.0 or in some contexts ip address 192.168.1.1/24.

Troubleshooting questions describe a problem where devices cannot communicate, and you must identify that the prefix length is incorrect. For instance, two routers are connected via a serial link, but one has an interface configured with a /30 prefix and the other with a /24 prefix. Even though the IP addresses fall in the same range, the routers will treat them as different subnets and will not route traffic correctly. You would need to spot that the prefix lengths are mismatched.

Route summarization questions ask you to find a single prefix that covers multiple networks. For example: Which prefix length summarizes the networks 10.1.0.0/24, 10.1.1.0/24, 10.1.2.0/24, and 10.1.3.0/24? The answer is 10.1.0.0/22, because the first 22 bits of all four networks are the same. This type of question tests your binary conversion skills and understanding of longest prefix matching.

Another pattern is matching questions, where you are given a list of IP addresses and a list of subnets with prefix lengths, and you must assign each IP to the correct subnet. For example, given 192.168.5.33/27 and 192.168.5.65/27, you need to determine that the first belongs to subnet 192.168.5.32/27 and the second to 192.168.5.64/27.

In some exams, you might see a question about variable-length subnet masking (VLSM), where you use different prefix lengths in the same network to optimize address usage. For example, a network with three segments: one needs 100 hosts, one needs 50 hosts, and one needs 20 hosts. You must choose prefix lengths /25, /26, and /27 respectively, and assign subnets without overlap.

Finally, some questions test knowledge of the broadcast address and network address. For a given IP and prefix length, you might be asked to identify the broadcast address. For example, for 10.0.0.5/24, the broadcast is 10.0.0.255. Getting this wrong is a common mistake.

Understanding these question patterns helps you focus your study. Practice every type regularly until you can answer confidently.

Practise Prefix length Questions

Test your understanding with exam-style practice questions.

Practise

Example Scenario

You are a network administrator for a small company called TechGrow. The company has three departments: Sales, IT, and HR. Each department needs its own network segment (subnet). The company has been assigned the IP address block 192.168.10.0/24 from their ISP. You need to divide this /24 block into smaller subnets that will each support the required number of devices.

Sales has 40 employees, but you want room for growth, so you decide to give them a subnet that can support 50 devices. IT has 20 employees and needs room for 25 devices. HR has only 10 employees and needs 15 devices. You need to choose the correct prefix length for each subnet so that the total addresses used do not exceed the /24 block.

First, you determine the prefix length for Sales. A /26 prefix gives 62 usable hosts, which is more than enough for 50 devices. So you assign Sales the first subnet: 192.168.10.0/26. This subnet ranges from 192.168.10.0 (network address) to 192.168.10.63 (broadcast address), with usable addresses 192.168.10.1 to 192.168.10.62.

Next, IT needs a subnet for 25 devices. A /27 prefix gives 30 usable hosts, which is perfect. You assign IT the next available subnet: 192.168.10.64/27. This subnet's network address is 192.168.10.64, broadcast is 192.168.10.95, and usable addresses are 192.168.10.65 to 192.168.10.94.

HR only needs 15 devices, so a /28 prefix gives 14 usable hosts, which is just slightly too small. You decide to use a /27 for HR as well, to keep consistency, even though it wastes some addresses. So you assign HR the subnet 192.168.10.96/27. Its network address is 192.168.10.96, broadcast is 192.168.10.127, and usable addresses are 192.168.10.97 to 192.168.10.126.

Now you have used 128 addresses (from 0 to 127) out of your 256 available. The remaining addresses from 192.168.10.128 to 192.168.10.255 are free for future departments. By using the correct prefix lengths, you have efficiently allocated IP space while keeping each department in its own subnet. If you had used a /24 for the whole company, all devices would be in the same large network, causing performance issues from broadcast traffic. If you had used a /28 for Sales, they would not have enough addresses. This scenario shows how choosing the right prefix length meets both current and future needs.

Common Mistakes

Thinking that a /24 prefix gives exactly 256 usable host addresses.

A /24 network has 256 total addresses, but the first address (all host bits 0) is the network address and the last address (all host bits 1) is the broadcast address. These are not assignable to hosts. So the actual usable host count is 254, not 256.

Always subtract 2 from the total number of addresses in a subnet to get the usable host count. The formula is (2^(32 - prefix_length)) - 2.

Confusing the prefix length with the number of hosts. For example, thinking a /28 gives 28 hosts.

The prefix length indicates the number of bits for the network portion, not the host portion. A /28 means 28 network bits and 4 host bits (since 32 total bits minus 28 = 4). The number of hosts is 2^4 - 2 = 14. It is easy to mix up the two numbers.

Remember that the host bits are 32 minus the prefix length. Calculate the number of host bits first, then use the formula 2^(host_bits) - 2.

Forgetting that subnet masks are written as a continuous string of 1s followed by 0s. For example, using 255.255.255.254 as a subnet mask.

A subnet mask must have all 1 bits in the leftmost positions and all 0 bits in the rightmost positions. 255.255.255.254 in binary is 11111111.11111111.11111111.11111110. That mask has 31 '1' bits, but the pattern is broken because the last octet ends with a '0' bit. This is not a valid subnet mask because the 1s are not contiguous. A valid /31 mask would be 255.255.255.254, but that is a special case used only for point-to-point links. In general, invalid masks cause routing issues.

Learn the valid binary patterns. Only use /8 (255.0.0.0), /16 (255.255.0.0), /24 (255.255.255.0), /25 (255.255.255.128), /26 (255.255.255.192), /27 (255.255.255.224), /28 (255.255.255.240), /29 (255.255.255.248), /30 (255.255.255.252), /31 (255.255.255.254), and /32 (255.255.255.255) for most cases.

Assuming that longer prefix lengths always mean more hosts.

Longer prefix lengths mean more bits are used for the network, leaving fewer bits for hosts. So a longer prefix length results in fewer usable hosts. For example, /30 gives 2 hosts, while /24 gives 254 hosts. The relationship is inverse.

Think of the prefix length as dividing the address space. A larger number (like /30) carves out a smaller piece of the pie (fewer hosts). A smaller number (like /16) carves out a larger piece (more hosts).

Exam Trap — Don't Get Fooled

{"trap":"The exam gives you an IP address and a prefix length, then asks for the network address. You are tempted to simply use the prefix length as the number of bits to keep, but you forget to convert the host bits to zeros.","why_learners_choose_it":"Learners see the prefix length and think they can just take the first X bits of the IP address and fill the rest with zeros without considering the binary conversion.

They might accidentally change the network portion incorrectly because they do not perform the binary AND operation.","how_to_avoid_it":"Always convert the IP address and the subnet mask (derived from the prefix length) to binary. Then perform a logical AND operation.

For example, for 192.168.1.55/24, the mask is 255.255.255.0. In binary, the IP is 11000000.10101000.00000001.00110111. The mask is 11111111.11111111.11111111.00000000. The AND result is 11000000.

10101000.00000001.00000000, which is 192.168.1.0. Practice this until it is automatic. Alternatively, remember that for common prefix lengths, the network address is the IP address with the host portion set to zero.

For /24, the last octet becomes 0; for /16, the last two octets become 0. But for less common lengths like /27, you need to do the calculation carefully."

Step-by-Step Breakdown

1

Identify the prefix length

Look at the CIDR notation after the IP address, for example /24. The number indicates how many bits are dedicated to the network portion of the address. This is the starting point for all subnetting calculations.

2

Convert prefix length to subnet mask

Write the prefix length as a number of binary 1 bits, then fill the remaining bits with 0. For /24, that is 24 ones followed by 8 zeros: 11111111.11111111.11111111.00000000. Convert each octet to decimal to get 255.255.255.0.

3

Calculate the number of host bits

Subtract the prefix length from the total number of bits (32 for IPv4). For /24, host bits = 32 - 24 = 8. This tells you how many bits are available for devices on the subnet.

4

Calculate the total number of addresses in the subnet

Raise 2 to the power of the number of host bits. For 8 host bits, 2^8 = 256. This is the total number of IP addresses in that subnet, including the network and broadcast addresses.

5

Calculate the number of usable host addresses

Subtract 2 from the total number of addresses to exclude the network address and broadcast address. For 256 total, 256 - 2 = 254 usable hosts. This is the number of devices you can actually assign an IP to.

6

Determine the network address

Take the IP address and set all host bits to 0. For example, for 192.168.1.55/24, the last 8 bits (host bits) are set to 0, giving 192.168.1.0. This address identifies the subnet itself and cannot be assigned to a device.

7

Determine the broadcast address

Take the network address and set all host bits to 1. For 192.168.1.0/24, set the last 8 bits to 1, giving 192.168.1.255. This address is used to send data to all devices in the subnet and cannot be assigned to a host.

Practical Mini-Lesson

In a real IT environment, assigning the correct prefix length is a daily task for network administrators. When you design a network, you start by determining how many subnets you need and how many devices each subnet must support. Then you allocate a block of IP addresses from your ISP or internal address range. You must choose prefix lengths that provide enough host addresses without wasting too many.

For example, consider a company that has been allocated the 10.0.0.0/8 private address block (a huge range). You might use a /16 prefix for each regional office, giving each office over 65,000 addresses. Then within an office, you use /24 subnets for each floor or department. For server clusters that need only a few addresses, you might use /29 or /30 subnets. This hierarchical approach, called Variable Length Subnet Masking (VLSM), allows efficient use of the address space.

Configuring devices with the correct prefix length is crucial. On a router interface, you must specify both the IP address and the subnet mask (or prefix length). If you get the prefix length wrong, the router will think the interface belongs to a different network, and routing will not work correctly. For example, if you configure an interface with 192.168.1.1/24, the router expects all devices in 192.168.1.0/24 to be directly connected. If you then connect a device with IP 192.168.1.100/25 (which belongs to a different subnet 192.168.1.0/25), the router will not be able to communicate with it directly, because it treats the two as separate networks.

Another common practical situation is troubleshooting connectivity issues. If a user cannot reach a server, you might check the IP configuration of their computer. One common error is a misconfigured prefix length. For instance, if the computer is set to 192.168.1.100 with a /24 prefix, it will assume that any address in 192.168.1.0/24 is local. But if the actual network uses a /16 prefix, the computer will not communicate with devices outside that /24 range unless there is a router. Checking the prefix length is a standard step in network troubleshooting.

Professional network engineers use subnet calculators and IP address management (IPAM) tools to keep track of prefix lengths and avoid overlaps. Overlapping subnets occur when two different networks use the same prefix length and IP range, which causes routing confusion and data delivery failures. IPAM tools help document and allocate address space correctly.

prefix length affects the performance of routing protocols. When a router learns a route via OSPF or EIGRP, it stores the prefix length along with the network address. Routers use the longest prefix matching rule: when multiple routes match a destination, the route with the longest prefix length (most specific) is chosen. This is how routers make forwarding decisions. For example, a route to 10.1.1.0/24 is preferred over a route to 10.1.0.0/16 for any address within the /24 range.

mastering prefix length is not just about passing exams; it is about building reliable, efficient networks. Practice by designing subnets for different scenarios, and always verify your calculations before deploying changes.

Memory Tip

To find the number of hosts, subtract the prefix from 32, then raise 2 to that power and subtract 2. For /24: 32-24=8, 2^8=256, 256-2=254 hosts.

Covered in These Exams

Current Exam Context

Current exam versions that test this topic — use these objectives when studying.

Legacy Exam Context

Older materials may mention these exam versions, but learners should use the current objectives for their target exam.

N10-008N10-009(current version)

Related Glossary Terms