Chmod and umask Calculator
Converts a Linux file mode between octal digits, the ls -l string and a grid of read, write and execute boxes for owner, group and others, plus the setuid, setgid and sticky bits. Each octal digit adds read 4, write 2 and execute 1. New files usually start from 0666 and directories from 0777, and the umask switches bits off with a bitwise AND NOT rather than subtraction, so umask 022 gives 0644 and 0755.
Type a mode as octal digits, paste the string from ls -l, or tick the boxes, and the other two follow. The page then shows the listing, what each class can do, chmod and find commands, and what a umask does to new files and directories.
How a mode is built
A Unix file mode holds 12 bits, written as four octal digits. Each of the three right-hand digits covers one class of user, in the order owner, group and others, and adds 4 for read, 2 for write and 1 for execute. The leading digit carries the special bits: 4 for set-user-ID, 2 for set-group-ID and 1 for the sticky bit. That digit is usually 0 and usually left off, which is why chmod 755 and chmod 0755 name the same mode.
mode = 512 × special + 64 × owner + 8 × group + others, where each digit = 4 × r + 2 × w + x
Each digit holds exactly three bits, so the digits are base 8, and 0755 is octal for 493 in decimal: 7 × 64 + 5 × 8 + 5. POSIX chmod lists the same 12 values and sets an octal mode absolutely: every permission bit it does not name is cleared.
On a directory the letters mean something else. The GNU Coreutils manual describes read as listing the contents, write as creating and removing files, and execute as access to the files inside. Write is no use without execute: Linux's unlink(2) also needs search permission, so the breakdown offers create/delete only with x, and the Watch for line flags any class with r or w but no x.
Reading s, S, t and T
ls -l squeezes 12 bits into nine letters by doubling up the execute positions. POSIX ls prints s in the owner or group execute position when set-user-ID or set-group-ID is on together with execute, and S when the set-ID bit is on but execute is off. In the others position, t and T show the restricted deletion flag, better known as the sticky bit, with and without search permission for others. POSIX defines t and T only for directories, but GNU ls prints them for any file, and this page follows GNU.
A leading d or - gives the type, and GNU ls may add a . for a security context, or a + for another access method such as an ACL, after the mode. The field accepts all of these, or a whole pasted line, since the mode comes first among the ls -l fields, ahead of the link count, owner, group, size, date and time and name.
How the umask works
A program creating a file asks for a mode, and the umask removes bits from it. Linux's umask(2) page calls 0666 the usual request for a new file, and POSIX mkdir asks for 0777. The Seventh Edition manual of January 1979 defines the result as "the logical and of the given mode and the complement of the argument", and Linux still works that way:
new mode = requested mode AND NOT umask
It is a bit mask like a subnet mask, read the other way round: its 1 bits are switched off. Linux keeps only the nine permission bits of the mask and calls 022 the typical default, which turns 0666 into 0644. Subtracting the umask from 666, a common shortcut, is right only when the umask has no execute bits. With umask 0027, AND NOT gives files 0640, while 0666 − 0027 = 0637, shown as -rw--wxrwx, which hands others read, write and execute. The table adds that wrong result as File if subtracted when the umask has an execute bit. Directories start from 0777, where every bit is set, so subtraction never goes wrong for them.
The umask -S line uses the POSIX format u=,g=,o=, listing the bits the mask leaves clear; POSIX's own example is umask 002, shown as u=rwx,g=rwx,o=rx. The umask for this mode line runs the rule backwards. For a directory it is 0777 AND NOT the mode, setting aside a setgid bit, which new subdirectories inherit from a setgid parent. For a file several masks fit, because 0666 has no execute bits to clear, so the page picks the one that also lets directories be entered wherever files can be read: 0640 gives 0027, not 0026. No umask gives a file an execute or special bit, or a directory setuid or the sticky bit.
Worked example: a web root
The defaults describe the directory /var/www/html. Octal 0755 splits into special 0, owner 7 = 4 + 2 + 1, group 5 = 4 + 1 and others 5 = 4 + 1, so the listing is drwxr-xr-x. The owner can list, create/delete and enter; the group and others can list and enter. The numeric command is chmod 755 /var/www/html and the symbolic one is chmod u=rwx,g=rx,o=rx /var/www/html.
For the tree below it, find /var/www/html -type d -exec chmod 755 {} + sets every directory and find /var/www/html -type f -exec chmod 644 {} + every file. In binary, 0666 is 110 110 110 and NOT 0022 is 111 101 101, so new files get 110 100 100, which is 0644 or -rw-r--r--, and new directories get 0755. Umask 0022 has no execute bits, so no subtraction row appears. The umask -S line reads u=rwx,g=rx,o=rx, and the umask for this mode is 0022. The Watch for line warns that GNU chmod keeps a setgid bit the directory already has, and that 00755 or g-s clears it.
From six bits to twelve
The Third Edition manual's chmod page, dated 15 March 1972, lists six mode bits: read and write for the owner, read and write for everyone else, one executable bit and set user ID on execution. There is no group class. By the Sixth Edition's chmod page of 8 February 1975, the modes are today's: 4000 set user ID, 2000 set group ID, 1000 a "sticky bit for shared, pure-procedure programs", then read, write and execute for owner, group and others. That bit kept a shared program's text in swap space for its next run, which the manual calls worthwhile only for heavily used commands, and only the super-user could set it.
Set-user-ID was patented. Dennis Ritchie's US patent 4,135,240, "Protection of data file contents", was filed on 9 July 1973 and granted on 16 January 1979. It describes an extra access bit on executable files, the "set user identification bit (SUID bit)", which temporarily changes the user's identity to the file owner's while the program runs. Ritchie and Thompson's paper The UNIX Time-Sharing System, in the Bell System Technical Journal of 1978, gives files "a set of ten protection bits" and the classic use: a program guarding an accounting file no one else may read or change.
Berkeley's 4.3BSD added the sticky bit's modern job, listing sticky directories among its kernel changes since 4.2BSD. Its sticky(8) page of 26 May 1986 describes a directory where only a file's owner, the directory's owner or the super-user can remove or rename a file, and names /tmp as the use. Octal modes nearly went away later: ISO POSIX-2:1993 marked them obsolescent, and POSIX Issue 6 made them mandatory.
Directories, find and the GNU exceptions
Running chmod -R 755 on a tree makes every regular file executable. The two find commands split the tree instead: one changes only directories, the other only files, using the entered mode without its execute and special bits. The -exec ... {} + form packs many path names into each chmod run. POSIX's capital X comes close in one command, chmod -R u=rwX,go=rX /var/www/html, granting execute to directories and to files that already have one, where the find pair clears it.
GNU chmod treats directories specially. It leaves a directory's set-user-ID and set-group-ID bits alone when given 755, 0755 or u=rwx,go=rx, so that set-group-ID inheritance survives routine fixes. To clear them it needs a symbolic mention such as a-s, an operator mode such as =755, or a numeric mode of five or more digits such as 00755. GNU calls this its own extension; POSIX leaves set-ID requests on directories to each implementation.
The symbolic command writes the sticky bit as a separate +t clause, as in chmod u=rwx,g=rwx,o=rwx,+t /tmp for 1777. POSIX leaves t combined with u, g or o unspecified, so the page never writes o=rwxt.
Assumptions
The Applies to switch sets the listing's first letter and which commands appear; the page can't see the real file. Access control lists, file-system attributes and read-only mounts can still refuse what the mode bits allow, and on Linux a default ACL on the parent directory overrides the umask. The commands quote the path for a POSIX shell, and a path that starts with - must be written as ./-name. The octal field asks for three or four digits, so a half-typed 75 never flips the boxes.
Frequently asked questions
What does chmod 755 mean?
Each digit is a sum of read 4, write 2 and execute 1, for the owner, the group and everyone else in that order. 7 is 4 + 2 + 1, so the owner can read, write and execute; 5 is 4 + 1, so the group and others can read and execute. ls -l shows the mode as rwxr-xr-x. On a directory, execute means permission to enter it and reach the files inside.
What is the difference between 644 and 755?
644, shown as rw-r--r--, lets the owner read and write and everyone else only read, with no execute bit anywhere. 755, shown as rwxr-xr-x, adds execute for all three classes, which a program or script needs to run and a directory needs before anyone can enter it. Under the typical umask of 022, new files come out 644 and new directories 755.
How does umask decide the permissions of new files?
Programs usually request mode 0666 for a new file and 0777 for a new directory, and every bit set in the umask is switched off, so the result is the requested mode AND NOT the umask. Umask 022 gives files 0644 and directories 0755, umask 002 gives 0664 and 0775, and umask 077 gives 0600 and 0700.
Why is the umask not simply subtracted from 666?
Because the mask clears bits instead of subtracting a number, and the two only agree when the umask has no execute bits. With umask 027, new files come out 0640, but 0666 minus 0027 is 0637, which would give the group write and execute and give others read, write and execute. Directories start from 0777, where every bit is already set, so subtraction happens to give the right answer for them.
What do s, S, t and T mean in ls -l output?
A lowercase s in the owner or group execute position means the setuid or setgid bit is set together with execute, and a capital S means the set-ID bit is set without execute. In the others position, t is the sticky bit with execute for others and T is the sticky bit without it. On a shared directory such as /tmp, the sticky bit stops users deleting or renaming each other's files.
What does the setgid bit do on a directory?
Files created inside a setgid directory take the directory's group instead of the creator's own group, and new subdirectories inherit the setgid bit, so a shared folder stays with its project group. Mode 2775 combines it with group write. GNU chmod leaves an existing setgid bit on a directory alone when given 775; chmod 00775 or chmod g-s clears it.
Sources
- chmod: change the file modes, The Open Group and IEEE, POSIX.1-2024, 2024
- ls: list directory contents, The Open Group and IEEE, POSIX.1-2024, 2024
- umask: get or set the file mode creation mask, The Open Group and IEEE, POSIX.1-2024, 2024
- mkdir: make directories, The Open Group and IEEE, POSIX.1-2024, 2024
- find: find files, The Open Group and IEEE, POSIX.1-2024, 2024
- umask(2): set file mode creation mask, Linux man-pages project, 2026
- inode(7): file inode information, Linux man-pages project, 2026
- unlink(2): delete a name and possibly the file it refers to, Linux man-pages project, 2026
- Structure of File Mode Bits, GNU Coreutils manual
- Directories and the Set-User-ID and Set-Group-ID Bits, GNU Coreutils manual
- UNIX Programmer's Manual, Third Edition: chmod(II), Bell Telephone Laboratories, via the Unix History Repository, 1972
- UNIX Programmer's Manual, Sixth Edition: chmod(I), Bell Telephone Laboratories, via the Unix History Repository, 1975
- UNIX Programmer's Manual, Seventh Edition: umask(2), Bell Telephone Laboratories, via the Unix History Repository, 1979
- Protection of data file contents, US patent 4,135,240, Dennis M. Ritchie, Bell Telephone Laboratories, via Google Patents, 1979
- The UNIX Time-Sharing System, Bell System Technical Journal, hosted by Nokia Bell Labs, 1978
- sticky(8): persistent text and append-only directories, 4.3BSD, University of California, Berkeley, via the Unix History Repository, 1986
- Changes to the Kernel in 4.3BSD, Michael J. Karels, University of California, Berkeley, via the Unix History Repository, 1986