public function getMask(): IP
    {
        if ($this->mask === null) {
            if ($this->prefix == 0) {
                $this->mask = new static::$ip_class(0);
            } else {
                $max_int = gmp_init(static::$ip_class::MAX_INT);
                $mask = gmp_shiftl($max_int, static::$ip_class::NB_BITS - $this->prefix);
                $mask = gmp_and($mask, $max_int); // truncate to 128 bits only
                $this->mask = new static::$ip_class($mask);
            }
        }

        return $this->mask;
    }