Skip to content

CIDR calculator

Work out the first and last address, size and mask of an IPv4 or IPv6 CIDR range, and check whether an address falls inside it.

Runs in your browser. Nothing you paste is sent to us.

Range

IPv4 or IPv6. A sample private range is filled in.

10.20.3.17 is inside the range.

Details

IPv4 /22 Private network (RFC 1918)

CIDR
10.20.0.0/22
First address
10.20.0.0
Last address
10.20.3.255The broadcast address
Addresses
1,024
Usable hosts
1,02210.20.0.1 to 10.20.3.254
Netmask
255.255.252.0
Wildcard mask
0.0.3.255
In an allow list, a /32 (IPv4) or /128 (IPv6) is one address. Prefer the narrowest range that covers your addresses.

How to use it

  1. Enter a range such as 10.20.0.0/22 or 2001:db8::/48.
  2. Read the first and last address, the size and the mask.
  3. Enter an address to check whether the range covers it.
  4. Copy the range into your allow list or firewall rule.

What to know

A CIDR range is an address and a prefix length: the prefix says how many leading bits are fixed. A /24 in IPv4 holds 256 addresses; each step down doubles the size.

For IPv4 the first address names the network and the last is the broadcast address, so a /24 has 254 usable hosts. A /31 is a point-to-point link where both addresses are usable.

Keycloak has no IP allow list of its own for the admin console. Restricting it by address is usually done at the reverse proxy or load balancer in front of it.

What CIDR notation is

CIDR (Classless Inter-Domain Routing) notation writes a block of IP addresses as an address and a prefix length: 10.20.0.0/22. The prefix length says how many leading bits are fixed. All addresses that share those bits belong to the block.

CIDR replaced the old fixed classes A, B and C in the 1990s and is described in RFC 4632 for IPv4. IPv6 uses the same notation from the start. Firewalls, cloud security groups, Kubernetes network policies and reverse proxy allow lists all speak CIDR.

This calculator turns a CIDR block into its first and last address, size and masks, and checks whether a given address falls inside it. It handles IPv4 and IPv6.

How a CIDR block is worked out

The prefix length becomes a mask: that many 1 bits followed by 0 bits. AND the address with the mask to get the first address; set all the host bits to 1 to get the last.

Breaking down 10.20.0.0/22, the sample on this page
10.20.0.0/22

Address   00001010.00010100.000000|00.00000000
Mask      11111111.11111111.111111|00.00000000   = 255.255.252.0
          <------ 22 network bits ------>|<- 10 host bits ->

First     10.20.0.0
Last      10.20.3.255     (all 10 host bits set)
Size      2^10 = 1,024 addresses
IPv4 prefixAddressesNetmaskCommon use
/321255.255.255.255A single host
/312255.255.255.254A point-to-point link
/304255.255.255.252A small link with 2 usable hosts
/2816255.255.255.240A small subnet
/24256255.255.255.0A typical LAN or cloud subnet
/1665,536255.255.0.0A virtual network or VPC
/816,777,216255.0.0.0A very large private range

Usable hosts in IPv4

In a traditional IPv4 subnet, the first address names the network and the last is the broadcast address, so neither is given to a host. A /24 has 256 addresses and 254 usable hosts. A /31 is the exception: RFC 3021 allows both addresses on a point-to-point link. A /32 is a single host.

Cloud providers often reserve a few more addresses at the start of each subnet for their own routers and DNS; check your provider’s documentation for the exact count.

IPv6

IPv6 addresses are 128 bits, written as eight groups of four hex digits, with :: standing for one run of zero groups. There is no broadcast address. A single LAN is normally a /64, which holds 2^64 addresses; sites are often given a /48 or /56.

This calculator prints IPv6 addresses in the canonical short form of RFC 5952: lowercase, leading zeros dropped, and the longest run of zero groups replaced by ::.

Special ranges worth recognizing

Some ranges are reserved for particular uses. The calculator labels them when a block falls inside one.

RangeMeaningDefined in
10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16Private networks, not routed on the internetRFC 1918
100.64.0.0/10Shared address space for carrier-grade NATRFC 6598
127.0.0.0/8, ::1/128LoopbackRFC 1122, RFC 4291
169.254.0.0/16, fe80::/10Link-localRFC 3927, RFC 4291
192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24Documentation and examplesRFC 5737
2001:db8::/32IPv6 documentation and examplesRFC 3849
fc00::/7IPv6 unique local addresses, the private rangeRFC 4193
224.0.0.0/4, ff00::/8MulticastRFC 5771, RFC 4291

What this calculator does and does not do

  • It reads an IPv4 or IPv6 CIDR block, or a single address, which it treats as a /32 or /128.
  • It shows the first and last address, the number of addresses, and for IPv4 the usable hosts, netmask and wildcard mask; for IPv6 the full expanded form.
  • It warns when you type an address with host bits set, such as 10.20.3.17/22, and shows the block it actually names.
  • It checks whether an address is inside the block.
  • It labels private, documentation, loopback and other special ranges.
  • It rejects ambiguous input such as IPv4 parts with leading zeros, which some systems read as octal.
  • It does not split a block into subnets or merge several blocks into one.

