File permissions in UNIX are frequently specified as an octal number. Why is octal the preferred base for this purpose?
Because the permissions are stored in a bit field, grouped in 3-bit chunks (eg rwx).
Octal is a natural way to describe them because you only need 1 octal digit to exactly represent any sequence of 3 binary digits. (This is similar to why hexadecimal is used in programming -- since 1 hex digit can represent 4 binary digits, you only need 2 hex digits to describe 1 byte. It boils down to the fact that 8 and 16 are powers of 2, so converting between octal and binary or hexadecimal and binary is really easy.)
These chunks are user (aka owner), group and others. Each chunk has three permissions to describe: read, write, and execute.
Hence the full set of permissions looks something like rwxrwxrwx, where each is a binary digit. So, for example, 110100100 in binary becomes 644 in octal, and you know that the first octal digit is for the owner's permissions, the second for the group's permissions, and the third for everyone else.
There are three different classes specified by permissions on an object: Owner, group, and everyone else. Each of these classes has three independent permissions that can be set: read, write, and execute. This means each class has one of eight permission sets:
- No permissions
Since an octal digit takes one of eight different values (the numbers 0 through 7), you can represent any combination of read/write/execute with a single octal digit.
Internally, the computer stores permissions as a bit field. So, for example, if you set permissions to 644, the computer might represent this as the binary number 110100100, or:
110 | 100 | 100 rw- | r-- | r-- 6 | 4 | 4 Owner | Group | World
(Notice that binary 110 is equal to octal 6, and binary 100 is equal to octal 4).