Module 2 · Beginner · How computers work

CPU, GPU, RAM and storage explained

CPU, GPU, RAM and storage for beginners: cores and registers, GPUs and TPUs, why RAM empties at shutdown, SSD vs HDD, and what laptop to buy for coding.

By theprogrammers team · · 15 min read

A laptop advert says "Intel Core i5, 8 GB RAM, 512 GB SSD". Those three numbers decide most of how a computer feels to use: how fast it runs your code, how many apps it can keep open, and how many files it can hold. CPU, RAM and storage are the three parts every programmer should understand, because they also explain why some programs are slow and why others crash with "out of memory".

In short: the CPU does the work, RAM holds what's being worked on right now, and storage keeps everything else for later. Machine learning adds a fourth name you'll keep hearing: the GPU, and its cousin the TPU, which do huge amounts of maths in parallel. This lesson covers each one, how they work together, and what to look for when you buy a laptop for coding.

What you need first: what is a computer? Hardware and software.

Key terms

  • CPU (central processing unit): the chip that carries out program instructions. Also called the processor.
  • Core: one independent worker inside the CPU. A 6-core CPU can work on 6 things at once.
  • Clock speed (GHz): roughly how many steps per second a core takes. 3 GHz (gigahertz) is 3 billion steps a second.
  • RAM (random access memory): fast, temporary memory for running programs and their data. Its contents vanish when the power goes off.
  • Storage: where files are kept permanently, on an SSD or a hard disk (HDD).
  • Volatile: loses its data without power. RAM is volatile; storage isn't.
  • Register: a tiny storage slot inside the CPU that holds one value it's working on right now.
  • GPU (graphics processing unit): a chip with thousands of small cores that do many simple calculations at the same time.
  • TPU (tensor processing unit): a chip Google designed only for the maths inside neural networks.

The CPU: the part that does the work

Every program is a long list of tiny instructions: add these two numbers, compare these values, copy this data, jump to that instruction. The CPU fetches one instruction, works out what it means, carries it out, and moves to the next, billions of times a second. This is called the fetch-decode-execute cycle.

Three things describe how fast a CPU is:

FeatureMeansExample
Clock speedSteps per second for each core3.5 GHz = 3.5 billion steps per second
CoresHow many workers there are4, 8, 12 cores
GenerationHow new the design is; newer cores do more per stepAn Intel Core i5 of 2025 beats an i5 of 2015 at the same GHz

More cores help when the work can be split up: running several programs at once, compiling big projects, training machine learning models, or video editing. A simple Python script normally uses one core, so for it, a faster core matters more than many cores. (Python can use several cores, but you have to ask it to; the advanced Python lessons cover how.)

You can ask Python how many cores your computer has:

import os
print(os.cpu_count())

The answer depends on your machine, so we don't show one; a typical modern laptop shows between 8 and 16. That number counts "logical" cores: many CPUs run two threads on each physical core.

Registers: the CPU's own tiny memory

The CPU can't do maths directly on values in RAM. Every calculation happens in registers: a small set of storage slots built into each core, each holding one value. Before the CPU adds two numbers, it copies them from RAM into registers, adds them there, and copies the answer back.

Your one line of Python, total = price + gst, becomes several machine instructions. Written in a simplified, made-up assembly language, they look like this:

load   r1, [price]     ; copy price from RAM into register r1
load   r2, [gst]       ; copy gst from RAM into register r2
add    r3, r1, r2      ; r3 = r1 + r2, done inside the CPU
store  [total], r3     ; copy the answer from r3 back to RAM

A core has only a handful of registers. An Intel or AMD core (the x86-64 design) has 16 general-purpose registers; an ARM core, like those in phones and Apple's M-series chips, has 31. Some registers have special jobs:

RegisterHolds
Program counter (instruction pointer)The memory address of the next instruction to run
Stack pointerWhere the current function's local data sits in memory
Flags (status register)Results of the last comparison, such as "was it zero?" or "was it negative?", which if statements use
General-purposeNumbers and addresses the program is working on

