When you turn the key and hear rapid clicking but the engine doesn't crank, the starter motor is failing. The clicking is the starter solenoid trying to engage but failing to deliver enough current to spin the engine.
Battery vs. starter diagnosis: if a jump-start solves the problem, it was the battery. If the clicking continues after a jump-start, it's the starter motor.
Starters can fail gradually (occasional click-clack, then more frequent, then permanent failure) or suddenly (worked yesterday, dead today).
Replacement cost varies wildly by vehicle: $200 at a shop for an easy-access starter on a basic sedan, $800–$1,200 for a starter buried under the intake manifold on a V8.
Sometimes a stuck starter can be temporarily revived by tapping it firmly with a wrench while someone turns the key. This buys you time to get to a shop but isn't a long-term fix.