A stir bar operates in conjunction with a magnetic stirrer, which contains a rotating magnet or a set of electromagnets. When the magnetic stirrer is activated, the magnetic field causes the stir bar to spin, thus agitating the liquid in the container. This mechanism allows for uniform mixing of solutions, which is critical in various scientific applications, including nanotechnology.