A magnetic stirrer consists of a magnetic bar placed inside the container with the liquid and a rotating magnet or a set of electromagnets under the container. When the magnet rotates, it creates a magnetic field that causes the stir bar to spin and mix the liquid. This setup ensures thorough mixing without introducing contaminants.