Introduction
Gerber is the vector image format used to send the layers of a printed circuit board from design software to the factory. One file describes one flat, two-level image: a copper layer, a solder mask, a legend, a drill or rout layer, the board profile or a drawing. A board is a set of such files, usually zipped.
The current format is also called RS-274X, Extended Gerber or Gerber X. It is maintained by Ucamco, which publishes the Gerber Layer Format Specification. These pages follow revision 2026.05. Revisions that added attributes are often called X2, and the revision that added component data is called X3. The older Standard Gerber (RS-274-D) is revoked.
The extension is .gbr or .GBR, the registered media type is application/vnd.gerber, and the macOS type identifier is com.ucamco.gerber.image (conforming to public.plain-text and public.image). Many programs write Gerber under other names, often one extension per layer, such as .gtl, .gbl, .gts or .gko. Names ending .ger are also used. The extension does not say which layer a file holds: the .FileFunction attribute does.
A Gerber job file can list the files of a board. Drill data may also come as NC drill files.
Syntax
The file is UTF-8 text. Apart from the values of user attributes, only printable ASCII (codes 32 to 126) and line breaks are used. The format is case-sensitive, and command codes are in upper case. CR and LF have no effect when they follow *, % or ,. Spaces are allowed only inside strings and fields.
A word is a run of characters ended by *. There are two kinds of command:
- A word command is one word: a
G,DorMcode, in some cases preceded by coordinate data, for exampleX1000Y0D01*. - An extended command is one or more words enclosed in
%, starting with a two-letter code, for example%MOMM*%.
| Type | Form |
|---|---|
| Integer | [+-]?[0-9]+. Must fit a signed 32-bit integer. |
| Decimal | [+-]?((([0-9]+)(\.[0-9]*)?)|(\.[0-9]+)). Must fit an IEEE double. The decimal mark is a full stop. |
| Positive integer | Used for aperture numbers and macro variables. |
| String | Any characters except % and *. |
| Field | A string that also excludes the comma. Fields are separated by commas. |
| User name | [_a-zA-Z$][_a-zA-Z0-9]*. Cannot start with a full stop. |
| Standard name | A name starting with a full stop. Only names defined in the specification may be used. |
Names are case-sensitive and their definitions last to the end of the file. Inside strings and fields, \uXXXX and \UXXXXXXXX give a Unicode character by its hexadecimal code. Any character may be written this way. % (%) and * (*) must be escaped, a backslash is written \, and a comma inside a field is written , unless the string runs to the end of the word.
File structure
A file is a single stream of commands, processed in order. It must end with M02*, with nothing after it. Regions and block apertures must be closed first. The specification encourages readers to report an error when M02* is missing. The unit and the coordinate format must be set once each, before the first operation.
| Command | Form | Meaning |
|---|---|---|
| G04 | G04 string * | Comment. |
| MO | %MOMM*%, %MOIN*% | Unit: millimetres or inches. |
| FS | %FSLAX36Y36*% | Coordinate format. |
| AD | %ADD10C,0.1*% | Defines an aperture from a template. |
| AM | %AMname*…% | Defines a macro aperture template. |
| AB | %ABD12*% … %AB*% | Defines a block aperture. |
| Dnn | D10* | Selects the current aperture (number 10 or higher). |
| G01, G02, G03 | G01* | Plot state: linear, clockwise arc, counterclockwise arc. |
| G75 | G75* | Required before the first arc. |
| D01 | X…Y…D01*, X…Y…I…J…D01* | Plot a line or arc, or add it to a region contour. |
| D02 | X…Y…D02* | Move. |
| D03 | X…Y…D03* | Flash the current aperture. |
| LP | %LPD*%, %LPC*% | Polarity: dark or clear. |
| LM | %LMN*%, X, Y, XY | Mirroring of apertures. |
| LR | %LR45*% | Rotation of apertures. |
| LS | %LS0.5*% | Scaling of apertures. |
| G36, G37 | G36* … G37* | Start and end a region. |
| SR | %SRX2Y3I10J20*% … %SR*% | Step and repeat. |
| TF, TA, TO, TD | %TF.Part,Single*% | Set file, aperture and object attributes, and delete them. |
| M02 | M02* | End of file. |
The specification gives a formal grammar. A file is any sequence of the commands above followed by M02. A region holds only contours, each starting with D02 and followed by D01, D02, G01, G02 or G03. A block aperture may hold G04, AD, AM, Dnn, D01 to D03, G01 to G03, G75, LP, LM, LR, LS, regions, nested blocks and TF, TA, TO and TD, but not MO, FS, SR or M02.
Comments
A G04 comment has no effect on the image. Comments starting #@! are reserved for standard comments defined by the specification: an attribute command can be written this way, for example G04 #@! TA.AperFunction,SMDPad,CuDef*, with the same meaning, so that legacy software skips it.
Units and coordinates
The image is two-dimensional and seen from the top of the board, with X to the right, Y upwards and positive rotation counterclockwise. All files of a board use the same coordinate system.
MO sets the unit for the whole file, MM or IN. Inches are to be deprecated.
FS sets how the integers in coordinate data are read: %FSLAXidYid*%. L means leading zeros may be omitted and A means absolute coordinates. Both are required. i is the maximum number of integer digits, 1 to 6 (3 is typical), and d the number of decimal digits, which must be 6. X and Y use the same format. With FSLAX36Y36 in millimetres, X123123456 is 123.123456 mm and Y23456 is 0.023456 mm.
Coordinate data are signed integers with at least one digit, so zero is written 0. An omitted X or Y repeats the value of the current point. Each of D01, D02 and D03 leaves the current point at its coordinates.
Accuracy
The image is defined with unlimited precision, apart from the latitude allowed for arcs. Software processing it may move points by up to 0.5 µm either way, keeping coincident coordinates coincident. Writers should keep points and segments that are not coincident at least 1 µm apart, avoid arcs whose ends are less than 1 µm apart, and avoid objects smaller than 1 µm.
Graphics state
Operations depend on a graphics state. A file is invalid if an operation needs a parameter that has not been set.
| Parameter | Set by | May change | Initial value |
|---|---|---|---|
| Coordinate format | FS | No | Undefined |
| Unit | MO | No | Undefined |
| Current point | D01, D02, D03 | Yes | Undefined |
| Current aperture | Dnn | Yes | Undefined |
| Plot state | G01, G02, G03 | Yes | Undefined |
| Polarity | LP | Yes | Dark |
| Mirroring | LM | Yes | None |
| Rotation | LR | Yes | None |
| Scaling | LS | Yes | None |
Example
A 10 mm draw with a 0.2 mm round aperture, then one flash:
G04 A line and a pad*
%FSLAX36Y36*%
%MOMM*%
%TF.FileFunction,Copper,L1,Top*%
%ADD10C,0.2*%
%ADD11R,1.5X1.0*%
G75*
%LPD*%
D10*
G01*
X0Y0D02*
X10000000Y0D01*
D11*
X10000000Y0D03*
M02*
PCB fabrication data
For board manufacture the specification asks for the Gerber files, and any other documents, in one directory or ZIP archive (not RAR or 7z).
- One file holds one layer, and one layer is in one file.
- All files align, at scale 1:1, seen from the top.
- All pads are flashed, and every flash is a pad.
- A separate profile file is required, drawn as a region or as a clean closed path whose centre line is the profile. Copies of the profile in other layers are marked with
.AperFunction,Profile. - Drill and rout files are positive and use only circular apertures: flashes for holes, and draws or arcs forming open chains for slots. Other cut-outs belong in the profile. Diameters are finished (plated) sizes. Each drill span has its own file, and plated and non-plated holes are in separate files.
- Backdrilling uses a further non-plated drill file for the backdrilled span, with holes of the same diameter as the vias.
- Drawings (drill map, fabrication or assembly drawing) are kept apart from machine-readable layers.
- A netlist should be included, either as IPC-D-356A or as
.Pand.Nattributes on the pads. Net names may be replaced by arbitrary ones if the real names are confidential. - Component data for assembly goes in two extra layers, one for the top and one for the bottom.
- The attributes
.FileFunction,.FilePolarityand.SameCoordinatesare mandatory in fabrication data.
Divergence from spec
The specification lists mistakes found in real files and readers:
- Some CAD systems assume macro primitive 21 rotates about its own centre. It rotates about the macro origin.
- Some treat the hole in a standard or macro aperture as clearing what lies under a flash. It does not.
- Some read the diameter of a regular polygon aperture as the inside diameter. It is the outside diameter.
- Some implementations of the deprecated
MIandSFcommands also mirror or scale apertures or step distances. - Invalid constructs seen in files include a
%ICAS*%command, a%FSD…*%format,N2inside the format specification, coordinates such asIJ001with no digit afterI, and several images in one file separated by M00, M01 or M02. - Poor practice includes pads or copper pours painted with many strokes, pads made as regions or zero-length draws, and fewer than six decimals.
The text of revision 2026.05 is not wholly consistent: its attribute table names the values ViaDrill and BackDrill, while the text of its backdrilling example writes Via and Backdrill.
KiCad's file filter for Gerber files accepts the extensions gbr, gko, pho, gtl, gta, gto, gtp, gts, gbl, gba, gbo, gbp, gbs, and g or gm followed by one or two or more digits. The tracespace library recognises files exported from Eagle for OSH Park by names such as toplayer.ger, bottomsoldermask.ger or internalplane2.ger.
In the explorer
The viewer reads every command above, including the deprecated ones. It draws the layer with
standard, macro and block apertures, draws, arcs, regions, step and repeat, polarity,
mirroring, rotation and scaling, and draws single apertures, blocks and objects. It lists all
objects, apertures, macros, contours, attributes, nets, components, comments and commands,
checks the .MD5 attribute, and lists errors and deprecated elements.
AS is shown but not applied, as it concerns only an output device.
Files up to 256 MB are read. A picture is drawn in passes of 3 million objects and copies. One that is not finished carries a red striped edge; further passes draw on over it, 1, 10 or 100 at a time, until it is complete, also where more lies on one spot than a pass holds. Each picture also opens into quarters, which can be divided again.
Links
Software
Developers
- gerbv source – Gerber parsing and rendering library and viewer (C)
- KiCad file extensions – the extensions KiCad associates with each file type (C++)
- tracespace – PCB file parsing and rendering libraries, including layer detection by file name (JavaScript)
Reference
- Ucamco downloads – the Gerber Layer Format Specification (revision 2026.05), its grammar and test files
- Ucamco on Gerber – overview of the format and related documents