How does CNC machine work?

Basically, the CNC stands for Computer Numerical Control which refers to a computer controller that controls the movement of every axis of the machine using G and M codes instructions and drives the spindle or machine tool into a raw material to fabricate or to remove the unwanted material from workpiece more accurately without human intervention.

About G codes:
G codes is a common name in the CNC programming language that begins with the letter G. Basically, the G codes tell the machine tool what type of action need to perform and trigger the CNC machine tools axis movement.

About M codes:
M codes use to control the overall machine and use to perform specific action in CNC programs such as to start & stop the machine, turn ON the spindle, turn coolant ON/OFF and etc. Most of the M codes have default function but can be customized with the use of macro files including the predefined M codes.