Skip to content

Bitmask

Transform IP addresses using bitwise binary operations. Useful for changing subnets (especially for IPv6 addresses).

OperationThe bitwise binary operation to perform (and or or)
MasksA function that returns the binary masks to apply
InnerA function that returns IP addresses that the binary masks will be applied to

IP addresses (results from Inner that have been transformed by the masks in Masks)

Assuming a constant Inner function with an IP address 2001:db8:cafe::dead:beef

An and bitmask can effectively remove bits from an IP address:

Given a mask of ::ffff:ffff and an inner address of 2001:db8:cafe::dead:beef, returns ::dead:beef.

An or bitmask can effectively add bits to an IP address:

Given a mask of 2001:db8:cafe:: and an inner address of ::dead:beef, returns 2001:db8:cafe::dead:beef.