G-code is a programming language used to control automated machine tools, such as CNC milling machines, and for 3D-printer slicer applications. It is the most widely used computer numerical control (CNC) programming language. The G in G-code stands for geometry, and it provides metric-based numeric control of CAM-controlled equipment. G-code instructions are provided to a machine controller that tells the motors where to move, how fast to move, and what path to follow. The code used in G-code and other CNC code tells the computer that controls the motors of the manufacturing equipment how far to move and at what speed. G-code can repeat an action indefinitely until it is stopped.
G-code began as a limited language that lacked constructs such as loops, conditional operators, and programmer-declared variables with natural-word-including names. It was unable to encode logic but was just a way to "connect the dots" where the programmer figured out many of the dots locations longhand. The first implementation of a numerical control programming language was developed at the MIT Servomechanisms Laboratory in the 1950s, and the earliest version of G-code was standardized by the Electronic Industries Alliance in the early 1960s. Today, the exact, reproducible manufacturing afforded by G-code and similar languages is used in the creation of all kinds of military and scientific equipment and consumer goods.
If you work with CNC machines or 3D printers, understanding G-code is essential. The G-code commands instruct the machine where to move, how fast to move, and what path to follow. The G-code commands are simple and quite intuitive to understand, and most of the lines have the same structure. The "complicated" part of the G-code are all those numbers we see, which are just Cartesian coordinates. The G01 G-code command instructs the machine to move in a straight line at a set feed rate or speed. We specify the end position with the X, Y, and Z values, and the speed with the F value. The machine controller calculates (interpolates) the intermediate points to pass through to get that straight line.