Like others said you might have a old battery. But it might also just be a wrong setting.
You should be able to set at which battery level your systems shuts down/hibernates.
On windows, the level when the pc hibernates is 5%, so if you use windows and your battery goes to 0%, the setting was changed!
If you use Windows, it is in the control panel > Power Options > Change Plan Settings > Change Advanced Power Settings. The default "critical battery level" is 5%. If your battery is weak, increase it to 10% or even more to allow the pc to hibernate.
This obviously won't fix a broken battery, but if your battery still has enough power to allow your pc to safely hibernate, it might be enough for you!
19It is shutting down because it isn't plugged in – Ramhound – 2016-07-09T23:40:21.290
2Please edit your question to add exact details on what make and model of laptop this is. In general, if the laptop is running off of the battery and there is no backup power plugged in, it will shut down. – JakeGould – 2016-07-09T23:56:37.570
74I believe that the OP understands that the laptop cannot keep running past the point where it runs out of power / energy / capacity. The question is: Why does it do a hard shutdown, and not sleep, hibernate, or do some other sort of soft shutdown that saves state and allows the machine to be restarted / resumed when power is available again? – G-Man Says 'Reinstate Monica' – 2016-07-10T00:59:06.660
15@Ramhound: and "he lost the files because he didn't save them regularly"
:-D
. "the higher the truth the simpler it is" ;-) – Hastur – 2016-07-10T13:55:43.77010How old is the laptop? How old is the laptop battery? Batteries lose capacity over time with each discharge/recharge cycle. If it's over a few years old, you might want to consider replacing the battery. And enabling auto-save in your word programs (or using programs that have autosave as an option). – WernerCD – 2016-07-10T16:18:08.813
6I had this issue with my old laptop when I bought a cheaper, non-genuine replacement battery. It would just go black when it should have still about 5% battery left. I don't think it's impossible that your battery reports to the system that it stil has some juice left but then suddenly fails to provide the required voltage. – kamilk – 2016-07-10T23:31:18.560
2Likely your battery is near end of life. – Daniel R Hicks – 2016-07-11T12:21:39.433
3May be the battery needs to recalibrated. – SAMPro – 2016-07-11T18:38:55.773
@kamilk I've seen this happen with genuine batteries from well-known brands as well. – None – 2016-07-13T10:44:45.843
May be, laptop requires electric power to run program? – ً ً – 2016-07-13T12:03:27.863
3Learn to save. As a programmer who grew up before personal computers had hardware memory protection, I reflexively hit ctrl-s every five seconds. – pipe – 2016-07-14T03:53:09.390
2
@pipe You are not alone dude. :) Once upon a time a simple a pointer error was able to freeze your system in a blink (it was enough Turbo Pascal): since then my
– Hastur – 2016-07-14T10:32:18.670ctrl-
s involuntary reflex snaps after each sentence or modification even on a word processors.I've got the ctrl-s reflex too. Comes from using Windows 3.1 and 95 which would randomly crash all over the place. :-) Oddly, despite the lack of protections in DOS, it was never an issue. DOS app crashes were incredibly rare. Probably because they were so simple. – Brian Knoblauch – 2016-07-14T14:53:08.327
I've recently retrained my CTRL-S muscle memory now that I work so much with Excel. – Dan Henderson – 2016-07-14T19:10:10.750