What Are DXF and DWG?
DWG (Drawing) is the native binary format of AutoCAD, the world's leading CAD (Computer-Aided Design) software by Autodesk. Created in 1982 when AutoCAD launched, DWG has become the de facto standard for technical drawings in architecture, engineering, and construction (AEC) globally.
DXF (Drawing Exchange Format) is a documented interchange format also created by Autodesk in 1982 as an open alternative to DWG — designed to allow other CAD systems to import and export AutoCAD drawings. DXF is text-based (ASCII) by default, though binary DXF also exists. Because its specification is publicly documented, DXF is supported by virtually every CAD application on earth.
Both formats store 2D and 3D vector geometry: lines, arcs, circles, polylines, splines, surfaces, solids, blocks, text, dimensions, layers, hatches, and raster image references.
DWG Format History and Versions
DWG is proprietary — Autodesk does not publish its specification. This has led to a long-running legal battle and the creation of the Open Design Alliance (ODA/Teigha), which reverse-engineered DWG. Major DWG versions correspond to AutoCAD releases:
| DWG Version | AutoCAD Release | Year |
|---|---|---|
| R13 | AutoCAD R13 | 1994 |
| R14 | AutoCAD R14 | 1997 |
| 2000 (AC1015) | AutoCAD 2000-2002 | 1999 |
| 2004 (AC1018) | AutoCAD 2004-2006 | 2003 |
| 2007 (AC1021) | AutoCAD 2007-2009 | 2006 |
| 2010 (AC1024) | AutoCAD 2010-2012 | 2009 |
| 2013 (AC1027) | AutoCAD 2013-2017 | 2012 |
| 2018 (AC1032) | AutoCAD 2018-2024 | 2017 |
The first six bytes of a DWG file contain the version string: AC1032 for DWG 2018 format. AutoCAD can save to older versions ("Save As" with older format selection) for interoperability.
DXF Structure
DXF files are organized in sections, each consisting of group codes (integers) and associated values:
0 ← group code (entity type)
SECTION ← value
2
HEADER ← section name
9
$ACADVER ← header variable
1
AC1032 ← version
0
ENDSEC
0
SECTION
2
ENTITIES
0
LINE ← a line entity
8
Layer_1 ← layer name
10
100.0 ← X start point
20
200.0 ← Y start point
30
0.0 ← Z start point
11
300.0 ← X end point
21
200.0 ← Y end point
31
0.0 ← Z end point
0
ENDSEC
0
EOF
DXF Sections
| Section | Content |
|---|---|
| HEADER | Drawing variables ($ACADVER, $EXTMIN, $EXTMAX, $INSUNITS, etc.) |
| CLASSES | Application-defined classes (extended entities) |
| TABLES | Layers, linetypes, text styles, dimension styles, blocks, viewports |
| BLOCKS | Block definitions (reusable geometry components) |
| ENTITIES | All drawing geometry (lines, arcs, text, inserts, etc.) |
| OBJECTS | Non-graphical objects (dictionaries, groups, layouts) |
| THUMBNAILIMAGE | Preview image embedded in the file |
Common Entity Types
| Entity | Description |
|---|---|
| LINE | 2D/3D line segment |
| ARC | Circular arc |
| CIRCLE | Full circle |
| ELLIPSE | Ellipse |
| LWPOLYLINE | Lightweight polyline (2D, most common) |
| POLYLINE | Full 3D polyline with mesh support |
| SPLINE | NURBS spline curve |
| TEXT | Single-line text |
| MTEXT | Multi-line text |
| INSERT | Block reference (instance of a BLOCK definition) |
| HATCH | Filled area with pattern |
| DIMENSION | Dimension annotation |
| LEADER | Leader line annotation |
| IMAGE | Raster image reference |
| 3DFACE | 3D triangular/quadrilateral face |
| SOLID | Filled quadrilateral |
| ATTRIB | Block attribute instance |
Coordinate Systems and Units
DXF/DWG stores coordinates in floating-point world units. The unit system is set by $INSUNITS in the HEADER:
| Code | Unit |
|---|---|
| 0 | Unitless |
| 1 | Inches |
| 2 | Feet |
| 4 | Millimeters |
| 5 | Centimeters |
| 6 | Meters |
| 14 | Micrometers |
User Coordinate System (UCS): custom coordinate system origin and orientation, stored per-viewport. Critical for 3D drawings and isometric views.
Paper Space vs. Model Space: AutoCAD maintains two environments — Model Space (where actual geometry is drawn at real-world scale) and Paper Space/Layout (where viewports frame model geometry for plotting at specific scales).
Layers, Colors, and Linetypes
Layers are the primary organizational structure in CAD drawings:
- Each entity belongs to a layer.
- Layers have color (AutoCAD Color Index 0-255, or True Color RGB), linetype, lineweight, and plot state.
- Standard layer naming conventions (ISO, AIA, BS1192) ensure interoperability in collaborative projects.
AutoCAD Color Index (ACI): 255 standard colors where 1=red, 2=yellow, 3=green, 7=white/black. BYLAYER means the entity inherits the layer's color.
Linetypes: stored in LIN files and referenced by name (CONTINUOUS, DASHED, DASHDOT, CENTER, etc.). Custom linetypes with embedded text or shapes are also supported.
Blocks and External References (Xrefs)
Blocks: named collections of geometry stored in the BLOCKS section and instantiated via INSERT entities. Used for repeating symbols (doors, windows, bolts, trees). Blocks can have attributes (ATTDEF/ATTRIB) — text fields that can be filled per-instance.
Xrefs (External References): one drawing can reference other DWG files as if they were blocks, without embedding the geometry — the geometry is loaded from the external file at open time. Used for attaching base maps, structural drawings, and MEP (mechanical, electrical, plumbing) overlays in collaborative AEC workflows.
Dynamic Blocks (DWG only): blocks with parametric behavior — stretch, flip, rotate, array — controlled by block parameters and actions. Not supported in DXF.
Reading DXF and DWG Programmatically
ezdxf (Python, open source):
import ezdxf
doc = ezdxf.readfile("drawing.dxf")
msp = doc.modelspace()
# Iterate all LINE entities
for entity in msp.query("LINE"):
start = entity.dxf.start # Vec3(x, y, z)
end = entity.dxf.end
layer = entity.dxf.layer
print(f"Line: {start} → {end} on layer '{layer}'")
# Create a new DXF
doc = ezdxf.new(dxfversion="R2018")
msp = doc.modelspace()
msp.add_line((0, 0), (100, 50), dxfattribs={"layer": "MY_LAYER"})
doc.saveas("output.dxf")
LibreDWG (C library, GNU): reads DWG files (from R2.6 to 2018). No write support for safety.
Open Design Alliance Teigha/ODA SDK (C++/C#/Java, commercial): full read/write for all DWG/DXF versions. Used by most commercial CAD alternatives.
Converting DXF and DWG
- DWG → DXF: AutoCAD "Save As DXF", or free tools: DWG TrueView, ODA File Converter.
- DXF → DWG: Same tools.
- DXF/DWG → PDF: AutoCAD Plot dialog (PDF driver), Inkscape (DXF only), ezdxf + matplotlib.
- DXF/DWG → SVG: Inkscape import (DXF), ezdxf
r2000→ SVG, or Draftsight. - DXF → PNG/JPEG: ezdxf render with matplotlib backend, or convert via PDF.
- PDF → DXF: PDF2CAD (commercial), Able2Extract, or Inkscape (for vector-only PDFs).
- SKP (SketchUp) → DXF: SketchUp's File → Export → 3D Model → DXF.
- IFC → DWG: via Revit export or BIM authoring tools.
DXF vs. DWG: Which to Use?
| Scenario | Recommendation |
|---|---|
| Sharing with non-AutoCAD users | DXF — universal compatibility |
| Round-trip editing in AutoCAD | DWG — no data loss |
| Programming / scripting | DXF — open spec, many libraries |
| Dynamic blocks / xrefs | DWG — not fully preserved in DXF |
| Web display (SVG conversion) | DXF — easier to parse |
| Archive / long-term storage | DXF — open format |
| BIM (Building Information Modeling) | IFC instead — richer semantics |
Best Practices
- Save DXF as ASCII (not binary) for maximum compatibility with third-party tools.
- Specify DXF version explicitly — R2010 or R2013 is a good balance of features and compatibility.
- Purge unused elements before export:
PURGEcommand removes unused layers, blocks, and linetypes. - Audit drawing before export:
AUDITfixes drawing database errors. - Bind xrefs before distributing DWG files to avoid broken references.
- Use standard layer naming (ISO 13567 or AIA layer standards) for collaborative projects.
- Set
$INSUNITScorrectly to avoid scale mismatches when importing. - Include a title block as a block reference with attributes for project metadata.
- Use ezdxf for Python scripting — it is the best open-source DXF library.
- Archive DXF alongside DWG for long-term accessibility when proprietary readers may not be available.
Related conversions
Frequent conversions across the catalogue: