You can follow steps 3 and 4 below for both Battery power and while your MacBook is charging.
Note: If you are on a MacBook, you will see two tabs here: Battery and Power Adapter. Click on the Apple logo from top-right → Click on System Preferences.Prevent Your Mac from Sleeping Using Energy Saver Prevent Mac From Sleeping Using Terminal App.Prevent Your Mac from Sleeping Using Energy Saver.So, let us dig right in and see how to stop your Mac from sleeping. All of these methods are straightforward. The first one is using the energy-saver feature, second is to use the terminal, and the third is using a third-party app. Does your Mac go to sleep when you are downloading a file or backing it up? Do you want to keep your Mac from sleeping? Okay, there are three easy ways to do so.