A computer appears to know the time, it shows a clock, stamps files, and triggers events on schedule, yet the processor at its center has no inherent sense of time whatsoever. What it has is a steady beat, and everything the system reports as time is counted from that beat by software. Understanding where the beat comes from, and why it is never perfectly steady, explains both how digital devices keep time and why they inevitably drift out of agreement with one another.
The beat originates in a quartz crystal. Quartz is piezoelectric, applying a voltage causes it to deform, and a crystal cut to a precise size oscillates at an extremely stable frequency determined by its physical dimensions. That oscillation is converted into an electrical clock signal, and the whole processor is paced by it, every instruction and every internal operation timed to its ticks. A clock speed quoted in gigahertz is a direct statement of this rate, billions of oscillations per second, each one a moment at which the processor can advance its work.
The processor does not know what a second is, it only counts ticks, and the translation into human time is performed by software that knows how many ticks the crystal produces per second. The system counts the oscillations, divides by the known rate, and reports the elapsed time, all measured forward from a reference date the system was given once and has been accumulating from ever since. The clock displayed on screen is, at bottom, a running total of crystal oscillations expressed in familiar units, which works precisely as long as the crystal's true rate matches the rate the software assumes.
That assumption is where timekeeping becomes imperfect. A quartz crystal is stable but not exact, its frequency varies slightly with temperature, shifts gradually as the crystal ages, and differs from one unit to the next due to manufacturing tolerances, so a crystal running marginally fast gains time and one running slow loses it, at a rate unique to each device. This is why a computer left to itself slowly diverges from the correct time, and why networked devices continually discipline their own clocks against external references using protocols such as NTP, adjusting their accumulated count to stay aligned with the atomic clocks maintained by national metrology laboratories. A processor keeps time much as a person counts seconds, steadily but never exactly, and the precision that modern systems appear to possess does not come from the crystal in any single device, it comes from a hierarchy of far better clocks and the protocols that quietly hold everything else in step with them.