KAHIBARO Bookshelves
Discord Login Register

7.5. CIDR

Understanding CIDR

Classless Inter‑Domain Routing, or CIDR, is a way to write IP address ranges and subnet masks more flexibly and efficiently than the old classful system. In CIDR, you describe a network using an IP address plus a prefix length, such as 192.168.10.0/24. The prefix length tells you how many bits at the start of the address belong to the network part. CIDR is used everywhere in modern IP addressing, from small home networks to global internet routing.

From Subnet Masks to Prefix Length

In classful addressing, networks were grouped into fixed classes with fixed masks, but CIDR ignores those classes and simply uses a prefix length. The prefix length represents the number of 1 bits in the subnet mask, counted from the left.

For example, the following masks and prefixes match:

Subnet maskBinary mask (first bits)Prefix
255.0.0.011111111.00000000.00000000.00000000/8
255.255.0.011111111.11111111.00000000.00000000/16
255.255.255.011111111.11111111.11111111.00000000/24
255.255.255.12811111111.11111111.11111111.10000000/25
255.255.255.19211111111.11111111.11111111.11000000/26
255.255.255.24011111111.11111111.11111111.11110000/28

In CIDR notation, you always write an IP address, a slash, and the prefix length, for example:

  • 10.0.0.0/8
  • 172.16.0.0/16
  • 192.168.1.0/24
  • 192.168.1.128/25

The IP address in CIDR notation is the network address for that block, not a random host in the range.

Network and Host Bits

In CIDR, the prefix defines the network bits, and the remaining bits are host bits. If you have an IPv4 address, there are always 32 bits in total. If the prefix is /n, then there are $n$ network bits and $32 - n$ host bits.

For example:

  • /24 means 24 network bits and 8 host bits.
  • /26 means 26 network bits and 6 host bits.
  • /30 means 30 network bits and 2 host bits.

CIDR does not care whether the address would have been Class A, B, or C. Only the prefix length matters.

Calculating Number of Addresses

Once you know the prefix length, you can calculate how many IP addresses are in that CIDR block. The number of host bits is $h = 32 - \text{prefix}$. The total number of addresses in the block is then $2^h$.

For an IPv4 CIDR block with prefix length $/n$:

  • Host bits: $h = 32 - n$
  • Total addresses: $2^h$

If you need usable host addresses on a typical IPv4 subnet, you normally subtract the network address and the broadcast address. So the number of usable host addresses is usually $2^h - 2`, except for very small prefixes where special rules may apply.

Some common examples:

CIDRHost bitsTotal addressesUsable hosts (typical)
/248$2^8 = 256$254
/257$2^7 = 128$126
/266$2^6 = 64$62
/275$2^5 = 32$30
/284$2^4 = 16$14
/293$2^3 = 8$6
/302$2^2 = 4$2

Finding the Network Range from CIDR

When you see a CIDR block, you can determine the network address, broadcast address, and the first and last usable host addresses by looking at the prefix and the remaining host bits.

The size of each block in the last affected octet is determined by the number of host bits in that octet. For IPv4, each octet is 8 bits, so you can look at where the prefix cuts across the octets.

An easy way to think about block size is:

  1. Find how many host bits are in the last octet that contains part of the network.
  2. The block size in that octet is $2^{\text{host\_bits\_in\_that\_octet}}$.

For example, consider 192.168.10.0/26.

  • Prefix is /26, so there are $32 - 26 = 6$ host bits total.
  • The first 24 bits are the first three octets, and the next 2 bits are in the fourth octet.
  • That leaves 6 host bits, all in the fourth octet. So the block size in the fourth octet is $2^6 = 64$.

So the ranges in the fourth octet are:

  • 0 to 63
  • 64 to 127
  • 128 to 191
  • 192 to 255

Because the network is 192.168.10.0/26:

  • Network address: 192.168.10.0
  • Broadcast address: 192.168.10.63
  • First usable host: 192.168.10.1
  • Last usable host: 192.168.10.62

Another example is 192.168.10.128/25.

  • Prefix is /25, so host bits are $32 - 25 = 7`.
  • The first 24 bits are full octets, plus 1 network bit in the fourth octet, leaving 7 host bits there.
  • Block size in the fourth octet is $2^7 = 128$.

