For Moodle to work you don't need to have 777 permission on directories, and 666 permission on files. For Moodle to work you need to have the set of permissions that let Moodle read and write files, and list and enter (traverse) directories.
And this is where the miriad of different setups make things complicated, and in the worst scenario you might need those 777 and 666 permissions (but if you are in this situation, either your hosting provider or you are doing something fundamentally wrong, in my humble opinion).
If Moodle is the only one dealing with directories and files in moodledata (i.e., you are not uploding, deleting or changing things in there yourself, via FTP, sftp, cPanel or whatever other access method you have to moodledata), then even the "super restrictive" permissions of 700 (for directories) and 600 (for files) will work. Because Moodle will be the owner of all the files and directories (as its creator) and will have enough access with those permissions.
On the other hand, if you are manipulating things in there yourself (or other systems that won't go through Moodle) you need to come up with a set of permissions that allow both parties (Moodle and you/the other system) to have enough access. And here's where you might need 770/660. if both parties belong to a common Unix group. If you are unlucky/didn't do things right, and they dont belong to a common Unix group, you'll need to use 777/666 as you only option. But notice that 777/666 should be your last option, when everything is setup in the worst possible case.
Saludos.
Iñaki