Unix file permissions decide who can read, write and run a file. The chmod command changes them, and the numbers it takes look cryptic until you see that each digit is just a sum of three values.
Three classes, three permissions
Every file has permissions for three classes: the owner, the group and everyone else (others). Each class can have read (r), write (w) and execute (x). ls -l shows them as nine characters, such as rwxr-xr-x.
For a directory, read lets you list its contents, write lets you create and delete entries, and execute lets you enter it.
How the octal digits work
Read is worth 4, write 2 and execute 1. Add the values you want for each class and write the three sums in a row: rwx is 7, r-x is 5, rw- is 6 and r-- is 4. So 755 means the owner has rwx while the group and others have r-x, and 644 means the owner can read and write while everyone else can only read.
Sensible defaults
Use 644 for regular files and 755 for directories and scripts. Use 600 for private files such as SSH keys, which OpenSSH refuses to use if others can read them, and 700 for private directories. Avoid 777: it lets any user modify the file.
You can also change one bit at a time with symbolic mode, for example chmod u+x script.sh to make a script executable for its owner.
Special bits
A fourth leading digit adds the special bits. Setuid (4) and setgid (2) run an executable with the privileges of its owner or group, and setgid on a directory makes new files inherit its group. The sticky bit (1) on a directory lets only a file's owner delete it, which is why /tmp is mode 1777.