Why Go Rewrites 0644 as 0o644 (and Why chmod Won't Take 'rwx')
I typed 0644, saved, and my editor changed it to 0o644. That lowercase o fixes a kind of bug that is fifty years old, and it also explains why file permissions are numbers and not letters.
While I was adding file saving to my Go todo app, I wrote a very ordinary line.
os.WriteFile(filename, data, 0644)
I saved the file. My editor ran gofumpt, a stricter version of gofmt, Go's standard formatting tool, and the line changed without asking me.
os.WriteFile(filename, data, 0o644)
I didn't type that o. My first thought was that a plugin was damaging my file.
It wasn't. The formatter changed the number on purpose. The reason goes back to a design mistake from about fifty years ago, which Go has now fixed.
The number that looks like ten
In the early 1970s, C made a rule that almost every language since has copied. A whole number written with a zero in front is octal, which means base 8. The zero isn't decoration. It changes the base.
var a = 010 // Reads like ten. Compiles as eight.
That's the whole trap. In base 8, 010 means one eight and no ones, which is eight. Your eye is trained to skip a leading zero, because everywhere else a leading zero is only padding: in postcodes, in invoice numbers, or in the number 07 on a football shirt.
This has caused real bugs for decades. Someone lines up a column of numbers by adding zeros in front, and some of them silently become base 8. JavaScript's strict mode finally made the old form an error.
C only chose this syntax because octal was the natural way to write numbers on the PDP-8 and PDP-11, the computers Unix was first written for. On that hardware, bits were grouped in threes.

Go 1.13: the prefix family gets its missing member
A prefix at the start of a number can say which base it's in. Go has three of them today.
| Prefix | Base | Example |
|---|---|---|
0b | binary | 0b1010 |
0x | hexadecimal | 0xFF |
0o | octal | 0o644 |
Go inherited 0x from C. Go 1.13, released in 2019, added 0b for binary and 0o for octal. With 0o, octal is written out clearly instead of being hinted at by a zero.
The old form with a leading zero still works, because fifty years of C habits don't disappear in one release. Plain gofmt leaves it alone. gofumpt, which many editor setups run instead, treats 0o644 as the correct spelling in any module that uses Go 1.13 or later, and rewrites the old form.
The compiler treats 0644 and 0o644 exactly the same. So the rewrite doesn't change your program. It changes what the next person reading the code needs to know. To read 0644 correctly, you have to remember a hidden rule from 1972. 0o644 tells you directly.
This is typical of Go. When I wrote about coming to Go from C++, I saw the same pattern again and again. Where C leaves a danger to style guides, Go changes the syntax so that the dangerous code can't be written. The declaration order, the required braces, and now the octal prefix all follow the same idea.
Fine, but why is a file permission octal at all?
Because a Unix permission is nine bits, and nine bits fit exactly into three octal digits.
Every file has permissions for three groups of people: the owner, the file's group, and everyone else. Each of the three gets three bits: read, write and execute. One octal digit holds exactly three bits, so each group gets one digit, with nothing left over.
Each permission always has the same value.
| Letter | Permission | Value |
|---|---|---|
r | read | 4 |
w | write | 2 |
x | execute | 1 |
Add up the values for one group, and you get that group's digit. Read and write is 4 + 2 = 6. Read and execute is 5. Read alone is 4. All three is 7.
So 0o644, the usual mode for ordinary files, means the owner can read and write, and everyone else can only read. 0o755, the usual mode for programs and directories, means the owner can do everything, and everyone else can read and run but not change.
In hexadecimal or decimal, the three groups don't line up with the digits. Octal is the only base where each digit is exactly one group. The permission system wasn't adapted to octal later. It was designed in octal, on those same PDP-11s.
Why can't I just write "+rwx"?
This was my next question, because in the terminal I never think in numbers.
chmod +x deploy.sh
chmod u+rw notes.txt
So why does Go make me do arithmetic, when chmod accepts readable letters?
Because the letters aren't the operating system's language. They are only how the chmod program talks to you.
chmod is a small program. When you give it u+rw, it does what you would do by hand. It reads the letters, looks up the file's current permissions, works out the new nine-bit number, and passes that number to the kernel. The letters never leave the chmod program. The system call underneath, which is how a program asks the kernel to do something, only accepts a number.
Go's os.WriteFile sits just above that same system call, so it asks for what the kernel asks for, which is a number. The type is an unsigned 32-bit integer with the permission bits in the lowest nine places, under its own name.
type FileMode uint32
There is no code anywhere on that path that reads letters. Go chose not to put a translator between you and the operating system.
It does give you one help in the other direction. FileMode has a String() method, so printing a mode shows the familiar letters from ls -l.
fmt.Println(os.FileMode(0o644)) // -rw-r--r--
fmt.Println(os.FileMode(0o755)) // -rwxr-xr-x
Numbers go in and letters come out. The letters are for people. The number is what the kernel uses.
The three you will actually use
Almost every time a Go program sets a permission, it's one of these three.
0o644 is for data files your program writes, such as configs, CSV files and logs. The owner can change them, and everyone can read them.
0o600 is the same, but private. Use it for tokens, keys and anything secret. Only the owner can read or write.
0o755 is for directories and for anything that is meant to be run. A directory needs the execute bit, because that bit is what lets you open it.
For the todo app's save file, 0o644 is the correct choice.
Wrapping Up
When gofumpt changes 0644 into 0o644, your editor isn't misbehaving. The formatter is removing one of the oldest sources of bugs in programming, every time you save.
And the permission is a number because Go's function sits closer to the kernel than chmod does. There are three groups, three bits each, and one octal digit per group, the same as on the PDP-11.
If Go is new to you, Go 101 covers the language from the beginning. If you are coming from C++ like I did, the pointers, slices, and errors post covers the bigger differences.
Check yourself
3 questions · nothing is savedReferences & Primary Sources
Official specifications, standards, and documentation cited in this post.
- [1]
Defines prefix notation for binary (0b/0B), octal (0o/0O), and hexadecimal (0x/0X) literals introduced in Go 1.13.
SPECgo.dev - [2]
POSIX specification for file permission bitmasks, S_IRUSR, S_IWUSR, and octal mode representation.
STANDARDpubs.opengroup.org
- Written
- Jul 7, 2026
- Length
- 1,218 words · 6 min
- Built
- …
- Served by
- …
- Delivered
- …
- Over the wire
- …
- Go's share
- …
Software Jargon, Decoded: Every Term Developers Throw Around
Idempotent, race condition, tech debt, LGTM, yak shaving: the everyday words of software teams in one place, with what each one actually means and why it exists.
- 1C++ 101: The Language That Trusts You Completely
- 2Go 101: A Small Language for Big Systems
- 3The Two Jobs of the Asterisk: Pointers in Go and C++
- 4List* l or List *l? The Oldest Style War in Programming
- 5From C++ to Go: Demystifying Pointers, Slices, and Errors
- 6Why Go Rewrites 0644 as 0o644 (and Why chmod Won't Take 'rwx')
How an Operating System Schedules Work
You have more programs than CPU cores, yet everything seems to run at once. Here's how the scheduler does it.
Memory: The Stack, the Heap, and Pointers
Where your variables actually live, why the heap costs more than the stack, and what a pointer really is.
Projects built with what this post is about.


