What a Program Is — How It Relates to CPU, Memory, and Storage

This article is part of the IT Foundations course, which builds up from scratch the practical IT knowledge you need at a minimum for programming and vibe coding.
A program is a sequence of instructions, and when you run it, it is loaded into memory and the CPU carries them out one at a time. Diagrams show why saving alone does not run it, starting from how the three parts divide the work.

This article covers what happens inside the computer when a program runs.

Saving a file and running it are separate events inside the computer.

The difference comes down to what each of the three parts — CPU, memory, and storage — is responsible for.

  • A program is a sequence of instructions, and running it moves through them one line at a time from the top
  • How CPU, memory, and storage divide the work, and what disappears when the power goes off
  • Why saving alone does not run it — the writing goes no further than storage
  • What "run this" in a set of steps hands to the runtime

A program is a series of instructions, and running it moves through them from the top

A program is the instructions you want the computer to carry out, arranged in the order they are carried out.

The human-readable text of it is the source code, and carrying it out one instruction at a time from the top is running it.

The three lines down the left of the diagram are the contents of app.js, and the CPU only ever receives one line at a time.

A line that only remembers a value puts nothing on screen.

When the third line finishes, the run itself ends, and the values remembered along the way do not remain.

If an instruction partway through cannot be carried out, the run ends there.

In the next three lines, the name gokei in the middle is not written anywhere.

console.log("Printing the total");
gokei();
console.log("Finished");

"It stopped with an error" means the run ended before reaching the last line.

The first line still appears on screen, the middle line produces the error text, and the last line ends without being read.

A program is a sequence of instructions carried out from the top

A program is what you want done, written out in order.

Running it means carrying out that sequence one item at a time from the top, and if a line partway through cannot be carried out, the lines after it end without being read.

What CPU, memory, and storage are each responsible for

The "computer" in the previous diagram is made of three parts with different roles.

The CPU (Central Processing Unit) carries out instructions one at a time, memory holds the contents only while something is running, and storage keeps things even when the power goes off.

How CPU, memory, and storage divide the work
CPUprocessorMemoryRAMStorageSSD / diskReads instructionsone at a timeHolds what runsand its valuesKeeps filesstoredNothing remainsClearedRemains"Out of memory"is about this"Low disk space"is about this
The left is the part, the middle is what it is responsible for, and the right is whether it remains when the power goes off. The rightmost column is the clue for reading warning messages.
One file splits into instructions and reaches the CPU one at a time
app.js instorageLine 1 instructionLine 2 instructionLine 3 instructionCPU runs themone at a timeMemory
The app.js in storage on the left is one file. Once it is loaded into memory it splits into the instructions inside it, and the CPU on the right receives them one at a time from the top.

One file in storage becomes a sequence of instructions inside memory, and the CPU receives only one of them at a time.

Values from partway through a calculation also sit in memory, and the file in storage is not rewritten while it runs.

The three parts are divided up inside one computer as follows.

The three parts inside your own computer
Your computer
Storage
  • The app.js file you saved
  • Remains as it is even when the power goes off
Memory
  • The contents of app.js that were loaded
  • Values remembered along the way, such as 150 and 200
  • All of it disappears when the power goes off
CPU
  • Receives only the one instruction it is carrying out now
  • It no longer holds the instructions that are finished
The outside is your own computer. Storage keeps the files you saved, and memory holds only what is running right now.

Only the contents move along; the app.js in storage itself stays where it is.

What goes into memory is only what is running right now and the values from partway through it.

This distinction also shows up in how you read the warnings a computer produces.

"Out of memory" is about memory, so deleting files usually does not increase it.

"Low disk space" is about storage, and deleting files does free that up.

Where things are kept and where they run are different

Storage is where files are kept, memory is where what is running right now is held, and the CPU is what carries out those instructions one at a time.

What you wrote to storage remains when the power goes off, and what was in memory disappears.

Why saving a file alone does not make it run

Saving means writing the characters of the source code to storage.

They are written into the folder of my-app, the booking app you are building.

Where in storage a file goes when you save it
Storage
my-app (the folder of the booking app you are building)
  • app.js — the source code you saved
  • Saving again changes the contents of this file
Other folders
  • Photo and document files
  • Files that are not running sit there as they are too
The outside is storage. my-app is the folder of the booking app you are building, and the app.js you saved goes inside it.

The CPU never goes and reads a file placed here on its own.

When you have only saved, not a single instruction has been carried out yet.

StepStorageMemoryScreen
Save onlyapp.js is writtenNothing goes inNothing appears
Save and runapp.js is unchangedLoaded and starts running350 appears

The save-only row stops at storage, and since nothing goes into memory, the CPU receives no instructions at all.

Nothing happens on screen because you have not told it to run.

When you run it again, the old contents of memory are discarded and the new file is loaded.

What you fixed runs at the moment that reload happens.

This is why a set of steps tells you to run it again.

Saving is not the same as taking effect

Saving goes no further than writing the characters to storage.

A running program keeps going with the contents as they were when it was loaded, so even if you fix the file, the result on screen does not change until you run it again.

"Run this" means handing a file to the runtime

The runtime — the software that reads source code and has the CPU carry out its instructions — is what loads the file into memory and delivers the instructions to the CPU.

"Run this" in a set of steps means handing the file to this runtime.

The only thing you type yourself is the one line on the far left.

That one line shows up in a set of steps in this form.

# Run JavaScript (Node.js) source code
node app.js

# Run Python source code
python app.py

This one line is a command — an instruction in text that tells software what to do.

The front is the name of the runtime and what follows is the file name of the source code, separated by a space.

What is inside a single command
A single command (node app.js)
The front — the name of the runtime
  • node — reads JavaScript source code
  • python — reads Python source code
What follows — the file you hand it
  • app.js — the file name of the source code you saved
  • The runtime loads this from storage
  • A short name decided in advance is sometimes written instead of the file name
The outside is the single command, and the two inside it are the front and what follows. The commands in a set of steps can be read by splitting them into these two.

The front tells you which runtime is needed, and what follows tells you which file gets loaded.

The screen where you type this line is covered in this course's article "What a Development Environment Is."

Even when the language changes, the reading stays the same: the front is the software that receives it, and what follows is what you hand to it.

There is one more place where the wording of the steps differs.

How things end after you tell it to run splits into two.

After you tell it to run, there are two ways it ends
Tell itto runRuns to the lastline and endsResult appears,back to the promptHas an instructionthat keeps waitingDoes not enduntil stopped
One instruction splits into an upper and a lower branch. The upper branch is a program that ends at the last line, and the lower branch is a program that does not end until you stop it.

The lower branch is the kind of program a set of steps tells you to leave running.

Some runtimes reload the file automatically every time you save.

Even then, the screen changes only after the new file has been loaded.

Telling it to run means handing over a file

"Run this" means hand the file to the software called the runtime.

You hand it over with one line such as node app.js, and some programs run to the last line and end while others do not end until you stop them.

QUIZ

Knowledge Check

Answer each question one by one.

Q1When you have only saved the source code, which part is that file kept in?

Q2What does a computer do when it "runs a program"?

Q3In the command node app.js, what does the node at the front refer to?