1. Home
  2. Explore
  3. Computer Science
  4. How Computers Work

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

How Computers Work

Speaker 1Speaker 2

How Computers Work

6:18
0:00-6:18
  1. Anna

    Michael, have you ever wondered what's actually happening inside a computer when you press a key or move a mouse? It's all based on some pretty clever electrical engineering and logic.

  2. Michael

    I guess I've taken it for granted. I know it's all ones and zeros, but the details are a mystery to me. Where do we even start?

  3. Anna

    Let's start at the very bottom: the humble transistor. At its core, a transistor is like a switch controlled by electricity. There's a type called a MOSFET, which has three terminals: source, drain, and gate. Apply a voltage to the gate, and the switch closes—current flows from source to drain.

  4. Michael

    So it's like a light switch, but instead of your finger, a voltage flips it. And I'm guessing there are two types, like push-to-make and push-to-break?

  5. Anna

    Exactly! An N-channel MOSFET conducts when the gate is high, like push-to-make. A P-channel conducts when the gate is low, like push-to-break. In computers, we always use them in pairs called CMOS—Complementary Metal Oxide Semiconductor. The gates are tied together, so when one opens, the other closes.

  6. Michael

    That makes sense. And that pairing is what lets us build logic gates, right? Like the NOT gate—whatever you put in, you get the opposite out.

  7. Anna

    Bingo! With a NOT gate, if the input is high, the N-channel opens to ground so the output is low. If input is low, the P-channel opens to high voltage. But there's more than just NOT. You can build AND, OR, XOR, and their complements. And here's the kicker: the NAND gate is universal. You can build any other gate using only NAND gates.

  8. Michael

    So all those logic gates are actually built from transistors? And they can be combined into circuits that do arithmetic?

  9. Anna

    Exactly. Let's talk about binary numbers. Computers use base-2, with digits 0 and 1, which correspond to low and high voltage. For example, the binary number 101 means 1×4 + 0×2 + 1×1 = 5 in decimal. Multiple wires each carry one bit, and groups of 8 bits are called a byte.

  10. Michael

    Right, so how do you add two binary numbers? I remember something about carry bits.

  11. Anna

    For a single bit, 0+0=0, 0+1=1, 1+1=0 with a carry of 1. That's exactly how an XOR gate and an AND gate behave. XOR gives the sum bit, AND gives the carry. For multi-bit addition, you chain these together. And multiplication? It's just repeated shifting and adding—like shifting left is multiplying by 2.

  12. Michael

    And what about comparing numbers? For alarms or equal checks, I imagine we need to see if two numbers are identical.

  13. Anna

    Yes! The XNOR gate returns 1 when its two inputs are the same. So if you XNOR every pair of bits from two numbers, then AND all those results together, you get 1 only if every bit matches. That's how we check equality.

  14. Michael

    But computers don't just do one operation and stop. They need to store intermediate results and run a sequence of steps. How does that work?

  15. Anna

    That's where storage comes in. First, there's the latch, a circuit built from NAND gates that can hold a single bit. It has an enable input: when enable is 1, it reads the data input; when enable goes to 0, it holds that value. Eight latches make a register, which stores a byte. Registers are used inside the processor for temporary values.

  16. Michael

    And beyond registers, we have RAM and hard drives, each bigger but slower. I remember you mentioning a clock that synchronizes everything.

  17. Anna

    Exactly. The clock is a crystal that oscillates billions of times per second. Operations like addition take a few clock cycles: first load inputs into registers, then let the logic circuit settle, then store the result. The clock keeps everything in step.

  18. Michael

    So how does the computer know what operations to do? I mean, programs are just instructions stored in memory, right?

  19. Anna

    Yes! In the von Neumann architecture, instructions and data are both stored as binary numbers in memory. Each type of instruction has a fixed length. For example, an add instruction might be one byte for the opcode followed by three 8-byte addresses for the two inputs and the output. The computer starts at memory address 0, fetches that instruction, executes it, and then knows exactly how many bytes to skip to get to the next instruction.

  20. Michael

    So if you want the program to loop or make decisions, you need jump and conditional jump instructions. That's what makes a computer Turing complete, right? Capable of any computation given enough time and memory.

  21. Anna

    Precisely. A jump instruction tells the computer to go to a new address instead of the next one sequentially. A conditional jump only does that if a condition is true, like if two numbers are equal. With those, you can build loops and branches. That's enough to compute anything.

  22. Michael

    But programmers don't write raw instructions and memory addresses. They use high-level languages like C or Python, and a compiler translates that into machine code.

  23. Anna

    Yes, and functions are a key abstraction. A function is a block of instructions stored once. When you call it, the computer jumps to that block, runs it, and jumps back. This saves space and lets programmers reuse code. Libraries like DLLs are collections of compiled functions.

  24. Michael

    Now, what about output? How does the computer turn those bytes into images and sound?

  25. Anna

    A display is a grid of pixels. Each pixel has red, green, and blue subpixels. The brightness of each is controlled by a byte value from 0 to 255. So three bytes per pixel. To display an image, the computer just writes the correct bytes to a region of memory that's mapped to the display. Simple shapes are drawn by arithmetic and loops—like drawing a line using Bresenham's algorithm, which is just integer arithmetic.

  26. Michael

    And sound? Speakers produce sound by moving a membrane with an electromagnet. The computer sends a stream of numbers that represent the sound wave's amplitude at each time step, and a digital-to-analog converter turns that into a varying voltage.

  27. Anna

    Exactly. For input, keyboards use a grid of rows and columns. When a key is pressed, it completes a circuit, and the keyboard sends a code to the computer. That code is stored in memory as a message, and the operating system or application can read it. The mouse sends changes in position and button clicks, and the computer updates the cursor's coordinates.

  28. Michael

    So really, everything comes down to the transistor. From a bunch of switches, we build logic gates, arithmetic circuits, memory, and ultimately complete systems.

  29. Anna

    Right. And it's all layered: CMOS pairs give us NAND gates, NAND gates give us any logic, logic gives us instructions, instructions give us programs, and programs give us everything from games to operating systems. Computers are incredibly dumb—they just follow detailed instructions—but because they do it billions of times per second, we get amazing results.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent