So, I was just wondering about how volatile memory storage loses data when the power to them is cut off. But can we not solve that problem by using a battery in conjunction with a RAM and a ROM and when there's a power cut i.e. when the computer didn't receive a shutdown signal the battery kicks in and a controller transfers data from RAM to an EEPROM?

EEPROM - because I guess HDDs and SSDs consume more power. I mean if we could do this then we can maybe program it to explicitly store data in EEPROM, if not data then the OS(only a copy). That way we can also boot faster. There maybe very obvious reasons not to do this. But they are not clear to me. So can you tell me why is this not done?

  • 9
    \$\begingroup\$ Why bother with transferring to EEPROM if the RAM is battery backed up. \$\endgroup\$
    – Andy aka
    Commented Oct 7, 2019 at 15:17
  • 9
    \$\begingroup\$ And the eeprom idea.... Well today a typical mid-end home PC has about 8GB of DRAM. EEPROM of 8GB? MAybe you meant flash after all? \$\endgroup\$
    – Eugene Sh.
    Commented Oct 7, 2019 at 15:26
  • 8
    \$\begingroup\$ They already do that, though not for main memory in a computer; the common term is "battery-backed SRAM". SRAM is too expensive by far to use as main memory, but battery-backed SRAM was used historically for things like BIOS settings (ever heard of "the CMOS battery"?), and it's how saving games worked on NES, SNES, Game Boy, and a few early Game Boy Advance video games. \$\endgroup\$
    – Hearth
    Commented Oct 7, 2019 at 15:29
  • 6
    \$\begingroup\$ en.wikipedia.org/wiki/Non-volatile_random-access_memory \$\endgroup\$
    – Paddy
    Commented Oct 7, 2019 at 15:37
  • 6
    \$\begingroup\$ In laptops the suspend mode powers (and refreshes) the DRAM only. Power requirements are relatively low, usually a week or more in suspend mode is possible before the laptop’s battery is empty and the RAM contents are lost. Some laptops/OSses have a feature where they wake up after a certain time, write the RAM contents to disk (hibernate) and shut down completely. \$\endgroup\$
    – Michael
    Commented Oct 8, 2019 at 7:35

7 Answers 7


Short answer: You might be able to "connect a battery to a RAM to prevent data loss during power outage", but this depends on the type of RAM.

SRAM (Static Random Access Memory) is not DRAM, explained below. SRAMs are found in many electronic devices such as a modern (home) thermostat (uses a battery to retain the settings if the power goes out) and in an alarm clock (battery keeps the time and can power unit for a short period), etc. Hard drives typically have some SRAM in them masquerading as "32MB of disk cache." Specialized SRAM is even present inside the CPU, as it's blazing-fast L1, L2, and L3 cache memory.

Lithium "coin cell" primary (non-rechargeable) batteries are commonly used for SRAM retention. Modern SRAMs can have lower working voltages, such as 1.8 V, requiring more circuitry to back with a 3.0 V battery. The supply current is very small (even nano-amps) so data can be retained for a long time from a small battery. Many industrial machines (robots, variable-frequency drives, programmable logic controllers, etc.) employ a SRAM backup battery to retain critical data through (frequent) power cycles.

The acronym SRAM means "Static Random Acccess Memory." Static, because its contents stay whatever state they were programmed, indefinitely, but only as long as power is applied. SRAM is very fast but bulky physically and is relatively expensive, so only finds niche roles even today. SRAM and DRAM are volatile types, meaning that their contents are lost if power is lost.

EEPROM (Electrically-Erasable Programmable Read-Only Memory) is an old, non-volatile digital storage medium, meaning data persists after power-off. These were originally "programmed" or "fused" at the bit-level, but modern ones are somewhat faster and can handle data in blocks. These are still much slower than SRAM or DRAM. Due to this extreme slowness, limited capacity, and a limited write/erase capability, they only find use in roles such as parameter storage and tiny programs for microcontrollers, etc. It is infeasible to backup main system memory to EEPROM due to the large amount of time involved.

FLASH memory, commonly seen as a USB Flash Drive and in SSD Hard Drives, is another non-volatile storage medium. It too is much slower than other types of RAM, and has a finite write limit, so is not used for main memory. A SSD hard drive is nothing more than a whole bunch of these, all used in parallel, to increase speed and capacity.

DRAM (Dynamic Random Access Memory) is a different beast altogether. "Dynamic" because it is always changing, and the contents will change (be lost) without intervention. DRAM is relatively dense (capacity-wise) and inexpensive, so is used for computer main system memory. Unfortunately it is also slower* than SRAM and needs to be "refreshed" continuously, else its contents are lost within a short time depending on temperature. Normal operation of the PC's memory controller keeps the data in DRAM refreshed continuously so that it is always available. If power is turned off, the memory controller still needs to refresh the data while running on backup battery power. Laptops, for example, do this when suspending to RAM. Because this refresh is an active process, it draws more current, and thus the battery is typically much larger than a coin cell. If the battery is depleted, then the DRAM contents are lost and the machine is forced to cold-boot.

A promising new technology is FeRAM. (Ferro-Electric RAM) is quite fast, non-volatile, and has a high endurance. It is new technology, so is quite expensive and capacity is limited, so has very limited roles.

*Aside: to get around the slowness of DRAM, a PC uses these massively in parallel. First, a whole stick is accessed at once (8x speed since there are 8 chips on it), then if the motherboard supports dual-banking, two modules at once (2x8 = 16x), triple-banking = 24x, etc. This is how a module marked "PC3-10666" can possibly perform like one chip running at 10,666MHz. From a 666MHz bus: 666*2 (DDR means two transfers per clock) * 8 chips/module = 10,666.

  • 3
    \$\begingroup\$ Thank you! This was a great help. \$\endgroup\$ Commented Oct 7, 2019 at 17:01
  • 9
    \$\begingroup\$ Before the flash SSD era, haven't there been storage devices that were essentially just boxes of battery-backed DRAM, with dedicated circuitry for refreshing it? \$\endgroup\$
    – user1686
    Commented Oct 8, 2019 at 4:56
  • 9
    \$\begingroup\$ @grawity There have been (cf. images-na.ssl-images-amazon.com/images/I/41CVgprtpsL.jpg). They were sold as literal "RAM Disks". Though I would not label them as "common", more a really specialized exotic piece of hardware – and in that domain virtually anything existed if you looked hard enough. \$\endgroup\$
    – Hermann
    Commented Oct 8, 2019 at 5:19
  • 9
    \$\begingroup\$ en.wikipedia.org/wiki/Memory_refresh says: "Although in some early systems the microprocessor controlled refresh, with a timer triggering a periodic interrupt that ran a subroutine that performed the refresh, this meant the microprocessor could not be paused, single-stepped, or put into energy-saving hibernation without stopping the refresh process and losing the data in memory. So in modern systems refresh is handled by circuits in the memory controller, or increasingly on the chip itself." \$\endgroup\$ Commented Oct 8, 2019 at 5:56
  • 5
    \$\begingroup\$ @ReversedEngineer: of course. I was commenting to rdtsc, who wrote: „To "refresh" DRAM properly, the CPU (traditionally) has been responsible. There is no dedicated chip just for refreshing it.” That's no longer the case in modern systems. \$\endgroup\$ Commented Oct 8, 2019 at 9:08

Can we not simply connect a battery to a RAM to prevent data loss during power cuts? So can you tell me why is this not done?

Of course we do! It's called battery-backed SRAM, and it's widely used in embedded systems. These days, the cost of NVRAM technology (such as conventional EEPROM, or new FRAM) is low, they can do the same thing without power, so it's not as common as before, but it's still here. And it's very likely that your desktop computer still has one inside to keep the BIOS settings.

Battery-Backed SRAM

Image source: ST M48T128Y datasheet

Applications include:

  • Date/Time. The coin cell on your computer motherboard powers the real-time clock chip, which has SRAM inside that keeps the time. It's the reason that your desktop computer remembers the time even if power is removed. Embedded systems still have dedicated RTC chips, but for post-2000s PCs, it's integrated into the motherboard chipset, a.k.a the southbridge, or Platform Controller Hub as Intel calls it.

  • Calibration Parameters. A piece of test equipment such as an oscilloscope can save the current calibration data inside SRAM (A common problem of old test equipment is losing all calibration data when the battery is dead).

  • Runtime Parameters. A microcontroller can save important runtime data in a battery-backed SRAM, so that the data never loses even if the microcontroller is reset due to a power outage or crashes. Similarly, a handheld scientific calculator can save your variables.

    • Many desktop computers still use this technique to retain some BIOS settings, along with the date/time. It is kept because people found that it is easy to remove the battery and reset everything if the BIOS setting is bad. Early PCs used real dedicated SRAM chips, modern PCs integrated the RTC/SRAM circuitry into the motherboard chipset.

