The best way to shut down your Mac is to choose Shut Down from the Apple () menu.
Just as your Mac follows a startup process after it turns on, it follows a shutdown process before it turns off. That process includes automatically quitting all open apps and logging out of your macOS user account.
If you can't shut down your Mac because it isn't responding, you can force it to turn off without shutting down. Hold down the power button until your Mac turns off.
Use this method only when you can't shut down. You'll lose any unsaved changes to documents that you have open.