These days they are usually electronic. There's a magnet you stick to a spoke, and then a pickup that gets attached someplace where the magnet will pass right over. Then there's a small brain that counts the time between each pass, and by taking the wheel circumference into account, tells you the speed.
Chat with our AI personalities
The speed you're travelling at is easiest determined by getting yourself a bike computer. They're cheap enough.
THe number of speeds on the bike on a derailer gear bike can be found by counting the number of sprockets(at the rear wheel) and multiplying that with the number of chainrings(by the pedals).
A good way is to position the wheel with the valve right down, put a mark on the ground, then while sitting in the saddle scoot the bike forward until the valve is pointing straight down again and put another mark there. Then it's a simple case of measuring the distance between the marks and enter that value into the speedo.
Most of them have a few different settings, like KMH or MPH, to show average speed, or current speed or total distance, or ride time or time of day. More advanced models can count down to a preset covered distance, show your cadence or calorie consumption. But basically you set them up with the units of your choice and then pick the display content that you like. After that it's just to read the numbers.