A simple computer works by combining binary bits of data via logic operations. 0 OR 0 gives 0, 0 OR 1 gives 1, 1 OR 1 gives 1. 0 AND 0 gives 0, 0 AND 1 gives 0, 1 AND 1 gives 1, and so forth. Clever combination of AND, OR, NOT and IF functions allow you to perform mathematical and other operations on multi-digit binary numbers. Do this millions of times on a silicon chip and you've got the laptop I'm typing on right now. Before silicon chips, transistors and vacuum tubes, there were mechanical computers that work by physically moving switches or wheels to indicate the changes in value. An extremely simple example is the odometer on your car (if it's not electronic). Every so many rotations of the axle leads the tenth-mile wheel to move forward. Once that wheel turns all the way around, it causes the mile wheel to move forward one click. Once that goes around from 0 to 9, it causes the ten mile wheel to move forward one click. If you go 100,000 miles, or a million, or however many digits the odometer has (I'll have to go out to my car and look), the whole register clears and it flips back around to zero. This, of course, is an extremely simple mechanism only built to count in a forward direction. The early history of computing is all about the development of mechanical adding machines and other calculators.
This leads us to the Digi-Comp I. This was an educational toy sold in the 1960's where you move two levers back and forth, and depending on how you 'programmed' it, that is, how you arranged a series of wires, a little counter would give you the result of a simple mathematical operation.
Recently Nico71 built a LEGO Digi-Comp I.
You can watch it in action serving as a counter.