---
tag: m0420
title: Bed Leveling State
brief: Set/report bed leveling state and parameters
author: thinkyhead
contrib: sustmi, shitcreek, ellensp

group: motion
requires: AUTO_BED_LEVELING_*|MESH_BED_LEVELING
eeprom: true

codes: [ M420 ]
related: [ G29, M421 ]

notes: |
  - The "current position" may change in response to `M420 Sn`.
  - By default `G28` disables bed leveling. Follow with `M420 S` to turn leveling on.
      - With `ENABLE_LEVELING_AFTER_G28` leveling will always be enabled after `G28`.
      - With `RESTORE_LEVELING_AFTER_G28` leveling is restored to whatever state it was in before `G28`.
  - For multi-axis machines (`I_DRIVER_TYPE` defined) without implementation of inverse kinematics, bed leveling produces wrong results while the toolhead is not oriented vertical and perpendicular to the bed and must be turned off with `M420 S0`.
  - Remaining nuance (advanced): If firmware is built with `M420_C_USE_MEAN` in M420 source, `C` centering uses arithmetic mean instead of midpoint math.

parameters:

- tag: L
  optional: true
  requires: AUTO_BED_LEVELING_UBL, EEPROM_SETTINGS
  description: |
    Load a UBL mesh from EEPROM slot.
    - If no slot is given, the current UBL storage slot is used.
  values:
  - type: int

- tag: S
  optional: true
  description: |
    Set leveling enabled or disabled.
    - A valid mesh is required to enable leveling.
    - With `MARLIN_DEV_MODE`, `S2` creates a simple random mesh and enables leveling.
  values:
  - type: bool

- tag: V
  optional: true
  description: 'Verbose: Print the stored mesh / matrix data'
  values:
  - type: bool

- tag: T
  optional: true
  requires: AUTO_BED_LEVELING_UBL
  description: Format for UBL mesh map output (used with `L` and/or `V`)
  values:
  - tag: 0
    description: Human readable
  - tag: 1
    description: CSV
  - tag: 2
    description: LCD
  - tag: 4
    description: Compact

- tag: Z
  optional: true
  requires: ENABLE_LEVELING_FADE_HEIGHT
  description: |
    Set Z fade height
    - With Fade enabled, bed leveling correction is gradually reduced as the nozzle gets closer to the Fade height. Above the Fade height no bed leveling compensation is applied at all, so movement is machine true.
    - Set to 0 to disable fade, and leveling compensation will be fully applied to all layers of the print.
  values:
  - type: float
    tag: linear

- tag: C
  optional: true
  requires: HAS_MESH
  description: |
    - Re-center the all mesh Z values, then subtract the given negative offset (default 0).
       - UBL: Center on the Mean Average (sum / count).
       - Others: Center on the Midrange ((highest - lowest) / 2).
    - Works only with a valid mesh.
  values:
  - type: float
  - tag: negative_offset

examples:
- pre: Report current leveling state
  code: M420
- pre: Enable leveling
  code: M420 S1
- pre: Disable leveling
  code: M420 S0
- pre: Set fade height to 10mm
  code: M420 Z10
- pre: Re-center mesh values (C defaults to 0)
  code: M420 C
- pre: Re-center mesh values and apply an additional offset
  code: M420 C0.05
- pre: Load UBL mesh slot 0 and show it in compact format
  code: M420 L0 V T4
- pre: Show UBL mesh in LCD-style format
  code: M420 V T2

---

Set/report the Bed Leveling state and Mesh values, when applicable.

With `AUTO_BED_LEVELING_UBL` you can load and save a mesh from EEPROM and set mesh report format.

With mesh-based leveling you can set a Fade Height to gradually reduce bed leveling correction to zero, so the remaining print job is free of bed leveling compensation artifacts.
