Like you, most keen cyclists like to know the following information when they are out cycling: How fast am I going? How far have I been? And how long did it take me? As well as this basic data cycle computers can give details of average speed, cadence, temperature, heart rate, etc.
All bike computers work in the same way, you attach a magnet to a spoke on the front wheel and as the wheel rotates a sensor that is mounted on the front fork counts how fast the wheel is turning. When the wheel size is configured in the computer, it can then calculate how fast you are going and how far you have been.