Spreadsheet Practice

How to add leading zeros to numbers in Excel

Formula (Excel and Google Sheets)

=TEXT(A2,"00000")

Format the number as text with a fixed number of digits: =TEXT(A2,"00000").

Result on the example
one result per row in B2, filled down to B6
Works in
Every current version
Google Sheets
Same formula

See it work

The formula is already in B2, filled down to B6. Change any input and the result updates, or edit the formula to experiment.

How it works

Spreadsheets drop leading zeros from numbers because 02134 and 2134 are the same number. TEXT with the pattern "00000" pads it to five digits; each 0 in the pattern is a digit that is always shown.

=TEXT(A2,"00000")

Result"02134"

  1. A22134

    The value in A2.

  2. TEXT(A2,"00000")"02134"

    TEXT: Formats a number or date as text, e.g. "mmm" or "$#,##0".

    • valueA22134
    • format_text"00000"

In Google Sheets

The same formula works in Google Sheets: =TEXT(A2,"00000"). We ran it in Google Sheets mode on the same data and it returns the same results.

Other ways to do it

Each one was run on the same example sheet.

FormulaResultWhen to use it
=RIGHT("00000"&A2,5)02134, 10001, 06510…Pads by joining zeros in front and keeping the last five characters.

Common mistakes

  • The result is text, which is right for IDs and ZIP codes but won't add up in a SUM.
  • To keep the value as a number and only change how it looks, use a custom number format 00000 on the cell.
  • For codes that must keep their zeros, format the column as Text before typing or importing.

Try it yourself

Same data, empty answer cell. Your formula is graded instantly, then re-checked on changed data, so a typed-in number won't pass.

Add leading zeros to numbers

In B2, show the ZIP code with leading zeros so it always has five digits, and fill down to B6.

Questions

How do I pad to a variable length?

Use REPT: =REPT("0",8-LEN(A2))&A2 pads to 8 characters.

How do I remove leading zeros?

Convert to a number: =VALUE(A2).

Checked by running on 2026-10-29: every formula and result on this page was calculated by the Spreadsheet Practice formula engine, in both Excel and Google Sheets modes.