Home > Java Core > Check if IP is in CIDR Range

Check if IP is in CIDR Range

Java class to find if the given IP is in range of CIDR provided, this utility will help in cases mostly like whitelisting the features in any application. Features like we have to restrict any endpoint from getting called outside of the given CIDR IP range. This is the core java library class, no other jar is required.

CIDR (Classless Inter-Domain Routing) notation is a compact method for specifying IP addresses and their routing suffixes.

The CIDR notation is typically preceded by a slash “/” and follows the IP address. For example, we can express the idea that the IP address is associated with the netmask by using the CIDR notation of, where 24 represents the number of network bits in the IP address (IPv4 address has 32 bits, so the network can be between 0 and 32).