Skip to main content
Design rules define the manufacturing constraints and electrical requirements for your PCB. The DRC (Design Rule Check) engine validates your layout against these rules to ensure manufacturability and correct operation.

Overview

KiCad’s design rule system is built around the DRC_ENGINE class (source/pcbnew/drc/drc_engine.h:131), which evaluates constraints and reports violations. Rules can be simple global settings or complex conditional expressions.

DRC Engine Architecture

DRC_ENGINE Class

// Source: pcbnew/drc/drc_engine.h:131
class DRC_ENGINE : public UNITS_PROVIDER
{
    BOARD* m_board;
    BOARD_DESIGN_SETTINGS* m_designSettings;
    std::vector<DRC_TEST_PROVIDER*> m_testProviders;
    
    void RunTests( PROGRESS_REPORTER* aProgressReporter );
    std::vector<std::shared_ptr<DRC_ITEM>> GetViolations();
    void EvalRules( DRC_CONSTRAINT_T aConstraintType,
                   const BOARD_ITEM* a,
                   const BOARD_ITEM* b,
                   PCB_LAYER_ID aLayer,
                   REPORTER* aReporter );
};

Design Constraints

Clearance Rules

Minimum spacing between objects

Track Width

Trace width constraints

Via Size

Via diameter and drill limits

Differential Pairs

Coupled routing requirements

Rule Types

Clearance Constraints

Define minimum spacing between objects:
Electrical clearance between copper features:
// Tested by: drc_test_provider_copper_clearance.cpp
min_clearance: 0.2mm  // Typical for standard PCB
Applies between:
  • Track to track (different nets)
  • Track to pad
  • Pad to pad
  • Zone to any copper

Track Constraints

Control trace geometry:
track_width
min/opt/max
Minimum: 0.127mm (5 mil) typical for fine-pitchOptimal: 0.254mm (10 mil) for standard signalsMaximum: Unlimited (or limited for controlled impedance)
annular_width
minimum
Copper ring around drilled holeTypical: 0.15mm minimum for standard PCBs
track_angle
allowed
Permitted routing anglesCommon: 45° or 90° only (avoid arbitrary angles)

Via Constraints

// Tested by: drc_test_provider_via_diameter.cpp
struct VIA_DIMENSION
{
    int m_Diameter;     // Via pad diameter
    int m_Drill;        // Drill hole size
};
Typical values:
  • Standard Via: 0.6mm pad, 0.3mm drill
  • Micro Via: 0.4mm pad, 0.2mm drill (laser drilled)
  • Large Via: 1.0mm+ for high current

Differential Pair Rules

For high-speed signals (USB, LVDS, etc.):
// Tested by: drc_test_provider_diff_pair_coupling.cpp
struct DIFF_PAIR_CONSTRAINT
{
    int gap;              // Spacing between traces
    int max_uncoupled;    // Maximum uncoupled length
    int width;            // Individual trace width
};
USB 2.0 typically requires:
  • Gap: 0.127mm (5 mil)
  • Width: 0.254mm (10 mil)
  • Impedance: 90Ω differential

Custom Design Rules

KiCad supports advanced rule syntax for complex constraints:

Rule File Format

Rules are defined in the .kicad_dru file or board settings:
(version 1)

# Global clearance rule
(rule "default clearance"
  (constraint clearance (min "0.2mm")))

# High-voltage clearance
(rule "HV clearance"
  (condition "A.NetClass == 'HV' || B.NetClass == 'HV'")
  (constraint clearance (min "2.0mm")))

# Power trace width
(rule "power width"
  (condition "A.NetClass == 'Power'")
  (constraint track_width (min "0.5mm")))

# USB differential pairs
(rule "USB diff pair"
  (condition "A.inDiffPair('/USB*')")
  (constraint diff_pair_gap (min "0.127mm") (opt "0.127mm"))
  (constraint diff_pair_width (min "0.254mm") (opt "0.254mm")))

Rule Conditions

Filter rules using expressions:
A.NetName == 'GND'
A.NetClass == 'Power'
A.inDiffPair('/USB_*')
A.Layer == 'F.Cu'
A.isPlated()
A.Type == 'Via'
A.Type == 'Track'
B.Type == 'Pad'
A.hasProperty('PartNumber')
A.getProperty('Value') == '100nF'

DRC Test Providers

The DRC engine runs multiple specialized test providers:
1

Copper Clearance

