How does a computer work?

Computers can only do a few very simple operations consisting of flipping electrical switches on and off. You can represent numbers in patterns of the on-off states of sequences of switches. By flipping switches on and off in particular patterns, you can perform simple mathematical operations on the numbers. You can do more complex mathematical operations by stringing simpler operations together.

Below is a diagram showing a computer that can add one plus one to get two. It’s made out of an XOR gate and an AND gate, each of which is a relatively simple bunch of transistors wired together in particular ways. Transistors are just on-off switches that can be flipped electrically, so they have no moving parts (except electrons.) The beauty part is that the output wire of one transistor can be used to flip another transistor on and off.

The “numbers” in the diagram are just voltages: “zero” is zero volts, and “one” is (I think) 2.5 volts. The numbers in a computer are encoded in binary (base two) because it’s the most convenient way to physically realize them — voltage that’s pretty close to zero can be read as zero, and a voltage that’s pretty close to 2.5 can be read as one.
This simple adder has two input wires and two output wires. The input wires each represent a single binary digit, and the output wires together represent two binary digits. If one input wire has a voltage and the other doesn’t, the equivalent of adding one plus zero, the adder returns no voltage in the “twos” digit and a voltage on the “ones” digit. If there’s a voltage on both input wires, the equivalent of adding one plus one, the adder returns a voltage on the “twos” digit and no voltage on the “ones” digit, the binary number 10, or as we know it in decimal notation, 2.

Here’s a diagram of a four-bit adder, capable of adding numbers as big as sixteen. The diagram shows how adding seven (0111) plus twelve (1100) to get nineteen (10011) would work.
Wire together enough adders and other basic logic devices, set up at the right initial voltages, and you’ve got yourself a computer.

Original post on Quora