Programming
We provide developers and engineers the guides and tutorials they...
Search
We provide developers and engineers the guides and tutorials they...
Content is king. It's not just about how you're going to write, b...
Looking for an engaging connection with thousands of other people...
Why computers have both RAM and storage: speed versus persistence versus cost, the memory hierarchy, and what happens when either one runs short.
Quick answer: Computers have both because no single technology is fast, cheap, large and permanent at the same time. RAM (memory) is very fast but volatile: it loses everything when the power goes off, and it costs much more per gigabyte. Storage (an SSD or hard drive) keeps data without power and is cheap per gigabyte, but it is far slower to access. So the computer keeps everything on storage and copies whatever it is using right now into RAM. RAM is the desk you work on; storage is the filing cabinet. You need both, and making either one bigger does not replace the other.
Also Read: Why Is Naming Things So Hard in Programming? - How To's
| RAM | Storage (SSD / HDD) | |
|---|---|---|
| Holds | Running programs and the data they are using | Files, applications and the operating system |
| Keeps data without power | No | Yes |
| Typical size in a laptop | 8 to 32 GB | 256 GB to 2 TB |
| Speed of access | Around 100 nanoseconds | Tens of microseconds (SSD) to milliseconds (HDD) |
| Cost per gigabyte | High | Low |
| Used by | The CPU, directly | The CPU, through the operating system |
The confusion is understandable, because both are measured in gigabytes and phone makers often call storage "memory". They do different jobs.
Because it is too slow. A processor executes billions of instructions per second and constantly reads and writes data as it goes. The well-known list of latency numbers puts a main memory reference at about 100 nanoseconds. Reading from an SSD is measured in tens to hundreds of microseconds, and a hard disk seek takes several milliseconds.
Scaled to human terms, if a memory access took one second:
| Operation | Scaled time |
|---|---|
| Read from RAM | 1 second |
| Random read from an SSD | Several minutes to half an hour |
| Seek on a hard disk | Roughly a day |
A CPU that had to wait for storage on every step would spend nearly all its time idle. There is also the question of wear: flash cells in SSDs tolerate a limited number of writes, and a processor rewrites its working data constantly. See SSD vs HDD.
You can watch this happen. When RAM fills up, the operating system starts using storage as overflow, called swap or a page file, and the machine becomes dramatically slower. See why your computer slows down when RAM is full.
Two reasons.
It forgets. The common kind of RAM (DRAM) stores each bit as a tiny electrical charge in a capacitor. The charge leaks away in milliseconds, so the memory must be refreshed continuously. Cut the power and the contents are gone. Every document, photo and program would vanish each time you shut down, or the battery died.
It is expensive. Per gigabyte, RAM costs many times more than flash storage, which in turn costs more than hard disks. A terabyte of SSD is an ordinary purchase. A terabyte of RAM belongs in a large server.
RAM and storage are two levels of a longer ladder. Computer designers call it the memory hierarchy. Each step down is larger, cheaper and slower.
| Level | Typical size | Typical access time | Persistent |
|---|---|---|---|
| CPU registers | A few hundred bytes | Under a nanosecond | No |
| L1 / L2 / L3 cache | Kilobytes to tens of megabytes | About 1 to tens of nanoseconds | No |
| RAM | Gigabytes | About 100 nanoseconds | No |
| SSD | Hundreds of gigabytes to terabytes | Tens of microseconds and up | Yes |
| Hard disk | Terabytes | Milliseconds | Yes |
| Tape, cloud archive | Effectively unlimited | Seconds to hours | Yes |
Figures are orders of magnitude, and vary by hardware.
The trick that makes the ladder work is locality. Programs tend to reuse the same data and instructions repeatedly, and to use data near what they just used. So a small, fast layer holding the recently used items can serve most requests, with the big, slow layer behind it for the rest. That is exactly what a cache is. See how CPU caches work.
The result behaves almost like a memory that is as large as the bottom layer and nearly as fast as the top one, at a sensible price.
When you open a program:
The operating system blurs the line in both directions:
Saving a file is the moment data crosses from the volatile side to the permanent side. That is why unsaved work is lost in a crash, and why databases go to such lengths to write changes to storage safely before confirming them. See the write-ahead log.
| Symptom | Likely shortage |
|---|---|
| Slow when many tabs or applications are open; constant disk activity when switching | RAM |
| "Disk full" warnings; cannot install or save | Storage |
| Slow to boot and to open applications, on a machine with a hard disk | Storage speed: move to an SSD |
| Slow in one demanding program with resources to spare | Probably the CPU or GPU |
Adding RAM does not give you more room for files. Adding storage does not let you run more programs at once. And more RAM than your workload uses brings little benefit beyond a larger file cache.
Somewhat.
Even so, the basic trade remains. Until one technology is as fast as DRAM, as cheap as flash and permanent, computers will keep using layers.
RAM is fast, temporary working memory that is cleared when the power goes off. Storage is slower, permanent space for files and programs.
In strict usage, no. "Memory" means RAM. In everyday speech, especially about phones, "memory" is often used to mean storage, which causes confusion.
Not by itself. A faster kind of storage (an SSD in place of a hard disk) makes loading much quicker. More capacity only helps if the drive was nearly full.
The operating system moves less-used data to storage and brings it back when needed. This works, but it is much slower. If that space also runs out, programs are closed.
RAM and storage exist side by side because of a trade-off that physics and economics have not let anyone escape: fast memory is volatile and costly, and permanent memory is slow and cheap. Computers get the best of both by layering them, keeping everything on storage and the work in progress in RAM. Understanding that split explains most everyday performance problems, and which upgrade will fix them.