DEV Community

Shankar L
Shankar L

Posted on

How Memory Works (RAM vs Storage)

Why should you care?

If you've ever bought a laptop or smartphone, you've probably seen specifications like:

  • 8 GB RAM
  • 512 GB SSD
  • 1 TB Storage

Many beginners assume RAM and storage are the same thing because both are measured in gigabytes.

They are not.

Understanding the difference between RAM and storage helps you:

  • Choose the right computer for your needs.
  • Understand why applications become slow.
  • Learn how operating systems manage programs.
  • Build a strong foundation for operating systems and computer architecture.

The Problem

Imagine you have a laptop with:

16 GB RAM
512 GB SSD
Enter fullscreen mode Exit fullscreen mode

A common question is:

"If my SSD is much larger, why can't the computer use it as RAM?"

Another question is:

"Why do applications close when the computer loses power, but my files remain?"

To answer these questions, we need to understand what RAM and storage actually do.


The Concept

A computer has two main places where data is kept.

RAM (Random Access Memory)

RAM is the computer's temporary working memory.

When you open an application:

  • The operating system loads it from storage into RAM.
  • The CPU executes instructions from RAM.
  • Data stays there only while the computer is running.

When power is turned off:

RAM → Everything is erased.
Enter fullscreen mode Exit fullscreen mode

Storage (SSD/HDD)

Storage is the computer's permanent memory.

It stores:

  • Operating system
  • Applications
  • Photos
  • Videos
  • Documents
  • Games

Unlike RAM, storage keeps data even when the computer is turned off.

SSD/HDD → Data remains.
Enter fullscreen mode Exit fullscreen mode

Simple Explanation

Think of your computer like a student studying for an exam.

The bookshelf contains all the books.

The study table is where the student actually works.

In this analogy:

Bookshelf = Storage

Study Table = RAM
Enter fullscreen mode Exit fullscreen mode

You don't study directly from the bookshelf.

You first bring the required books to the table.

Similarly:

Storage

↓

RAM

↓

CPU

↓

Output
Enter fullscreen mode Exit fullscreen mode

Programs must be loaded into RAM before the CPU can execute them.


Real-world Analogy

Imagine you're cooking dinner.

The refrigerator stores all your ingredients.

The kitchen counter is where you prepare the meal.

The chef works on the counter, not inside the refrigerator.

In this analogy:

  • Refrigerator = Storage
  • Kitchen Counter = RAM
  • Chef = CPU

When you're finished cooking, you can:

  • Put unused ingredients back into the refrigerator.
  • Clean the counter.

The counter becomes empty.

Likewise, RAM is cleared when the computer shuts down.


Code Example

Consider this simple Java program.

public class Main {
    public static void main(String[] args) {

        int number = 100;

        System.out.println(number);
    }
}
Enter fullscreen mode Exit fullscreen mode

What happens internally?

  1. The Java program is stored on the SSD.
  2. When you run it, the operating system loads it into RAM.
  3. The JVM starts executing the program from RAM.
  4. The CPU performs the calculations.
  5. The output appears on the screen.
  6. When the program closes, its memory is released.

The file remains on the SSD even after execution.


Common Mistakes

Mistake 1

Thinking RAM stores files permanently.

It doesn't.

Anything stored only in RAM disappears after power is lost.


Mistake 2

Believing more storage makes the computer faster.

A larger SSD gives you more space.

It does not necessarily improve performance.

Performance depends on factors such as:

  • CPU
  • RAM
  • SSD speed
  • Software optimization

Mistake 3

Thinking RAM and storage perform the same job.

They serve completely different purposes.

RAM

Temporary
Fast
Working Memory
Enter fullscreen mode Exit fullscreen mode
Storage

Permanent
Slower
File Storage
Enter fullscreen mode Exit fullscreen mode

Mistake 4

Closing an application does not delete it.

Closing an application removes it from RAM.

The application itself still exists on storage.


Advanced Notes

Why Is RAM Faster?

RAM is designed for extremely fast access.

Typical access times:

Device Approximate Access Time
CPU Cache Few nanoseconds
RAM Tens of nanoseconds
SSD Tens to hundreds of microseconds
HDD Several milliseconds

Because RAM is much faster than storage, the CPU can execute programs efficiently.


What Happens When RAM Is Full?

If RAM becomes full:

  • The operating system moves less frequently used data to storage.
  • This process is called paging or swapping.
  • Because storage is much slower than RAM, the computer becomes noticeably slower.

RAM Is Volatile

RAM is volatile memory.

This means:

Power Off

↓

Data Lost
Enter fullscreen mode Exit fullscreen mode

Storage is non-volatile, meaning it keeps data without electricity.


SSD vs HDD

SSD HDD
No moving parts Mechanical disks
Faster Slower
Silent Makes noise
More durable More fragile
Lower access time Higher access time

Most modern computers use SSDs because they significantly reduce application and boot times.


Summary

RAM and storage work together but serve different purposes.

Application Stored on SSD

↓

Operating System Loads It

↓

RAM

↓

CPU Executes Instructions

↓

Program Runs
Enter fullscreen mode Exit fullscreen mode

Remember these key differences:

RAM Storage
Temporary Permanent
Very Fast Slower
Stores running programs Stores files and applications
Data lost when power is off Data remains after shutdown

A good way to remember:

Storage remembers everything. RAM remembers only what the computer is using right now.


Top comments (0)