If your system turns on and boots into the operating system without an issue, then suddenly powers itself off with out any error screen. There are a number of reasons why it can do this. The most common and probably the easiest one to resolve is that your system is overheating. Dust, Lint, Animal hair, Cigarette smoke, Industrial debris are all things that commonly build up on the heat sink of a computer and clog it. This build up does not allow proper air flow to dissipate the heat causing the system to over heat and shut off. Most desktops will give a audible siren of alternating HIGH and LOW beeps.
If you have a laptop it is a fairly simple process to clean it out. Simply get a can of compressed air and blow the air into the heat exhaust of the laptop. MAKE SURE THE LAPTOP IS TURNED OFF FIRST!. you may want to do this out side as well a lot of dust and debris will come out of the fan intake vent.
If you have a desktop that is shutting down like explained earlier. First make sure that the computer is turned off and unplugged. Remove the side panel of the computer. Once the side panel is off inspect the heat sink and fan( It is the fan that is attached to metal fins). If there is a build up of dust or the fins appear to be clogged. Take some canned air and blow out all the dust and debris. You may want to do this outside or in a garage; it will makes a mess.