Although modern UEFI firmware mostly uses NVRAM, but some still have a battery-backed SRAM in addition to NVRAM.

  • Cryptography and Security. A security hardware can save the private key inside a battery-backed SRAM, with a temper tamper-detection mechanism that erases and disconnects the SRAM if intrusion is detected, permanently destroys the private key. Similarly, in the extreme case, the program itself is saved in SRAM to frustrate any reverse-engineering efforts by competitors.

We don't do this on desktop computers. DRAM's power consumption is too high for a small battery. Also, most operating systems and software is not designed to continue working after a power loss anyway. You can implement something like hibernation, but if so, why don't you just use hibernation?

As the comments have pointed out, technically we do, if you use the Suspend feature on a laptop running on its battery, it's basically equivalent to "connecting a battery to the RAM."

  • 4
    \$\begingroup\$ @dave_thompson_085 A lot of people do get angry as well in the retro gaming / arcade community, some games are permanently lost when the battery of the encryption-key SRAM is dead ;-( \$\endgroup\$ Commented Oct 8, 2019 at 6:54
  • 6
    \$\begingroup\$ Well, it's largely available on laptops: it is exactly what "suspend to RAM" is, and I use it every day instead of deep hibernation, because it's faster to wake up. I'm probably not the only one, and I can tell you all major operating systems support it since many years. \$\endgroup\$
    – dim
    Commented Oct 8, 2019 at 9:55
  • \$\begingroup\$ "And it's very likely that your desktop computer still has one inside to keep the BIOS settings." Is this what the CMOS battery is? \$\endgroup\$
    – Cruncher
    Commented Oct 10, 2019 at 15:33
  • 1
    \$\begingroup\$ I recently paid good money to replace the memory board holding the configuration data for one of my radios (ICOM R-71A ) after the battery died. I could have simply replaced the battery, but there was no way to re-enter the configuration data (and no source of configuration data I could find to enter). It's impressive that the battery lasted 30 years, just wish I'd known I had to replace it before it was gone. \$\endgroup\$
    – TMN
    Commented Oct 10, 2019 at 16:13
  • \$\begingroup\$ @Cruncher Yes. Although the term "CMOS battery" is kind of a misnomer. CMOS is the name of the semiconductor technology used for manufacturing all kind of chips, calling the battery the "CMOS battery" is as meaningless as naming a computer program the "C program". I suppose that the name came from the fact that CMOS enabled the first generation of ultra-low power SRAM and RTC chips and made battery-backup solutions more practical, so people started to use the name of the technology to refer the SRAM/RTC chip that holds the BIOS settings and time. \$\endgroup\$ Commented Oct 10, 2019 at 16:49

For a PC, that's more or less what "hibernate on low battery" is. The contents of RAM are written to disk in the hibernation file. Since you need the whole system to be on while doing this, it needs quite a lot of power, and is therefore only suitable for systems which would have a battery anyway like laptops.

Similarly it's possible to boot quickly from hibernation; Intel call this "rapid start" and it's been available on some systems for a long time.

The main limiting factor is that RAM is so large that it takes many seconds to write it all to Flash.

  • \$\begingroup\$ In the case of a PC, it may happen that the O.S. does an "hybrid" aproach: write to disk, but keep in RAM as well. This way, it can boot super-quickly and is protected in case of a power failure, since it has all the hybernation data on the disk. This is faster than a cold boot and restores the contents and running programs, just like suspending to RAM would. \$\endgroup\$ Commented Oct 9, 2019 at 11:55

EEPROM - because I guess HDDs and SDDs consume more power.

SSDs are EEPROM by definition.

What you describe is exactly how "suspend to disk" or "hibernate" functions in modern computers do. You pull the plug, the battery or an external battery (UPS) starts to power the computer and when the battery depletes to a certain point, the OS (depending on settings) just writes the whole RAM to a file and shuts down. When you power the thing back on, the OS sees that the "hibernation" file exists and instead of booting normally, it reads the file to RAM and starts from where it stopped before (a lot of simplifications here, of course).

There is also a "suspend to RAM" function - turn off periferals, halt the CPU and power only the RAM and the RAM controller.

Both functions can be chained - you suspend to RAM first, and when the battery depletes some more, the computer wakes briefly in order to transfer the RAM content to the disk and power itself off completely.

  • 2
    \$\begingroup\$ "Both functions can be chained - you suspend to RAM first, and when the battery depletes some more, the computer wakes briefly in order to transfer the RAM content to the disk and power itself off completely." – It actually makes more sense to write the RAM contents to disk first, because then you don't have to do anything other than powering off when the battery depletes. This is called Hybrid Sleep in Windows, Safe Sleep in macOS ("Safe" because you can safely pull out the battery / lose power) and also exists in Linux. \$\endgroup\$ Commented Oct 9, 2019 at 7:01
  • 2
    \$\begingroup\$ @JörgWMittag I believe that that's not exactly what happens. Don't quote me on this, but I believe that some O.S. can turn off peripherals and most devices (like if it was suspending) and write everything to the disk before going into the lower-power states (aka: suspend). When you power on the PC, it can resume everything. In case of a power failure, everything is already in the disk and it just resumes. I strongly believe the copying is done before halting the CPU, but after turning off all peripherals (display, keyboard, mice, webcam, network cards, gpu, others). \$\endgroup\$ Commented Oct 9, 2019 at 12:00

To add to the other thorough answers, let me point out that simply having power available for the memory is insufficient to guarantee a proper restart where you left off. If you simply allow the power to drift out of specification for the processor it will typically "go nuts" at some point as the internal logic begins to fail and a GHz speed processor can create a lot of data corruption in the milliseconds it takes to drop to the point where it goes silent entirely (and even a single bit might be enough to cause it to crash).

For this reason you want supervisory circuits and usually som software that monitor the power rails and permit an orderly start-up and shut down that does not corrupt non-volatile or battery-backed SDRAM or RAM.


If your really looking to protect your a device from power loss then a UPS is the way to go. APC and numerous other brands have 1500va UPS that will allow most computers to run 10 minutes or so depending on the power consumption of the device.

The UPS is a battery, but its easy to implement and doesn't require any fiddle about to solder it on or etc.

If you are taking about a computer you can put it in sleep mode, the UPS will last a lot longer.

For the PC you can hibernate the computer, it writes the contents of RAM to the hard drive and reloads it when the computer it turn on again.


Since @rdtsc has provided an excellent answer let me share an experience which might be what you are thinking:

In a remote part of Canada a building used a heating/cooling system from a very reputed company. But grid power was unreliable. If power was lost it took over 2 hours for the system to reboot (power interruptions happen more than once per day in Winter). Imagine taking 2 hours when it is -50C cold (brrr). What I did was 'battery back' (UPS) the computer board. So, when power came back on, the system resumed immediately. I believe it is still in use...

  • \$\begingroup\$ I was unaware of UPS before I asked this question. This is why I thought that the RAM can be battery-backed so that when the power cuts happen, the data that is in the main memory can be kept on EEPROMs. The point I am trying to make is that I was thinking about data loss, but if UPS is used we don't need to worry about power cuts, they would power the machine. The use of battery-backed RAM would only preserve data but UPS would allow you to use the computer system so that you can perform emergency backups. \$\endgroup\$ Commented Oct 10, 2019 at 7:19
  • \$\begingroup\$ My approach to solving the problem of power cuts was narrow. \$\endgroup\$ Commented Oct 10, 2019 at 7:20
  • 1
    \$\begingroup\$ Most UPSs have a feature where it can communicate with your computer and shut it down automatically when power is low, etc... As additional info, before EEPROMS, stereos had memory chips which had a special pin for connecting a 9V battery. This allowed the MPU to 'remember' the tuning, etc when the power is off... \$\endgroup\$ Commented Oct 10, 2019 at 8:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.