The size of the registers is what "64-bit" in "64-bit processor" means: each general-purpose register holds 64 bits, so the biggest whole number one register can hold is 2⁶⁴ − 1. Python can show that number, and whether your Python itself is a 64-bit build:

import struct

print(2 ** 64 - 1)
print(struct.calcsize("P") * 8, "bit Python")
18446744073709551615
64 bit Python

struct.calcsize("P") is the size of a memory address in bytes. Almost every Python installed today is 64-bit. (Python's own int isn't limited to 64 bits; it joins several pieces together for bigger numbers, which is why 2 ** 100 still works.)

You'll never manage registers yourself in Python; the interpreter and the compiler do it. They matter because they're the reason the memory levels below exist: the CPU keeps the values it needs next as close to its registers as it can.

RAM: the working space

When you open a program or a file, it's copied from storage into RAM, because the CPU can read RAM about a thousand times faster than even a fast SSD. RAM is where your running code, its variables and the data it's working on live.

Two facts about RAM matter for programmers:

  1. It's volatile. When the power goes off, or a program closes, its data in RAM is gone. That's why unsaved work disappears in a power cut, and why programs save to files.
  2. It's limited. A laptop might have 8 or 16 GB. When programs need more than that, the computer starts using storage as overflow ("swap" or "page file"), which is much slower. Everything starts to lag.

You can see how much memory a Python list takes up:

import sys

small = list(range(1_000))
big = list(range(1_000_000))
print(sys.getsizeof(small) < sys.getsizeof(big))
print(round(sys.getsizeof(big) / 1_000_000, 1), "MB for the list itself")
True
8.0 MB for the list itself

A list of a million numbers takes about 8 MB, just for the list's slots, before counting the numbers it points to. A 10-crore-row dataset can easily need more RAM than a laptop has, which is exactly the problem data scientists run into.

Storage: keeping files for later

Storage holds the operating system, your apps, your photos, code and documents, even when the computer is switched off.

TypeHow it worksSpeedCost per GBWhere you find it
HDD (hard disk drive)Spinning magnetic platters and a moving armSlowCheapestOlder laptops, backup drives, big servers
SSD (solid state drive)Flash memory chips, no moving partsFastHigherAlmost every new laptop
NVMe SSDAn SSD connected directly to the fast PCIe busFastestHigherMost mid-range and better laptops

An SSD makes a computer feel far quicker than an HDD: it boots in seconds and opens programs almost instantly. For a laptop used for coding, an SSD is a must, not an extra.

Phones and many cheap laptops use eMMC or UFS storage, which are flash chips soldered to the board. They work like SSDs, but eMMC is noticeably slower.

How the three work together

Say you run a Python script that reads a CSV file of marks and prints the average:

  1. The script and the CSV file sit in storage.
  2. When you run it, the operating system loads Python and your script into RAM.
  3. Your code reads the CSV file from storage into a list in RAM.
  4. The CPU loops over the list and adds up the marks, using values from RAM.
  5. It prints the result. If you save it to a file, it goes back to storage.

Between the registers and RAM there's also a small, extremely fast memory inside the CPU, called the cache, which keeps copies of the data the CPU used most recently. From fastest and smallest to slowest and biggest:

LevelTypical sizeRough speed to reach
CPU registersA few hundred bytesInstant: under 1 nanosecond
CPU cacheA few MB to tens of MBA few nanoseconds
RAM8 to 64 GBAbout 100 nanoseconds
NVMe SSD256 GB to 2 TBAbout 100,000 nanoseconds (0.1 milliseconds)
HDD1 to 20 TBAbout 10,000,000 nanoseconds (10 milliseconds)

A nanosecond is a billionth of a second. The numbers are rough, but the pattern is what matters: each step down is many times slower. Good programs keep the data they use most in faster places.

GPU and TPU: processors for parallel work