Provider: drc_test_provider_copper_clearance.cppChecks spacing between all copper features on each layer.
2

Hole Size

Provider: drc_test_provider_hole_size.cppValidates drill diameters against manufacturing limits.
3

Track Width

Provider: drc_test_provider_track_width.cppEnsures all traces meet minimum/maximum width constraints.
4

Connectivity

Provider: drc_test_provider_connectivity.cppChecks for unconnected nets and starved thermals.
5

Schematic Parity

Provider: drc_test_provider_schematic_parity.cppVerifies PCB matches schematic netlist.
6

Silk Clearance

Provider: drc_test_provider_silk_clearance.cppPrevents silkscreen over pads and vias.
7

Text Dimensions

Provider: drc_test_provider_text_dims.cppValidates text size and stroke width.
8

Solder Mask

Provider: drc_test_provider_solder_mask.cppChecks solder mask clearance and bridging.

Running DRC

Interactive DRC

Run from the PCB editor:
  1. Inspect → Design Rules Checker
  2. Select test scope (entire board or specific area)
  3. Choose which violations to check
  4. Run tests and review violations
  5. Navigate to errors from the violations panel

Batch DRC

Run DRC from command line or CI/CD:
kicad-cli pcb drc \
  --output report.txt \
  --format json \
  --severity-all \
  design.kicad_pcb

Violation Handling

The engine calls violation handlers for each error:
typedef std::function<void(
    const std::shared_ptr<DRC_ITEM>& aItem,
    const VECTOR2I& aPos,
    int aLayer,
    const std::function<void( PCB_MARKER* )>& aPathGenerator
)> DRC_VIOLATION_HANDLER;

Clearance Caching

For performance, clearance values are cached:
// Source: pcbnew/drc/drc_engine.h:42
struct DRC_OWN_CLEARANCE_CACHE_KEY
{
    KIID m_uuid;          // Item identifier
    PCB_LAYER_ID m_layer; // Layer being checked
};

// Cache stores computed clearance values
unordered_map<DRC_OWN_CLEARANCE_CACHE_KEY, int> m_clearanceCache;

Net Classes

Group nets with common requirements:
class NETCLASS
{
    wxString m_name;           // Net class name
    int m_clearance;           // Clearance requirement
    int m_trackWidth;          // Default track width  
    int m_viaDiameter;         // Via pad size
    int m_viaDrill;            // Via drill size
    int m_diffPairWidth;       // Diff pair trace width
    int m_diffPairGap;         // Diff pair spacing
};
Assign nets to classes in schematic or PCB editor. Classes provide default values that can be overridden by specific design rules.

Manufacturing Limits

Typical PCB manufacturer capabilities:
  • Minimum trace: 0.127mm (5 mil)
  • Minimum clearance: 0.127mm (5 mil)
  • Minimum drill: 0.3mm (12 mil)
  • Minimum annular ring: 0.15mm (6 mil)

Best Practices

Begin with relaxed rules that match standard PCB capabilities. Tighten only where necessary for routing density or performance.
Group related nets (power, high-speed, differential pairs) into net classes. Apply class-specific rules rather than per-net rules.
Add comments in custom rules explaining the reasoning. Include links to datasheets or standards.
Run DRC frequently during layout. Fix violations incrementally rather than at the end.
Confirm your design rules match your chosen PCB manufacturer’s capabilities before finalizing the design.

Advanced Features

Length Matching

Ensure equal trace lengths for timing-critical nets:
// Tested by: drc_test_provider_matched_length.cpp
rule "DDR length matching"
  (condition "A.NetClass == 'DDR'")
  (constraint length (min "50mm") (max "52mm"))
  (constraint skew (max "1mm"))  # Maximum length difference

Creepage and Clearance

For high-voltage designs:
// Tested by: drc_test_provider_creepage.cpp  
rule "mains creepage"
  (condition "A.NetClass == 'Mains' || B.NetClass == 'Mains'")
  (constraint creepage (min "3mm"))  # Surface path distance

Via Restrictions

Control via placement:
rule "no vias under BGA"
  (condition "B.Reference == 'U1'")
  (constraint disallow via)

Source Code References

// Main DRC engine
// Location: source/pcbnew/drc/drc_engine.h:131
class DRC_ENGINE : public UNITS_PROVIDER

Next Steps

PCB Layout

Apply design rules during routing

Manufacturing Output

Generate fabrication files

Footprint Libraries

Design footprints meeting rules

Build docs developers (and LLMs) love