First step: translate 192.168.1.0/22 into something you can use as a mask. 192.168.1.0/22 means that the first 22 bits of the IP in question must be identical to the first 22 bits in the base IP. BTW, each octet of the IP can be at most 255, so your sample IP of 192.168.1.312 was invalid. Untested code: [code=php:0] // Expects $base_ip and $ip to be in dotted format function in_network( $base_id, $bit, $ip) { $base_ip = ip2long( $base_ip ); $test1 = $base_ip >> ( 32 - $bits ) $ip = ip2long($ip); $test2 = $ip >> (32 - $bits ); return $test1 == $test2; } if ( in_network('192.168.1.0', 22, '192.168.1.212') ) { echo "Same network!"; } else { echo "Different network!"; } [/code]