Mask
With computers, a mask is a special value that acts as a data filter. It's called a "mask" because it reveals some parts of digital information, and conceals or alters others.
Bitmasks
In binary operations, a bitmask can filter bit values using logical operations. For instance, a bitmask of 00001111 one operand of the boolean AND operation, it converts the first four bits of the other operand to 0. The final four bits will be unchanged. This operation is called "masking out" the first four bits, changing them to 0.
If the OR operator is used, any 1 values in the bitmask produce a 1 in the corresponding result, and other bits remain unchanged. So, a bitmask of 00001111, used with OR, will "mask out" the last four bits, changing them to 1.
If the XOR operator is used, any 1s in the bitmask cause corresponding bits in the operand to be toggled — 1 becomes 0, and 0 becomes 1.
Bitmask examples | ||||
---|---|---|---|---|
Bitmask | 00001111 | 00001111 | 00001111 | 00001111 |
Operation | AND | AND | OR | XOR |
Operand | 11010010 | 01101101 | 10010110 | 01011010 |
Result | 00000010 | 00001101 | 10011111 | 01010101 |
Netmask
A netmask is another type of bitmask, used in computer networking. One type of netmask, a subnet mask, defines logical divisions ("subnets") of a computer network. For instance, a subnet mask of 255.255.255.0 masks out the first three bytes of an IP address, leaving only the final byte — the host identifier.
Search masks
In Microsoft Windows, a search mask is a string, which may contain wildcards, which filters search results. It's commonly used to search for files by name. For instance, in the command:
forfiles /m "s*.exe"
The search mask s*.exe is used by the forfiles command to locate all .exe files in the current directory whose name begins with s.
Umask
In Unix-like operating systems, such as Linux, BSD (Berkeley Software Distribution), and macOS X, a umask is an octal value mask that defines the permissions of new files.
For information about user file creation masks in Linux, see umask in our Linux command guide.