Add Leading Zeros in Excel (5 Ways)

Excel drops leading zeros from numbers, so 00125 becomes 125. To keep or add them for IDs, PIN codes or invoice numbers, use a number format, the TEXT function, REPT for text, or Power Query.

Display onlyCustom format 00000
As textTEXT or REPT
TypingStart with an apostrophe: ‘00125

1. Custom number format (keeps the number)

Select the cells → Ctrl + 1 → Custom → type one 0 per digit, such as 0000000000 for 10 digits.

Custom number format with ten zeros
Numbers displayed with leading zeros

The cell still holds the number, so it sums and sorts normally. The zeros are only shown, and may be lost when saved as CSV.

2. TEXT function (zeros become part of the value)

=TEXT(A1,"0000000000")
TEXT function padding numbers to ten digits

Or set the length with REPT: =TEXT(A1,REPT("0",10)). The result is text, so the zeros survive copying, CSV export and mail merge.

TEXT with REPT padding numbers

3. REPT for text and numbers

TEXT only works on numbers. For codes that contain letters, add the missing zeros in front:

=REPT("0",10-LEN(A1))&A1
REPT padding text and numbers to ten characters

Any character works: =REPT("#",5-LEN(A1))&A1 pads with #. If the value is already longer than 10 characters, wrap it as MAX(0,10-LEN(A1)) to avoid an error.

REPT padding with hash signs

4. Power Query

Add Column → Custom Column with:

Text.PadStart(Text.From([#"Text/Number"]),10,"0")

Text.From turns numbers into text first, so the same formula works for any column.

Power Query Text.PadStart adding leading zeros

5. Keep zeros while typing

  • Type an apostrophe first: '00125. The apostrophe doesn’t show.
  • Or format the cells as Text before typing.
  • When importing CSV files, set the column to Text in Power Query, or use the CSV to Excel converter, which keeps leading zeros.

Related