Learn to Code
All tracks
Learn to Code

Free lessons from scratch to pro — every language, databases and DevOps.

AboutContactPrivacy PolicyTerms of Use

Your progress is saved in this browser. © 2026 Learn to Code

PB
Programming Basics
0/10 completed
Beginner
How computers workWhat is a program?Thinking in algorithmsData, variables and types
Intermediate
Decisions and loopsBreaking problems into functionsErrors and debugging
Advanced
Reading documentation and learning on your ownClean code basics
Pro
Thinking like a software engineer
Tracks / Programming Basics / Beginner

How computers work

Before writing code, it helps to know what a computer actually is. The good news: every computer, from a smartwatch to a data centre, works on the same few ideas.

The four jobs of a computer

Every computer does four things, over and over, billions of times a second:

Job Part Example
Input Keyboard, mouse, touchscreen, microphone, network You tap "Send"
Processing CPU (Central Processing Unit) Work out what "Send" means
Storage RAM (short-term) and disk/SSD (long-term) Keep the message
Output Screen, speakers, network Show "Delivered ✓"

The main parts

          ┌──────────────────────────────────────────┐
 Input ──▶│  CPU  ◀──────▶  RAM (memory)              │──▶ Output
          │   ▲               fast, temporary          │
          │   └──────────▶  Storage (SSD / disk)       │
          │                   slower, permanent        │
          └──────────────────────────────────────────┘
  • CPU: the "brain". It follows instructions one after another, very fast (billions per second, measured in GHz). Modern CPUs have several cores, so they can do several things at once.
  • RAM: the CPU's desk. It's very fast, but it's emptied when the power goes off. Programs and the data they're working on live here while they run.
  • Storage (SSD/HDD): the filing cabinet. It's slower, but it keeps files when the power is off.
  • GPU: a processor with thousands of small cores. It's great at graphics and at AI maths.

Why this matters to programmers: reading from RAM is about 100× faster than reading from an SSD, and an SSD is about 1000× faster than the network. Much of performance work comes down to keeping data close to the CPU.

Everything is numbers: binary

Computers are built from billions of tiny switches called transistors, which are either on (1) or off (0). One switch is a bit, and 8 bits make a byte.

With bits you can represent anything:

JavaScript · editable

Text is numbers too. Every character has a code (ASCII and Unicode):

JavaScript · editable

Images are grids of pixels, each made of red, green and blue numbers. Music is a long list of sound-wave samples. It's all numbers.

Unit Size Holds roughly
1 byte 8 bits One letter
1 KB 1,000 bytes A short email
1 MB 1,000 KB A photo, or a book
1 GB 1,000 MB A movie
1 TB 1,000 GB A laptop's whole drive

The operating system

You never talk to the hardware directly. The operating system (Windows, macOS, Linux, Android, iOS) sits in between:

  • It shares the CPU between many programs (so you can play music while browsing)
  • It manages memory, so programs can't read each other's data
  • It handles files, networking, the screen and devices
  • It gives programs a standard way to ask for things (system calls)
Your program  →  Operating system  →  Hardware

From your code to the CPU

The CPU only understands machine code: very simple numeric instructions like "add these two numbers" or "jump to step 40". Humans write in programming languages, and a tool translates:

Approach How Languages
Compiled Translated to machine code before running C, C++, Rust, Go
Interpreted / JIT Translated while running Python, JavaScript, Ruby
Bytecode + VM Compiled to an intermediate code run by a virtual machine Java, C#, Kotlin

You'll explore this more in the next lesson.

Practice

  1. Change the binary example to print the numbers 0–16. What pattern do you see in the last digit?
  2. Find the code numbers for the letters of your name.
JavaScript · editable
✎ Check your understanding

1.Which part stores data permanently, even when the power is off?

2.How many bits are in a byte?