How do you convert binary to octal?
Break the binary number into groups of three bits, counting from the right, and replace each group with its value from 0 to 7. Octal is base 8, and 8 is 2 cubed, so three bits always make exactly one octal digit. 111101101 splits as 111 101 101 and becomes 755.
There's no multiplying or long division involved. You only need to know the eight 3-bit patterns, and the table below covers all of them.
Using this converter
- Enter the binary value, for example
110100100. - Click Convert.
- Read off the octal result, here
644.
Input with leading zeros (000111) is accepted and gives 7. Whitespace before or after the number is trimmed, but spaces between groups are not allowed, so type 111101101 rather than 111 101 101.
The eight 3-bit patterns, read as permissions
Octal's best-known job is Unix file permissions, where each bit in a group switches one permission on. The bits are worth 4 (read), 2 (write) and 1 (execute), as defined for the numeric mode of chmod in POSIX:
| Bits | Octal | Permission | Meaning |
|---|---|---|---|
| 000 | 0 | --- |
no access |
| 001 | 1 | --x |
execute only |
| 010 | 2 | -w- |
write only |
| 011 | 3 | -wx |
write and execute |
| 100 | 4 | r-- |
read only |
| 101 | 5 | r-x |
read and execute |
| 110 | 6 | rw- |
read and write |
| 111 | 7 | rwx |
everything |
So when ls -l shows rwxr-xr-x, write it as bits (111 101 101) and the octal mode drops straight out: 755.
Worked examples
A web server file. rw-r--r-- is 110 100 100. Paste 110100100 into the tool and you get 644, the usual mode for HTML and image files.
A private directory. rwx------ is 111 000 000. The tool gives 700.
A shared project folder. rwxrwxr-x is 111 111 101, which converts to 775.
A bit count that isn't a multiple of three. 11101101 has eight bits. Group from the right: 11 101 101. Pad the short group to 011, which is 3, so the answer is 355. If you grouped from the left you'd get 111 011 01, a different and wrong number. The tool parses the whole value, so it never makes that mistake.
Turning the result into a chmod command
- Write out the permission string for owner, group and others.
- Replace each letter with 1 and each dash with 0.
- Paste the nine bits into the converter.
- Use the three-digit result:
chmod 644 index.html.
A fourth, leading octal digit sets the special bits (setuid 4, setgid 2, sticky 1). Twelve bits such as 111101101101 convert to 7555, which sets all three special bits on top of r-xr-xr-x, so check before you run something like that.
Limits and what it won't do
| Situation | What happens |
|---|---|
| More than 53 bits | "That number is too large to convert precisely." |
0b prefix, spaces, - or . |
"Enter a valid binary number..." |
| Empty box | Output clears, no error |
| Leading zeros in the input | Accepted and dropped from the output |
The tool works on whole unsigned numbers only. It doesn't produce a permission string from octal or interpret rwx letters directly, so do the letter-to-bit step yourself as shown above.
Related tools
- Decimal to octal helps when a script printed a file mode as a plain decimal number.
- Octal to hexadecimal converts modes into the hex you see in a raw
statdump. - Binary to hex uses 4-bit groups instead, the standard for bytes and memory.
- The Bash lessons cover changing file permissions with
chmodin both symbolic and numeric form.
Last updated