When setgid permission is applied to a directory, files that were created in this directory belong to the group to which the directory belongs.
How to set the setgid permission
chmod g+s directory
How to unset the setgid permission
chmod g-s directory