Which AutoCAD wrote this DWG? Read the first six bytes
Every DWG starts with a version code such as AC1032. What each code means, how to read it without AutoCAD, and what changed inside the file from R13 to 2018.
Someone sends you a DWG and your program refuses it, or opens it with half the drawing missing. The first question is always the same: which version of the format is this? You do not need AutoCAD to find out. The file tells you in its first six bytes.
The six letters#
A DWG file begins with six ASCII characters: AC followed by four digits, or by a release number such as 2.10 in the oldest files. They name the file format, not the program. Autodesk changes the format only every few releases, so several AutoCAD versions write the same code.
| Code | Format name | Written by |
|---|---|---|
| AC1.40 | 1.4 | AutoCAD 1.4 |
| AC1.50 | 2.0 | AutoCAD 2.0 |
| AC2.10 | 2.1 | AutoCAD 2.1 |
| AC1001 | 2.2 | AutoCAD 2.2 |
| AC1002 | 2.5 | AutoCAD 2.5 |
| AC1003 | 2.6 | AutoCAD 2.6 |
| AC1004 | R9 | AutoCAD R9 |
| AC1006 | R10 | AutoCAD R10 |
| AC1009 | R11 and R12 | AutoCAD R11, R12 |
| AC1012 | R13 | AutoCAD R13 |
| AC1014 | R14 | AutoCAD R14 |
| AC1015 | 2000 | AutoCAD 2000 to 2002 |
| AC1018 | 2004 | AutoCAD 2004 to 2006 |
| AC1021 | 2007 | AutoCAD 2007 to 2009 |
| AC1024 | 2010 | AutoCAD 2010 to 2012 |
| AC1027 | 2013 | AutoCAD 2013 to 2017 |
| AC1032 | 2018 | AutoCAD 2018 and later |
Read it yourself#
Any tool that shows the start of a file will do. On Linux or macOS:
head -c 6 drawing.dwg; echoOn Windows, in PowerShell:
[System.Text.Encoding]::ASCII.GetString((Get-Content drawing.dwg -Encoding Byte -TotalCount 6))In PowerShell 7 the parameter is -AsByteStream instead of -Encoding Byte. A text editor also works: open the DWG and look at the first characters of the first line, before the binary noise starts.
If the six characters are not one of the codes above, the file is not a DWG, whatever its name says. A DXF starts with plain text such as 0 and SECTION.
What changed between the codes#
The code matters because the inside of the file changed shape more than once. Three changes decide whether a reader can open a file at all.
2004: the file became a container#
From AC1018 on, a DWG is split into pages that are compressed and checked with a checksum, and a map says where each page lives. The small header that points to that map is scrambled with a fixed pseudo-random sequence, not to protect anything, just so it is not plain text. A reader has to undo the scrambling, read the page map, decompress each page and put the sections back together before it sees a single line.
2007: text moved to its own stream#
From AC1021 on, each object keeps its numbers, its text and its references to other objects in three separate streams. A reader must find where each stream starts inside the object before it can read any of them.
2010: the object type got a new encoding#
From AC1024 on, the number that says what an object is (line, arc, text) is stored with a two-bit prefix that says how to read the rest. Read it the old way and every line and arc looks like an unknown custom object. We made exactly that mistake, and the post about it shows how far a plausible wrong number can carry you.
Since 2010 the format has moved on twice, to AC1027 and AC1032, but the way objects are stored stayed close enough that one reader can handle all three with small differences.
Which versions cicada reads#
cicada, the CAD editor on this site, reads every release from AC1012 (R13) to AC1032 (2018 and later). Each one gets its own field layout, because a reader that applied the 2010 rules to a 2000 file would not crash: it would produce a drawing that looks plausible and is wrong. The eight layouts are measured against two sets of files in the repository's test fixtures. One is a drawing the ODA File Converter wrote in every release from R13. The other is a drawing AutoCAD itself saved as R14, 2000, 2004, 2007, 2010, 2013 and 2018, and as DXF from 2000 on. In all seven, cicada reads 304 of the 345 objects, and every one matches the DXF of the same drawing. The other 41 are kinds it does not draw yet, such as tables and multileaders, and it lists them by type. That is why the years between the three changes above are not a gap any more.
Files before R13 are built differently. They have no section map and no object map: the header sits at fixed places, followed by tables of layers, linetypes and blocks and by lists of entities, one record after the other. cicada reads them from AC2.10 (AutoCAD 2.1) to AC1009 (R12). Each release is checked against a drawing AutoCAD saved in it, with the DXF saved beside it, from LibreDWG's test files: 2.1, 2.6, R9, R10 and R11. On all of them cicada reads the same entities at the same coordinates as the DXF. AC1001 and AC1002 are read with the rules of their neighbours, but no sample file checks them. AutoCAD 1.4 and 2.0 (AC1.40 and AC1.50) are refused by name, because no sample shows their layout.
A damaged file is not refused either. When the map that lists where each object sits is missing or cut off, cicada walks the object data from the start and keeps every object whose checksum is right. A file cut off in the middle opens with what comes before the cut, and the message counts the places where reading failed. An R2007 file that has lost its page or section map is the exception: its data pages carry no header of their own, so nothing can be found without those maps, and cicada says so.
What comes out the other end is DXF in the newest release, R2018 (AC1032). Almost every other program reads it, and it costs nothing to write the current format rather than a 1997 one.
What the code does not tell you#
- Which program wrote the file. Other CAD programs write DWG too, with the same codes. A few bytes further on the file holds a maintenance version, and the header holds more, but the six letters only name the format.
- Whether you can see everything. A drawing can hold objects from AutoCAD add-ons that only that add-on knows how to draw. A good viewer tells you how many it could not show; cicada lists them by type after opening.
- The units. Millimetres, inches and metres are a setting inside the header, called
INSUNITS. When a file does not set it, a reader has to assume, and should say that it did.
If you just want to look at a DWG, you can open it in your browser with cicada, and it will tell you its version on the way in.