The short answer
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
What each one does
| 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.
Why not use storage for everything?
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.
Why not use RAM for everything?
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.
The memory hierarchy
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.
How they work together
When you open a program:
- The operating system finds the program's file on storage.
- It loads the needed parts into RAM. See what happens when you run a program.
- The CPU runs it from RAM, pulling the hottest pieces into its caches.
- When you save, your changes are written back to storage.
The operating system blurs the line in both directions:
- Virtual memory lets programs use more memory than is physically installed, by moving idle pages to storage. See how virtual memory works.
- The page cache uses spare RAM to hold recently read files, so reading them again is nearly instant. This is why "free" RAM is not wasted when the system uses it for caching, and why a second launch of an application is faster than the first.
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.
Which one do you need more of?
| 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.
Is the line blurring?
Somewhat.
- NVMe SSDs are fast enough that swapping hurts far less than it did on hard disks.
- Persistent memory products, which keep their contents without power while sitting close to RAM in speed, have been built. Intel's Optane was the best-known, and it was discontinued, largely for commercial reasons.
- In-memory databases such as Redis keep all their data in RAM for speed, and still write to storage so that a restart does not lose it. See why Redis is so fast.
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.
Frequently asked questions
What is the difference between RAM and storage?
RAM is fast, temporary working memory that is cleared when the power goes off. Storage is slower, permanent space for files and programs.
Is memory the same as storage?
In strict usage, no. "Memory" means RAM. In everyday speech, especially about phones, "memory" is often used to mean storage, which causes confusion.
Can more storage make my computer faster?
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.
What happens when RAM runs out?
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.
Conclusion
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.
Related articles
- How Virtual Memory Tricks Every Program Into Thinking It Owns the RAM
- Why SSDs Are Faster Than HDDs, Explained From the Hardware Up
- How the CPU Cache Makes Code Fast (and How to Write Cache-Friendly Code)
- Why Your Computer Slows Down When RAM Fills Up