A CPU has a few powerful cores, each able to run any kind of program, full of decisions and jumps. Some jobs don't need that. Making an image brighter means doing the same small sum on every one of its millions of pixels, and none of those sums depends on another. For work like this, many simple workers beat a few clever ones.

In kitchen terms: the CPU is a few expert cooks who can make any dish. A GPU is hundreds of helpers who each do one simple task, like chopping onions, all at the same moment. A TPU is a machine built to do nothing but chop onions, extremely fast.

CPUGPUTPU
CoresA few powerful ones (4 to 24 in laptops)Thousands of small ones (a GeForce RTX 4060 has 3,072)Large blocks built only for matrix maths
Good atAny task, especially ones with lots of decisionsThe same calculation on lots of data at onceThe matrix maths inside neural networks
Used forRunning the OS, apps, your Python scripts, web serversGames, video editing, training and running AI modelsTraining and running large AI models
Where you find itEvery computer and phoneBuilt into most laptops; separate cards in gaming PCs and serversOnly in Google's data centres, rented through Google Cloud or Colab

Why machine learning runs on GPUs

Neural networks are mostly matrix multiplication: huge grids of numbers multiplied together. Multiplying two 1,000 × 1,000 matrices needs a billion multiplications:

n = 1000
print(f"{n ** 3:,} multiplications")
1,000,000,000 multiplications

Most of those multiplications can be done at the same time, which is exactly what a GPU's thousands of cores are for. Training a model that takes days on a CPU can take hours on a GPU. NVIDIA GPUs are the most used for machine learning, because libraries like PyTorch and TensorFlow are built on NVIDIA's CUDA software.

GPUs come in two kinds:

  • Integrated GPU: part of the CPU chip, sharing the computer's RAM. Fine for the screen, video and light work. Most laptops have only this.
  • Dedicated (discrete) GPU: a separate chip with its own fast memory, called VRAM (for example 8 GB). Needed for serious gaming and for training models on your own computer.

TPUs and NPUs

Google designed the TPU for its own AI work, and uses TPUs to train and run large models. You can't buy one for your laptop, but you can rent them on Google Cloud, and Google Colab lets you pick a TPU runtime.

New phones and laptops also include an NPU (neural processing unit), a small, power-saving AI chip. It handles on-device AI tasks such as blurring your background in a video call or improving photos, without draining the battery. Apple calls its version the Neural Engine.

Units: KB, MB, GB, TB

Storage and memory are measured in bytes. One byte holds one English letter or a small number from 0 to 255.

UnitAboutHolds roughly
1 KB (kilobyte)1,000 bytesHalf a page of plain text
1 MB (megabyte)1,000 KBA short book in plain text, or a small photo
1 GB (gigabyte)1,000 MBAbout 300 phone photos, or a short HD movie
1 TB (terabyte)1,000 GBAbout 3 lakh photos

Windows counts in powers of 1,024 instead of 1,000, which is why a "512 GB" SSD shows up as about 476 GB. Nothing is missing; it's two ways of counting. Bits, bytes and binary explains why.

advertised_bytes = 512 * 1000 ** 3
shown_by_windows = advertised_bytes / 1024 ** 3
print(round(shown_by_windows, 1))

photos = 128 * 1000 / 3      # 128 GB phone, photos about 3 MB each
print(int(photos), "photos")
476.8
42666 photos

What laptop do you need for coding?

For learning programming, web development and beginner data science, you don't need an expensive machine. Our recommendation:

PartMinimumComfortable
CPUA recent Intel Core i3 or AMD Ryzen 3Core i5 / Ryzen 5 or better, or an Apple M-series chip
RAM8 GB16 GB
Storage256 GB SSD512 GB SSD

RAM matters most for programmers. A browser with many tabs, VS Code, and a running app or database can use 6 to 8 GB together. If you're choosing between more RAM and a faster CPU on a budget, pick 16 GB of RAM. Avoid laptops with only an HDD or with eMMC storage.