The ranges in the fourth octet are:

  • 0 to 127
  • 128 to 255

The network 192.168.10.128/25 covers:

  • Network address: 192.168.10.128
  • Broadcast address: 192.168.10.255
  • First usable host: 192.168.10.129
  • Last usable host: 192.168.10.254

Converting Between CIDR and Subnet Masks

You can move between prefix length and dotted decimal masks by counting bits.

To find the mask from a prefix:

  1. Write 32 bits.
  2. Fill the first $n$ bits with 1, where $n$ is the prefix length.
  3. Fill the remaining bits with 0.
  4. Group the bits into four sets of 8 and convert to decimal.

To find the prefix from a mask:

  1. Convert each octet to binary.
  2. Count the total number of 1 bits from the left until you reach the first 0.
  3. That count is the prefix length.

Some common conversions are:

PrefixSubnet mask
/8255.0.0.0
/16255.255.0.0
/24255.255.255.0
/25255.255.255.128
/26255.255.255.192
/27255.255.255.224
/28255.255.255.240
/29255.255.255.248
/30255.255.255.252

To get the number of addresses from a prefix $/n$:

  1. Host bits: $h = 32 - n$
  2. Total addresses: $2^h$
  3. Typical usable hosts: $2^h - 2$

CIDR and Route Aggregation

CIDR is not only about local subnetting. It is also very important for aggregation of routes, which is also called route summarization. Instead of announcing many small routes, a router can announce one larger CIDR block that covers them all. This reduces the size of routing tables.

For example, imagine a provider has these networks:

  • 192.168.0.0/24
  • 192.168.1.0/24
  • 192.168.2.0/24
  • 192.168.3.0/24

All of these share the same first 22 bits. They can be combined into a single summary:

  • 192.168.0.0/22

This one route tells others that the provider can reach any address from 192.168.0.0 to 192.168.3.255. Inside its own network the provider can still use the individual /24 networks, but outside, other routers only see the single /22 route.

CIDR allows this type of flexible aggregation because it ignores fixed class boundaries and uses only the prefix length.

CIDR and Classless Addressing

With classful addressing, there were only three main network sizes: Class A, Class B, and Class C. CIDR removed these fixed sizes and allows any prefix from /0 to /32 for IPv4.

Some interesting examples:

  • /32 represents a single IP address, often used for a specific host or a loopback address.
  • /31 historically had no usable hosts, but some modern systems use it for point to point links where there is no need for broadcast.
  • /0 would represent the entire IPv4 space, and in routing is known as the default route.

CIDR gives network designers the ability to choose address block sizes that match actual needs instead of being limited by fixed classes. This flexibility is used in subnetting within an organization and also in summarization toward the internet.

Views: 0

Comments

Please login to add a comment.

Don't have an account? Register now!

Where to Move

