Understanding the DWG File Format

A technical deep dive into AutoCAD’s native binary format — how DWG™ files are structured, what entity types they contain, and how our free viewer parses them.

Open the DWG Viewer

What Is a DWG File?

DWG (short for “drawing”) is the native binary file format created by Autodesk for AutoCAD. First introduced in the early 1980s, it has become the de facto standard for 2D and 3D CAD data in architecture, engineering, and construction (AEC). Unlike text-based formats like DXF, DWG is a compact binary format optimized for performance.

A DWG file contains everything needed to describe a technical drawing: geometric entities (lines, arcs, circles, polylines), organizational structures (layers, blocks), annotation objects (text, dimensions), and metadata (units, coordinate systems, drawing properties).

Binary File Structure

A DWG R2000 file is organized into several sections, read sequentially:

File Header

Magic bytes ("AC1015"), version identifier, section locators (offsets to each section in the file), and encryption seeds.

Class Section

Defines custom object classes beyond the built-in types. Each class maps a class number to a DXF name (e.g., ACDBPLACEHOLDER, LAYOUT).

Object Map

A lookup table mapping every object handle (a unique integer ID) to its byte offset in the data section. This is how the parser finds any object by handle.

Data Section

The bulk of the file. Contains all objects serialized as variable-length bit streams. Each object starts with its type number and size, followed by entity-specific fields.

Handle Section

Each entity stores handle references to related objects: its owner, layer, linetype, reactors, and linked entities (prev/next in the entity chain).

Second Header

A duplicate of key header data, used for file recovery if the primary header is corrupted.

Bit-Level Encoding

Unlike most file formats that work with whole bytes, DWG uses bit-level encoding to minimize file size. Fields are packed at arbitrary bit boundaries using specialized data types:

TypeNameDescription
BBitSingle bit (0 or 1)
BSBit Short2-bit prefix + 0, 1, or 2 bytes (encodes 16-bit integers)
BLBit Long2-bit prefix + 0 to 4 bytes (encodes 32-bit integers)
BDBit Double2-bit prefix + 0 or 8 bytes (encodes 64-bit IEEE doubles)
DDDefault Double2-bit prefix + 0, 4, 6, or 8 bytes (delta from a default value)
HHandle4-bit code + 4-bit counter + variable bytes (object references)

The DD (Default Double) type is especially efficient for vertex data: the first point is stored as two full doubles (2RD = 16 bytes), while subsequent points use delta encoding (2DD) that typically requires only 0–4 bytes per coordinate.

Supported Entity Types

Our DWG viewer currently parses and renders the following entity types:

LINE

Straight line between two points

CIRCLE

Circle defined by center and radius

ARC

Circular arc with start and end angles

ELLIPSE

Ellipse or elliptical arc

LWPOLYLINE

Lightweight polyline with optional bulge arcs and widths

POLYLINE_2D

Legacy 2D polyline with separate VERTEX entities

SPLINE

NURBS or Bezier curves (control points and fit points)

TEXT

Single-line text with position, height, and rotation

MTEXT

Multi-line text with formatting codes

INSERT

Block reference (places a named block at a given position, scale, and rotation)

DIMENSION

Associative dimensions (linear, aligned, angular, radial, diameter, ordinate)

HATCH

Filled regions with pattern fills and boundary loops

SOLID

Filled triangles and quadrilaterals

POINT

Point marker entity

OLE2FRAME

Embedded OLE objects (bitmaps, images, spreadsheets)

BODY / 3DSOLID

ACIS solid bodies (decoder infrastructure ready, pending test data)

Supported Table Objects

Beyond geometric entities, DWG files contain table objects that define the drawing’s organizational structure:

LAYER

Layer definitions with color, linetype, and on/off state

LTYPE

Linetype definitions (dash patterns)

STYLE

Text style definitions (font, height, width factor)

BLOCK_HEADER

Block definitions containing geometry entities

BLOCK_CONTROL

Block table control object

DICTIONARY

Named object dictionaries

Not Yet Supported

The following entity types are recognized but not yet fully decoded or rendered. Most are uncommon in typical architectural drawings:

ATTRIB / ATTDEF

Block attributes and attribute definitions

MINSERT

Multiple INSERT in a rectangular array

VIEWPORT

Paper space viewports

LEADER / MLEADER

Leader lines with text annotations

TOLERANCE

Geometric tolerance symbols

RAY / XLINE

Infinite construction lines

TRACE

Legacy filled 2D segments (rarely used)

SHAPE

SHX shape references

IMAGE / WIPEOUT

Raster image attachments and wipeout regions

TABLE

Table objects (R2005+ feature)

MESH

3D polygon mesh

3DFACE

3D triangular/quadrilateral face

DWG Version History

The DWG format has evolved through many versions. Each version is identified by a 6-byte ASCII string at the start of the file:

Version IDAutoCAD VersionYearViewer Support
AC1015R2000 / R2000i / R20021999–2002Full
AC1018R2004 / R2005 / R20062003–2006Partial
AC1021R2007 / R2008 / R20092006–2009Not yet
AC1024R2010 / R2011 / R20122009–2012Not yet
AC1027R2013 / R2014 / R2015 / R2016 / R20172012–2017Not yet
AC1032R2018 / R2019 / R2020 / R2021+2017–presentNot yet

R2000 (AC1015) remains the most common interchange format. Most CAD software can export to R2000 via “Save As.” If your file uses a newer version, re-save it as DWG R2000 to open it in our viewer.

How Our Viewer Parses DWG Files

Our viewer is a pure TypeScript implementation that runs entirely in your browser. No server-side processing, no WASM, no native binaries. The parsing pipeline:

  1. 1BitReader reads the raw binary data at arbitrary bit offsets, decoding B, BS, BL, BD, DD, and Handle types.
  2. 2FileHeader parser reads the version magic, section offsets, and CRC checksums.
  3. 3ObjectMap parser builds a handle-to-offset lookup table from the compressed section data.
  4. 4ObjectDecoder reads each object’s common entity data (layer, color, linetype), then dispatches to entity-specific decoders for the geometry fields.
  5. 5Canvas2DRenderer walks the entity list and renders each one to an HTML5 Canvas using the 2D context API, with viewport transform for pan and zoom.

DWG vs DXF vs DWF

FormatTypePrimary UseEditable?
DWGBinaryAutoCAD’s native format, full fidelityYes (in AutoCAD)
DXFText/BinaryOpen exchange between CAD programsYes
DWFBinaryLightweight sharing (like PDF for CAD)View only

Also see: DWG Viewer · DXF Viewer · How to Open a DWG File · CAD Viewer

Need a wellness lighting solution?
Contact our experts today!