Mac OS Lock Screen
Instead of logging out it is also possible to lock your mac in case you need to leave. By default this is not password protected. This page will help you setup your lock screen.
Password Lock Screen
To enable the mac to ask for a password after locking your screen go to System Preferences -> Security & Privacy. Here you will find the option "Require Password" tick this box and select your preferred time interval.
There are multiple ways to lock your screen. By default you can use the following keyboard shortcuts ctrl + shift + eject or ctrl + shift + power. Note the eject and power are located in the upper right corner of your keyboard.
The other method is by using "Hot Corners", this is disabled by default.
To activate Hot Corners you need to go to System Preferences -> Desktop & Screen Saver -> Hot Corners..., then select a corner that you prefer and select Start Screen Saver. If this option is activated you can move your mouse to the corner you selected and it will lock your screen.