How to use it

  1. Type a block such as 203.0.113.0/24 or 2001:db8:1234::/48.
  2. Read the first and last address and the size.
  3. If a warning says host bits are set, use the network address it shows in your configuration.
  4. Type an address in the second field to check whether the block covers it.
  5. Copy the CIDR into your firewall, security group or proxy allow list.

CIDR in identity infrastructure

Address ranges come up whenever you restrict who can reach part of an identity system.

Restricting the Keycloak admin console

Keycloak has no IP allow list of its own for the admin console. The usual approach is to block or restrict the admin paths at the reverse proxy or load balancer in front of it, allowing only office, VPN or bastion ranges. Keycloak can also serve the admin console on a separate host name with the hostname-admin option, which makes it easier to keep that host internal.

Trusting a reverse proxy

Behind a proxy, Keycloak reads the client’s address and the original scheme from forwarded headers when proxy-headers is set. Only the proxy should be able to reach Keycloak directly; otherwise anyone can send forged forwarded headers. Restrict access to Keycloak’s port to the proxy’s addresses with a network rule.

Outbound allow lists

Identity providers call out to other systems: LDAP directories, SMTP servers, external identity providers and webhook targets. Firewalls that limit outbound traffic need those systems’ ranges.

Conditional access by network

Some organizations require a second factor only from outside the corporate network. That rule needs a precise list of the corporate ranges, and checking an address against them is exactly what the second field of this calculator does.

Common mistakes

  • Writing an address with host bits set, such as 10.20.3.17/22, where the network address 10.20.0.0/22 was meant. Some tools silently fix it, others reject it, and some match something different.
  • Off-by-one prefixes: a /23 is twice the size of a /24, and a /25 half.
  • Forgetting IPv6. A rule that allows an IPv4 range does nothing for users who connect over IPv6.
  • Allowing a whole cloud provider’s range when only one of your services lives there. Anyone else on that provider is then allowed too.
  • Writing IPv4 parts with leading zeros, such as 010.001.000.000, which some parsers read as octal.
  • Trusting client IP headers such as X-Forwarded-For without checking that the request came from your own proxy.

Security notes

IP restrictions are a useful outer layer, not authentication. Addresses can be shared, as with carrier-grade NAT and VPNs, and they change. Keep strong authentication, including a second factor, on admin access even when it is restricted by network.

Keep allow lists as narrow as you can, and review them. Ranges for offices and VPNs that no longer exist are a common leftover.

Splitting and combining blocks

Each step in prefix length halves or doubles a block. A /22 splits into two /23s, four /24s or eight /25s, and two neighboring /24s combine into a /23 only if they start on a /23 boundary.

BlockSplits intoRanges
10.20.0.0/22Four /24s10.20.0.0/24, 10.20.1.0/24, 10.20.2.0/24, 10.20.3.0/24
10.20.0.0/23Two /24s10.20.0.0/24, 10.20.1.0/24
10.20.1.0/24 and 10.20.2.0/24Cannot combineThey do not share a /23; the smallest single block covering both is 10.20.0.0/22

When planning networks for a cluster, leave room: pod and service ranges must not overlap each other, the node network, or any network you connect to through VPN or peering.

Questions

Frequently asked questions

How many IP addresses are in a /24?

256 addresses. In a traditional IPv4 subnet, 254 of them are usable hosts, because the first is the network address and the last is the broadcast address.

What does /32 mean?

In IPv4, a /32 is a single address: all 32 bits are fixed. The IPv6 equivalent is /128.

How do I calculate the range of a CIDR block?

Turn the prefix into a mask of that many 1 bits. AND the address with the mask to get the first address, and set all remaining bits to 1 to get the last. The block holds 2 to the power of the host bits addresses.

What is a wildcard mask?

The inverse of the netmask: 0.0.0.255 for a /24. Some routers and firewalls, notably in access control lists, take a wildcard mask instead of a prefix length.

Is 10.20.3.17/22 a valid CIDR?

It names the block 10.20.0.0/22, but it has host bits set, so many tools reject or rewrite it. Write the network address, 10.20.0.0/22, in configuration.

What is the IPv6 equivalent of a private range?

Unique local addresses, fc00::/7, defined in RFC 4193. In practice they are allocated from fd00::/8 with a random 40-bit prefix.

Why does a /31 have two usable addresses?

RFC 3021 allows /31 blocks on point-to-point links, where no network or broadcast address is needed, so both addresses can be used.

Can Keycloak restrict access by IP address?

Not for the admin console out of the box. Restrict admin paths at the reverse proxy or load balancer, or serve the admin console on a separate internal host name.

Rather not run Keycloak yourself?

We run it for you on a cluster of your own, with backups, upgrades and written support. Starter and Premium begin with a 7-day trial.