How Computers Work

How Software Gets Written and Run

How programmers turn source code into programs, what compiling and interpreting mean, and why software needs updates after it is released.

On this page
  1. What software is
  2. Source code
  3. Programming languages
  4. From source code to something that runs
  5. What happens when you start a program
  6. Why software has bugs
  7. Why programs need updates
  8. What changes between versions
  9. Putting it together

What software is

Software is a set of instructions that tells a computer what to do, whether it sits on a laptop, a phone or inside an internet of things gadget such as a smart bulb. The hardware can only carry out very simple operations, such as moving a number, adding two numbers or comparing them. A program is a long and carefully ordered list of those operations that together produce something useful, like a calculator, a game or a web browser.

People do not usually write those operations directly, because the processor expects them as patterns of ones and zeros that are hard for humans to read. Instead, programmers write in a form that is easier to think in and let other software translate it.

Source code

The text a programmer writes is called source code. It is quite different from the finished program that ordinary users download and open. It looks a little like very strict, precise English mixed with symbols. A tiny example in plain wording might be: “ask for a number, add one to it, show the result”. In a real language, that is a few short lines with exact spelling and punctuation. Computers are literal, so a missing symbol can stop the whole program.

Source code is just a text file. Programmers write it in editors that help with layout and spotting mistakes, and they usually keep a history of every change so they can undo errors and work together.

Programming languages

There are many programming languages, and they exist because different jobs suit different styles. Some are designed to be close to the machine and fast, which suits operating systems and games. Others aim for readability and quick development, which suits scripts, websites and data analysis. Some are made for particular settings, such as phone apps or database queries.

No language is simply the best. Choosing one usually depends on what is being built, what the team already knows, and where the program must run. The underlying ideas, such as variables, decisions, loops and functions, are shared across most of them, which is why programmers can often pick up a second language more easily than the first.

From source code to something that runs

The processor cannot run source code directly. There are two common routes from one to the other.

Compiling. A program called a compiler reads the whole source code and translates it into machine code, the instruction patterns the processor understands. The result is a file that can be run on its own, and the translation is done once, ahead of time. Compiled programs often start quickly and run fast, but the output is built for a particular type of processor and operating system.

Interpreting. An interpreter reads the source code and carries it out step by step while the program runs. It is convenient because you can change the code and run it again right away, and the same code can run wherever the interpreter is installed. The trade-off is that this can be slower, since translation happens as it goes.

Many real systems mix both approaches. Some languages compile into an intermediate form that a runtime then translates further as the program runs. Web pages, for example, include scripts that your browser runs for you. So the line between compiled and interpreted is not always sharp, but the basic idea holds: something must turn human-readable instructions into processor instructions.

What happens when you start a program

When you open an app, the operating system does the setup. It finds the program file on storage, loads the needed parts into memory, gives the program a share of the processor’s time, and lets it ask for services like opening files or drawing windows. Programs also rely on libraries, which are collections of ready-made code for common jobs such as handling images or networking, so developers do not have to write everything from scratch.

Once running, the program reacts to events: a click, a key press, data arriving from the network. Most of the time it is waiting for you.

Why software has bugs

A bug is a mistake in how a program behaves. Software is made of enormous numbers of small decisions, and people write it, so mistakes are normal. Some come from a simple slip. Others arise from situations nobody thought of, such as an unusual file, an unexpected combination of settings, or two actions happening at the same moment.

Testing finds many problems before release, but it cannot cover every possible situation. That is why even carefully made programs ship with some bugs and gain fixes later.

Why programs need updates

Updates happen for several separate reasons:

  • Fixing bugs. Mistakes found after release get corrected.
  • Closing security holes. Some bugs let attackers do things they should not. When one is discovered, a fix is released, which is the main reason keeping up with software updates is recommended.
  • Adding features. Developers improve what the program can do based on what users ask for.
  • Keeping up with the surroundings. Operating systems, websites, file formats and hardware change over time, and a program that does not adapt may stop working correctly.
  • Improving performance. Code can be made faster or use less memory and battery.

Updating is therefore a normal part of software’s life, not a sign that it was badly made. A program is closer to a service that is maintained than a finished object. When developers stop supporting a program, it does not stop working at once, but problems and security risks tend to build up with no one to fix them.

What changes between versions

Developers group changes into versions. Small fixes may only change the last number in a version label, while larger sets of changes get a bigger bump. The exact numbering scheme varies between projects, so the labels are a guide rather than a rule. Phone apps are updated through the store of the mobile operating system, and some desktop apps update quietly in the background, while others ask your permission. Either way, the new files replace the old ones, and the program starts afresh the next time it runs.

Putting it together

Software begins as text written by people, is translated into instructions the processor can follow, is loaded and managed by the operating system, and keeps changing as problems and needs appear. Understanding that cycle makes things like crashes, update prompts and compatibility warnings much less puzzling.

The complete guide to how computers work

How a Computer Works: From Switches to Screens
Read the guide

Keep exploring

Guides from other topics

All topics →