Your computer's sleep settings can be modified from two different locations in your power management options in Windows and from your System Preferences on a Mac, but also by certain software. If your computer goes to sleep even after you modify your settings, you will need to check the settings for the software installed on your computer. You may also need to update your drivers and BIOS if there are any conflicts with installed devices.
Modify Power Settings
Windows' basic power settings let you choose when to put both your display and your computer to sleep by modifying the power plan you are currently using. Open the Control Panel, click "System and Security," then click "Power Options." Click "Change plan settings" on whatever plan is currently selected, then change the setting from "Put the computer to sleep" to "Never." On a Mac, open your System Preferences, then click "Energy Saver." Click either the "Battery" or "Power Adapter" tab, then drag the "Computer sleep" slider to "Never." You may also want to deselect the "Put the hard disk(s) to sleep when possible."
Modify Advanced Settings
If modifying your power plan doesn't prevent your computer from going to sleep, there may be another option in the advanced settings that is taking precedence over your basic settings. Navigate back to the basic settings for your plan and click "Change advanced power settings" below the drop-down menus. Open the menu trees for the different categories and make sure none of them are telling your computer to sleep. Specifically, check the "Sleep" menu tree and make sure the options within match your preferences.
Modify/Disable Other Power Software
Other software, especially power management software, may be overriding your power management settings and putting your computer to sleep even if you don't have it set that way. If your problem started recently, look at the settings for any programs you recently installed, even those that may not appear to have anything to do with power settings. Specifically look for anything that deals with power, display or other system settings and disable any options that might be interfering.
Update Drivers and BIOS
Outdated drivers and BIOS can sometimes interfere with your computer's settings, especially if you have recently installed new hardware. Update the drivers for your computer's devices and check for any available updates for your BIOS. To find your BIOS version, open the Start menu or navigate to the Windows tile screen and type "msinfo32." Open the System Information page that appears and look for "BIOS Version/Date." Check your motherboard's manufacturer's website and look for your specific model to see if there are any updates available. If so, download the update and any available documentation to update your BIOS.