You don't need a dedicated GPU to learn programming or beginner machine learning. When you get to training bigger models, free cloud notebooks like Google Colab and Kaggle give you GPU time (and Colab offers TPUs), so you don't have to buy one.

Practice

  1. Match each part with its kitchen job: CPU, RAM, storage. (Cupboard, cook, counter.)
Show the answer

CPU is the cook, RAM is the counter, storage is the cupboard. The cook works only with what's on the counter, and ingredients come from the cupboard.

  1. You're typing an essay and the power goes off before you save. Which part lost your work, and why didn't the other part keep it?
Show the answer

The essay was only in RAM, which is volatile and loses its contents without power. It hadn't been written to storage yet, which is what saving does.

  1. How many 4 MB songs fit on a 64 GB phone, roughly, using 1 GB = 1,000 MB? Check in Python.
Show the answer

64 × 1,000 ÷ 4 = 16,000 songs.

print(64 * 1000 // 4)
16000

In practice fewer fit, because the operating system and apps use some of the space.

  1. A Python script that adds up a list runs at the same speed on a 4-core and an 8-core laptop of the same generation. Why?
Show the answer

A normal Python script runs on one core. Extra cores help only when the work is split across several cores, or when several programs run at once.

  1. You have ₹10,000 extra in your laptop budget. Should it go on upgrading from 8 GB to 16 GB of RAM, or from a Core i5 to a Core i7, for learning web development?
Show the answer

The RAM. Web development means running a browser, an editor, a local server and often a database together, which easily uses more than 8 GB. A Core i5 is fast enough for this work.

  1. Which processor fits each job best: training an image-recognition model; running a Python script that reads a CSV file; blurring your background in a video call on a new laptop?
Show the answer

Training the model: a GPU (or a TPU in the cloud), because it's millions of independent maths operations. The CSV script: the CPU, which runs ordinary programs. The background blur: the NPU if the laptop has one, otherwise the GPU.

  1. What does "64-bit" mean in "64-bit processor", and where do the calculations actually happen?
Show the answer

Each general-purpose register holds 64 bits. Calculations happen in registers: the CPU copies values from RAM into registers, works on them there, and copies results back.

Key takeaways

  • The CPU carries out instructions; more cores help with parallel work, and faster cores help single programs.
  • All calculations happen in registers, a few tiny slots inside each core; "64-bit" means each register holds 64 bits.
  • GPUs have thousands of simple cores for doing the same maths on lots of data at once, which is why AI runs on them; TPUs are Google's chips built only for neural-network maths.
  • RAM is fast working memory that's emptied when power goes off; running out of it slows everything down.
  • Storage (SSD or HDD) keeps files permanently; SSDs are much faster than HDDs.
  • Each step from CPU cache to RAM to SSD to HDD is many times slower.
  • For coding, prioritise 16 GB of RAM and an SSD over a faster CPU.

Frequently asked questions

Is 8 GB of RAM enough for programming?

It's enough to learn and for many small projects. With a browser, VS Code and a local server or database running at once, it gets tight, so 16 GB is more comfortable for web development and data science.

What is the difference between RAM and ROM?

RAM is fast, temporary memory for running programs, emptied when power goes off. ROM (read-only memory) holds data that's rarely changed, such as firmware. Phone adverts that say "128 GB ROM" really mean storage, which is a loose but common use of the word.

Do I need a GPU to learn machine learning?

No. Learning and small models run fine on a CPU. For bigger models, use the free GPUs in Google Colab or Kaggle before spending money on a graphics card.

Why does my computer get slower when many apps are open?

Each open app uses RAM. When RAM fills up, the operating system moves some of it to storage to make room, and reading it back is far slower than reading RAM. Closing unused apps or browser tabs frees RAM.

What to learn next

  1. See how all data becomes 0s and 1s in bits, bytes and binary numbers.
  2. Learn what manages the CPU and RAM in what is an operating system?
  3. Revise the big picture in what is a computer?