Move chapter:

  • ☰ 1. Introduction to Networking
    • ☰ 1.1. What is a Computer Network?
      • ☰ 1.2. Why Networks Matter
        • ☰ 1.3. Types of Networks
          • ☰ 1.3.1. PAN
            • ☰ 1.3.2. LAN
              • ☰ 1.3.3. MAN
                • ☰ 1.3.4. WAN
                • ☰ 1.4. Network Topologies
                  • ☰ 1.4.1. Bus
                    • ☰ 1.4.2. Star
                      • ☰ 1.4.3. Ring
                        • ☰ 1.4.4. Mesh
                        • ☰ 1.5. Network Components
                          • ☰ 1.5.1. Hosts
                            • ☰ 1.5.2. Clients / Servers
                              • ☰ 1.5.3. NICs
                                • ☰ 1.5.4. Switches
                                  • ☰ 1.5.5. Routers
                                    • ☰ 1.5.6. Modems
                                    • ☰ 1.6. Bandwidth, Latency, Throughput
                                    • ☰ 2. Binary and Networking Fundamentals
                                      • ☰ 2.1. Binary Numbers
                                        • ☰ 2.2. Bits vs Bytes
                                          • ☰ 2.3. Decimal ↔ Binary Conversion
                                            • ☰ 2.4. Hexadecimal Basics
                                              • ☰ 2.5. Data Units (Kbps, Mbps, Gbps)
                                                • ☰ 2.6. Encapsulation
                                                • ☰ 3. OSI Model
                                                  • ☰ 3.1. Why Layering?
                                                    • ☰ 3.2. Overview of 7 Layers
                                                      • ☰ 3.3. Physical Layer
                                                        • ☰ 3.4. Data Link Layer
                                                          • ☰ 3.5. Network Layer
                                                            • ☰ 3.6. Transport Layer
                                                              • ☰ 3.7. Session Layer
                                                                • ☰ 3.8. Presentation Layer
                                                                  • ☰ 3.9. Application Layer
                                                                    • ☰ 3.10. Encapsulation & Decapsulation
                                                                      • ☰ 3.11. Packet Journey
                                                                      • ☰ 4. TCP/IP Model
                                                                        • ☰ 4.1. TCP/IP vs OSI
                                                                          • ☰ 4.2. Internet Layer
                                                                            • ☰ 4.3. Transport Layer
                                                                              • ☰ 4.3.1. Ports & Sockets
                                                                                • ☰ 4.3.2. TCP Overview
                                                                                  • ☰ 4.3.3. Three-Way Handshake
                                                                                    • ☰ 4.3.4. Reliable Transmission
                                                                                      • ☰ 4.3.5. Flow Control
                                                                                        • ☰ 4.3.6. Congestion Control
                                                                                          • ☰ 4.3.7. UDP
                                                                                            • ☰ 4.3.8. TCP vs UDP
                                                                                            • ☰ 4.4. Application Layer
                                                                                              • ☰ 4.5. Packet Flow
                                                                                              • ☰ 5. Physical Layer & Transmission Media
                                                                                                • ☰ 5.1. Electrical Signals
                                                                                                  • ☰ 5.2. Copper Cables
                                                                                                    • ☰ 5.2.1. Twisted Pair
                                                                                                      • ☰ 5.2.2. Coaxial
                                                                                                      • ☰ 5.3. Fiber Optics
                                                                                                        • ☰ 5.4. Wireless Transmission
                                                                                                          • ☰ 5.5. Duplex Modes
                                                                                                            • ☰ 5.6. Signal Loss
                                                                                                              • ☰ 5.7. Error Detection
                                                                                                              • ☰ 6. Ethernet and Switching
                                                                                                                • ☰ 6.1. Ethernet Basics
                                                                                                                  • ☰ 6.2. MAC Addresses
                                                                                                                    • ☰ 6.3. Ethernet Frames
                                                                                                                      • ☰ 6.4. Collision Domains
                                                                                                                        • ☰ 6.5. Broadcast Domains
                                                                                                                          • ☰ 6.6. Hubs vs Switches
                                                                                                                            • ☰ 6.7. MAC Learning
                                                                                                                              • ☰ 6.8. VLANs
                                                                                                                                • ☰ 6.9. Trunking (802.1Q)
                                                                                                                                  • ☰ 6.10. Spanning Tree Protocol
                                                                                                                                  • ☰ 7. IP Addressing
                                                                                                                                    • ☰ 7.1. IPv4 Fundamentals
                                                                                                                                      • ☰ 7.2. Public vs Private IP
                                                                                                                                        • ☰ 7.3. Classful Addressing
                                                                                                                                          • ☰ 7.4. Subnet Masks
                                                                                                                                            • ☰ 7.5. CIDR
                                                                                                                                              • ☰ 7.6. Subnetting
                                                                                                                                                • ☰ 7.7. VLSM
                                                                                                                                                  • ☰ 7.8. Supernetting
                                                                                                                                                    • ☰ 7.9. IP Planning
                                                                                                                                                    • ☰ 8. IPv6
                                                                                                                                                      • ☰ 8.1. Why IPv6?
                                                                                                                                                        • ☰ 8.2. IPv6 Address Format
                                                                                                                                                          • ☰ 8.3. Address Types
                                                                                                                                                            • ☰ 8.4. IPv6 Header
                                                                                                                                                              • ☰ 8.5. SLAAC
                                                                                                                                                                • ☰ 8.6. Neighbor Discovery
                                                                                                                                                                  • ☰ 8.7. IPv4 vs IPv6
                                                                                                                                                                  • ☰ 9. Routing Fundamentals
                                                                                                                                                                    • ☰ 9.1. What is Routing?
                                                                                                                                                                      • ☰ 9.2. Static Routing
                                                                                                                                                                        • ☰ 9.3. Dynamic Routing
                                                                                                                                                                          • ☰ 9.4. Routing Tables
                                                                                                                                                                            • ☰ 9.5. Administrative Distance
                                                                                                                                                                              • ☰ 9.6. Metrics
                                                                                                                                                                                • ☰ 9.7. Default Routes
                                                                                                                                                                                  • ☰ 9.8. Route Summarization
                                                                                                                                                                                  • ☰ 10. Routing Protocols
                                                                                                                                                                                    • ☰ 10.1. Distance Vector Routing
                                                                                                                                                                                      • ☰ 10.2. Link State Routing
                                                                                                                                                                                        • ☰ 10.3. RIP
                                                                                                                                                                                          • ☰ 10.4. OSPF
                                                                                                                                                                                            • ☰ 10.5. EIGRP
                                                                                                                                                                                              • ☰ 10.6. BGP
                                                                                                                                                                                                • ☰ 10.7. Path Selection
                                                                                                                                                                                                  • ☰ 10.8. Convergence
                                                                                                                                                                                                  • ☰ 11. ARP, ICMP, and Core Protocols
                                                                                                                                                                                                    • ☰ 11.1. ARP
                                                                                                                                                                                                      • ☰ 11.2. Gratuitous ARP
                                                                                                                                                                                                        • ☰ 11.3. ICMP
                                                                                                                                                                                                          • ☰ 11.4. Ping
                                                                                                                                                                                                            • ☰ 11.5. Traceroute
                                                                                                                                                                                                              • ☰ 11.6. MTU & Fragmentation
                                                                                                                                                                                                              • ☰ 12. DNS and Name Resolution
                                                                                                                                                                                                                • ☰ 12.1. Why DNS?
                                                                                                                                                                                                                  • ☰ 12.2. Domain Hierarchy
                                                                                                                                                                                                                    • ☰ 12.3. Recursive Queries
                                                                                                                                                                                                                      • ☰ 12.4. DNS Record Types
                                                                                                                                                                                                                        • ☰ 12.4.1. A
                                                                                                                                                                                                                          • ☰ 12.4.2. AAAA
                                                                                                                                                                                                                            • ☰ 12.4.3. CNAME
                                                                                                                                                                                                                              • ☰ 12.4.4. MX
                                                                                                                                                                                                                                • ☰ 12.4.5. TXT
                                                                                                                                                                                                                                • ☰ 12.5. DNS Caching
                                                                                                                                                                                                                                  • ☰ 12.6. DNS Security
                                                                                                                                                                                                                                  • ☰ 13. Application Layer Protocols
                                                                                                                                                                                                                                    • ☰ 13.1. HTTP / HTTPS
                                                                                                                                                                                                                                      • ☰ 13.2. FTP / SFTP
                                                                                                                                                                                                                                        • ☰ 13.3. SMTP
                                                                                                                                                                                                                                          • ☰ 13.4. POP3
                                                                                                                                                                                                                                            • ☰ 13.5. IMAP
                                                                                                                                                                                                                                              • ☰ 13.6. SSH
                                                                                                                                                                                                                                                • ☰ 13.7. Telnet
                                                                                                                                                                                                                                                  • ☰ 13.8. DHCP
                                                                                                                                                                                                                                                    • ☰ 13.9. SNMP
                                                                                                                                                                                                                                                      • ☰ 13.10. NTP
                                                                                                                                                                                                                                                      • ☰ 14. Wireless Networking
                                                                                                                                                                                                                                                        • ☰ 14.1. Radio Fundamentals
                                                                                                                                                                                                                                                          • ☰ 14.2. Wi-Fi Standards
                                                                                                                                                                                                                                                            • ☰ 14.3. Frequency Bands
                                                                                                                                                                                                                                                              • ☰ 14.4. Channels
                                                                                                                                                                                                                                                                • ☰ 14.5. Roaming
                                                                                                                                                                                                                                                                  • ☰ 14.6. Interference
                                                                                                                                                                                                                                                                    • ☰ 14.7. WPA2 / WPA3
                                                                                                                                                                                                                                                                      • ☰ 14.8. Enterprise Wi-Fi
                                                                                                                                                                                                                                                                      • ☰ 15. NAT and Internet Connectivity
                                                                                                                                                                                                                                                                        • ☰ 15.1. NAT Basics
                                                                                                                                                                                                                                                                          • ☰ 15.2. PAT
                                                                                                                                                                                                                                                                            • ☰ 15.3. Port Forwarding
                                                                                                                                                                                                                                                                              • ☰ 15.4. ISP Concepts
                                                                                                                                                                                                                                                                                • ☰ 15.5. CGNAT
                                                                                                                                                                                                                                                                                  • ☰ 15.6. Internet Routing
                                                                                                                                                                                                                                                                                  • ☰ 16. Network Security Fundamentals
                                                                                                                                                                                                                                                                                    • ☰ 16.1. CIA Triad
                                                                                                                                                                                                                                                                                      • ☰ 16.2. Firewalls
                                                                                                                                                                                                                                                                                        • ☰ 16.3. ACLs
                                                                                                                                                                                                                                                                                          • ☰ 16.4. VPN
                                                                                                                                                                                                                                                                                            • ☰ 16.5. IDS / IPS
                                                                                                                                                                                                                                                                                              • ☰ 16.6. Zero Trust
                                                                                                                                                                                                                                                                                                • ☰ 16.7. DDoS
                                                                                                                                                                                                                                                                                                  • ☰ 16.8. Malware in Networks
                                                                                                                                                                                                                                                                                                    • ☰ 16.9. Security Hardening
                                                                                                                                                                                                                                                                                                    • ☰ 17. Network Services
                                                                                                                                                                                                                                                                                                      • ☰ 17.1. Load Balancing
                                                                                                                                                                                                                                                                                                        • ☰ 17.2. Reverse Proxy
                                                                                                                                                                                                                                                                                                          • ☰ 17.3. Web Hosting
                                                                                                                                                                                                                                                                                                            • ☰ 17.4. CDN
                                                                                                                                                                                                                                                                                                              • ☰ 17.5. DNS Hosting
                                                                                                                                                                                                                                                                                                              • ☰ 18. Monitoring and Troubleshooting
                                                                                                                                                                                                                                                                                                                • ☰ 18.1. Troubleshooting Methodology
                                                                                                                                                                                                                                                                                                                  • ☰ 18.2. Layer-by-Layer Debugging
                                                                                                                                                                                                                                                                                                                    • ☰ 18.3. Ping / Traceroute
                                                                                                                                                                                                                                                                                                                      • ☰ 18.4. Netstat
                                                                                                                                                                                                                                                                                                                        • ☰ 18.5. Tcpdump
                                                                                                                                                                                                                                                                                                                          • ☰ 18.6. Wireshark
                                                                                                                                                                                                                                                                                                                            • ☰ 18.7. Logs
                                                                                                                                                                                                                                                                                                                              • ☰ 18.8. Packet Analysis
                                                                                                                                                                                                                                                                                                                              • ☰ 19. Virtualization and Cloud Networking
                                                                                                                                                                                                                                                                                                                                • ☰ 19.1. Virtual Switches
                                                                                                                                                                                                                                                                                                                                  • ☰ 19.2. Hypervisors
                                                                                                                                                                                                                                                                                                                                    • ☰ 19.3. SDN
                                                                                                                                                                                                                                                                                                                                      • ☰ 19.4. Overlay Networks
                                                                                                                                                                                                                                                                                                                                        • ☰ 19.5. Containers & Networking
                                                                                                                                                                                                                                                                                                                                          • ☰ 19.6. Kubernetes Networking
                                                                                                                                                                                                                                                                                                                                            • ☰ 19.7. Cloud VPCs
                                                                                                                                                                                                                                                                                                                                            • ☰ 20. Advanced Enterprise Networking
                                                                                                                                                                                                                                                                                                                                              • ☰ 20.1. MPLS
                                                                                                                                                                                                                                                                                                                                                • ☰ 20.2. VXLAN
                                                                                                                                                                                                                                                                                                                                                  • ☰ 20.3. EVPN
                                                                                                                                                                                                                                                                                                                                                    • ☰ 20.4. SD-WAN
                                                                                                                                                                                                                                                                                                                                                      • ☰ 20.5. QoS
                                                                                                                                                                                                                                                                                                                                                        • ☰ 20.6. Traffic Engineering
                                                                                                                                                                                                                                                                                                                                                        • ☰ 21. Automation & Infrastructure as Code
                                                                                                                                                                                                                                                                                                                                                          • ☰ 21.1. Why Automation?
                                                                                                                                                                                                                                                                                                                                                            • ☰ 21.2. APIs
                                                                                                                                                                                                                                                                                                                                                              • ☰ 21.3. REST
                                                                                                                                                                                                                                                                                                                                                                • ☰ 21.4. Python for Networking
                                                                                                                                                                                                                                                                                                                                                                  • ☰ 21.5. Netmiko
                                                                                                                                                                                                                                                                                                                                                                    • ☰ 21.6. Ansible
                                                                                                                                                                                                                                                                                                                                                                      • ☰ 21.7. Terraform
                                                                                                                                                                                                                                                                                                                                                                        • ☰ 21.8. Configuration Management
                                                                                                                                                                                                                                                                                                                                                                        • ☰ 22. Network Design
                                                                                                                                                                                                                                                                                                                                                                          • ☰ 22.1. Small Office Design
                                                                                                                                                                                                                                                                                                                                                                            • ☰ 22.2. Enterprise Design
                                                                                                                                                                                                                                                                                                                                                                              • ☰ 22.3. Data Center Networks
                                                                                                                                                                                                                                                                                                                                                                                • ☰ 22.4. Redundancy
                                                                                                                                                                                                                                                                                                                                                                                  • ☰ 22.5. High Availability
                                                                                                                                                                                                                                                                                                                                                                                    • ☰ 22.6. Capacity Planning
                                                                                                                                                                                                                                                                                                                                                                                    • ☰ 23. Specialized Topics
                                                                                                                                                                                                                                                                                                                                                                                      • ☰ 23.1. IoT Networking
                                                                                                                                                                                                                                                                                                                                                                                        • ☰ 23.2. Industrial Networks
                                                                                                                                                                                                                                                                                                                                                                                          • ☰ 23.3. 5G Basics
                                                                                                                                                                                                                                                                                                                                                                                            • ☰ 23.4. Satellite Networks
                                                                                                                                                                                                                                                                                                                                                                                              • ☰ 23.5. HPC Networking (InfiniBand, RDMA)
                                                                                                                                                                                                                                                                                                                                                                                                • ☰ 23.6. Edge Computing
                                                                                                                                                                                                                                                                                                                                                                                                • ☰ 24. Capstone Projects
                                                                                                                                                                                                                                                                                                                                                                                                  • ☰ 24.1. Home Lab Project
                                                                                                                                                                                                                                                                                                                                                                                                    • ☰ 24.2. Enterprise Network Design
                                                                                                                                                                                                                                                                                                                                                                                                      • ☰ 24.3. Secure Multi-Site Network
                                                                                                                                                                                                                                                                                                                                                                                                        • ☰ 24.4. Packet Analysis Project
                                                                                                                                                                                                                                                                                                                                                                                                          • ☰ 24.5. Cloud Networking Project
                                                                                                                                                                                                                                                                                                                                                                                                          • ☰ 25. Bonus Content
                                                                                                                                                                                                                                                                                                                                                                                                            • ☰ 25.1. Certification Prep (CCNA / CCNP)
                                                                                                                                                                                                                                                                                                                                                                                                              • ☰ 25.2. Interview Questions
                                                                                                                                                                                                                                                                                                                                                                                                                • ☰ 25.3. Hands-on Labs
                                                                                                                                                                                                                                                                                                                                                                                                                  • ☰ 25.4. Real-World Case Studies
                                                                                                                                                                                                                                                                                                                                                                                                                    • ☰ 25.5. Final Exam