Anachronisms happen when something in your book is out of synch with time. In other words, anachronisms are references that are out of place given the text's chronology, sequence of events, or historical setting.
So if Shakespeare's moody prince Hamlet took on Laertes with a machine gun, or if he texted his buddies Rosencrantz and Guildenstern with his iPhone, we'd have major anachronisms on our hands. Hamlet is a prince in Denmark in the late Middle Ages, so machine guns and iPhones would make absolutely zero sense.
Anachronisms are errors, in a sense, but authors also sometimes use them on purpose to call our attention to chronology, history, and everything related to time.