Auxiliary codes M03 and M04 are designed to control spindle rotation. The only difference between these two M codes is the direction of rotation.
M03 - Start rotating the spindle clockwise.
The M03 command remains active until it is canceled with M04 or M05.
M04 - Start rotation of the spindle counterclockwise.
The M04 command remains valid until it is canceled with M03 or M05.
M05 - Stop spindle rotation. At the end of the machining program and before changing the tool, you need to stop the spindle rotation using command M05.
M3 S6000; Start rotating the spindle clockwise at a speed of 6000 rpm.
M5; Stop spindle rotation