On your wheel is a ring with two tabs on it. The ring spins with the wheel. The two tabs engage with the speedo drive. Inside the speedo drive is a set of gears, the tabs spin one gear, this rear spins the other. The second gear has a square drive in the end. The inner core of the cable goes in this square drive.
So as the wheel spins the speedo drive spins the cable. Now up on the speedo end the cable drives a gear set and a magnet. The gear set turns the odometers. The magnet spins a cup that the needle is mounted to. The faster the cable spins the magnet the farther up the scale the needle moves.
Most often the cable is the problem. As Rambo said the cable breaks down near the speedo drive. It breaks there from lack of lube on the cable. With no lube the cable gets harder to turn as well as rusting to the outer cable housing. When the cable gets too hard to turn it breaks near the speedo drive.
Unhook the cable from the speedo drive. Take a wooden match stick and use tape to make a small flag on the match stick. Put the match stick in the speedo drive. Lift the wheel off the ground, spin the wheel and watch the flag. Does the flag spin? If so the speedo drive is ok.
Now unhook the cable from the speedo. Check to see that a square end sticks out both ends. Turn one end of the cable by hand, watch the other end, does it turn? If so does it spin easy? Pull the inner out of the housing. Is it rusty? If so you can try cleaning the inner cable and housing. If you can get them clean then a thin coat of grease on the cable except for the upper two inches or so. This will help prevent grease from moving up the cable into the speedo and crudding it up.
On the speedo itself use a match stick in the square drive and spin by hand, does the speedo spin easy, with a smooth needle movement? If so your speedo is probably ok.
I might put on a new cable any way. The rust will come back on the old one.
Leo