Since 8 = 2³, each octal digit stands for exactly three bits:
- 0 =
000, 1 =001, 2 =010, 3 =011 - 4 =
100, 5 =101, 6 =110, 7 =111
Binary → octal: split the bits into groups of 3, starting from the right. Pad the leftmost group with zeros on its left, then replace each group with its digit.
Octal → binary: replace each digit with exactly 3 bits, keeping its leading zeros. 2 must become 010; writing just 10 shifts every bit to its left into the wrong place.
The weights inside each group are 4, 2, 1. That's also why Unix permissions use octal: read = 4, write = 2, execute = 1. chmod 640 means 110 100 000: the owner can read and write, the group can read, everyone else gets nothing.
It's the same idea as binary hex conversion, with groups of 3 instead of 4.