Sooner or later every developer stares at a line of ls -l output, sees something like rwxr-xr--, and has to answer a practical question: what number do I type into chmod to get exactly this? The string and the number are two spellings of the same permissions, and converting between them is simple arithmetic once you know the pattern. Guessing is how files end up world-writable by accident.
This guide teaches the conversion properly: how the nine characters group into three classes, what each letter is worth, and how to turn any rwx string into its octal mode by hand. It then shows how to check your answer with the free Chmod Calculator on Ovatly, which converts in both directions.
Contents
- Quick answer
- The three classes and the three letters
- The arithmetic: read is 4, write is 2, execute is 1
- How to convert with the calculator, step by step
- Worked example: two conversions by hand
- The modes you will meet most often
- Limitations
- Common mistakes
- FAQs
- Conclusion
Quick answer
Split the nine characters into three groups of three: owner, group, others. In each group, add the values of the letters present: r is 4, w is 2, x is 1, and a hyphen counts as 0. The three sums, written in order, are the octal mode. So rw-r--r-- gives 6, then 4, then 4: mode 644. To check yourself, tick the same boxes in the Chmod Calculator and read the octal value it shows, or type a mode into its lower field and press Apply octal to see the boxes it represents.
The three classes and the three letters
A symbolic permission string has nine characters, and they always come in the same order. The first three describe the file's owner, the next three describe the group, and the last three describe everyone else, usually called others. Within each group, the positions are fixed too: read first, write second, execute third.
Each position holds either its letter or a hyphen. The letter means the permission is granted; the hyphen means it is not. So r-x in a group means that class can read and execute but not write, and --- means that class can do nothing at all.
One warning about reading ls -l output: the listing shows ten characters, not nine. The first character is the file type, a d for a directory, a hyphen for a regular file, or an l for a link. Skip it; the nine after it are the permissions this guide is about.
The arithmetic: read is 4, write is 2, execute is 1
Each letter carries a fixed value: read is worth 4, write is worth 2, and execute is worth 1. A class's digit is simply the sum of the values of the letters it has. Because the values combine uniquely, every digit from 0 to 7 corresponds to exactly one combination:
- 0 means no permissions, shown as
--- - 1 means execute only,
x - 2 means write only,
w - 3 means write and execute,
wx - 4 means read only,
r - 5 means read and execute,
r-x - 6 means read and write,
rw- - 7 means all three,
rwx
That table is the whole system. Converting a string means three small additions, one per class, written in the order owner, group, others. Converting back means splitting each digit into its combination from the same table.
How to convert with the calculator, step by step
- Open the Chmod Calculator.
- Tick the read, write and execute boxes for owner, group and others so they match the string you are converting.
- Read the three outputs: the octal value, the symbolic form, and the ready-to-use chmod command built from them.
- To go the other way, type an octal mode into the lower field and press Apply octal; the boxes load to show exactly which permissions that mode represents.
The calculator covers the standard three-digit modes. An optional fourth digit, covering setuid, setgid and the sticky bit, can be typed and is understood, but the checkboxes show the last three digits.
Worked example: two conversions by hand
First conversion: rw-r--r--, the standard web file setup. Split it into classes: owner rw-, group r--, others r--. Owner has read and write, 4 + 2 = 6. Group has read only, 4. Others have read only, 4. Written in order, the mode is 644: the owner can edit the file, everyone else can only read it.
Second conversion: rwxr-x---, a typical shared script or directory setup. Owner rwx is 4 + 2 + 1 = 7. Group r-x is 4 + 1 = 5. Others --- is 0. The mode is 750: the owner has full access, the group can read and enter or run, and everyone else is locked out entirely.
Now check both in the tool. Ticking owner read and write, group read, others read produces 644 and the symbolic string rw-r--r--. Typing 750 into the octal field and pressing Apply octal loads owner all three, group read and execute, others nothing, which is rwxr-x---. Hand arithmetic and the tool agree both ways: the calculator becomes a check, not a crutch.
The modes you will meet most often
A handful of modes cover most everyday work. 644 is the standard web file mode. 755 pairs with it for directories, owner full access and everyone else read and execute, because a directory needs the execute bit to be entered at all; the classic executable script setup is the same 755. 600 is the private file mode, owner read and write and nothing for anyone else, the usual choice for keys and private data.
And one mode to avoid: 777 grants read, write and execute to every user on the system, so anyone can modify the file. If an error message seems to suggest 777 as a fix, treat it as a last resort to tighten again immediately, not a setting to leave in place.
Limitations
The calculator only converts between representations. It cannot see your files, connect to a server, or change any permission; the command it shows is text for you to copy and run yourself, in a terminal you control. It also cannot tell you whether a mode is right for your situation. Choosing who should read or run a file is a judgement about your system and your users, and no converter can make it for you. The fourth-digit special bits are the other boundary: they can be typed into the octal field and are understood, but the checkbox grid shows only the last three digits, so verify special-bit modes by the digit, not by the boxes.
Common mistakes
- Counting the file type character. The leading
d, hyphen orlinls -loutput is not a permission. Start counting from the second character. - Reading the classes in the wrong order. The order is always owner, group, others. A digit computed for the group but typed in the owner position grants the wrong people access.
- Giving directories the file mode. A directory at 644 cannot be entered, because entering needs execute. Directories normally sit one step higher than their files.
- Reaching for 777 to end an error. It works by removing all protection. Find the class that actually needs access and grant only that.
- Assuming execute means the same thing everywhere. On a file it means run it; on a directory it means enter it. The digit is the same, the effect is not.
FAQs
How is each octal digit calculated? Each class adds up its permissions: read is 4, write is 2, execute is 1. Owner read, write and execute is 7; group read and execute is 5; that is how a mode like 755 is built.
What mode should a private file have? 600, owner read and write with nobody else getting anything, is the usual choice for keys and private data. Avoid 777, which lets every user on the system modify the file.
What does the first letter in ls -l output mean? That extra leading character is the file type, not a permission: d for directory, a hyphen for a regular file, l for a link. The nine characters after it are the symbolic permissions.
Why do directories usually get 755 while files get 644? A directory needs the execute bit to be entered at all, so directory modes usually sit one step higher than file modes: 755 for directories pairs with 644 for the files inside them.
Can the calculator change permissions on my server? No. The calculator cannot see or change any real file; it only converts between the symbolic and octal representations and shows you the command to run yourself.
Conclusion
The conversion is three additions: split the string into owner, group and others, score each class with read 4, write 2, execute 1, and write the digits in order. Learn the sums once and strings like rwxr-x--- stop being codes to look up and become permissions you can read at sight. When you want a second pair of eyes, the Chmod Calculator checks the arithmetic in both directions without touching a single real file. Permissions decide who can reach your files; codes of a different kind decide who can reach your pages, and the companion guide on how to make a QR code for free covers that side. More tools and guides live in the Developer Tools archive.