Excel guide · 4 min read
How to add leading zeros in Excel
=TEXT(A2,"00000"), which turns 2134 into "02134". To keep the cell a number and just display the zeros, select it, press Ctrl+1, choose Custom and type 00000. To type zeros that stick, start the entry with an apostrophe ('02134) or format the cells as Text first.Sample data
Every result on this page was calculated from this sheet by the same spreadsheet engine the Cellwise app uses.
| A | B | C | D | |
|---|---|---|---|---|
| 1 | ZIP (as number) | Employee no. | Code (text) | Customer |
| 2 | 2134 | 42 | 7 | Allston Bike Co |
| 3 | 7030 | 315 | 88 | Hoboken Deli |
| 4 | 501 | 7 | 1204 | Holtsville Print |
| 5 | 94105 | 1088 | 35 | Bay Street Books |
Why Excel removes leading zeros
When you type 02134, Excel sees a number, and as a number 02134 is just 2134. It stores 2134 and the zero is gone. The same happens when you open a CSV file by double-clicking it, which is why ZIP codes from New England and New Jersey arrive as 4 digits and ZIP 00501 shows as 501.
So the real question is whether the value is a quantity or an identifier. ZIP codes, employee numbers, phone numbers and account numbers are identifiers. You never add them up, so storing them as text is fine, and often better.
Option 1: a custom number format (stays a number)
A custom format changes only how the cell looks. The cell still holds 2134, so it sorts and calculates as a number, but it displays as 02134. Each 0 in the format is a digit that is always shown, padded with zeros if needed.
For US ZIP codes, Format Cells > Special > Zip Code applies the same 00000 format for you. Use 000-00-0000 or (000) 000-0000 style codes for other fixed layouts.
- Select the cells.
- Press Ctrl+1 (or right-click > Format Cells).
- On the Number tab, choose Custom.
- In the Type box, enter one 0 per digit, such as 00000 for a 5-digit ZIP.
- Click OK.
Option 2: TEXT in a formula (real zeros, as text)
TEXT applies the same kind of format code inside a formula, and returns the result as text. The zeros are now part of the value, so they survive copying to another program, a mail merge, a CSV export, or joining with other text.
This is the method to use when another system needs the code with zeros, or when you build a longer ID from the number.
Result: 02134
Returns "02134" as text.
Build an ID with a prefix
Joining a number to text drops its formatting, so ="EMP-"&B2 gives EMP-42. Pad it with TEXT inside the join to get a fixed-width ID that sorts properly.
Result: EMP-0007
Returns "EMP-0007".
Pad codes that are already text
TEXT expects a number. Codes that are already text, like the ones in column C, still work because TEXT converts digit-only text, but codes with letters come back unchanged. A method that works on anything: stick zeros on the front and keep the right-most characters.
Put at least as many zeros in the string as the width you want. RIGHT then keeps exactly that many characters from the end.
Result: 00088
Returns "00088".
Typing and importing zeros that stick
To type a few codes by hand, start with an apostrophe: '02134. The apostrophe is not shown or stored in the value, and the cell becomes text. For a whole column you will type into, format it as Text first (Home > Number Format > Text). Formatting after typing does not bring zeros back.
For CSV files, do not double-click them. Use Data > From Text/CSV, click Transform Data, select the column and set Data Type to Text. In recent Excel for Microsoft 365 versions you can also turn off the automatic conversion: File > Options > Data > Automatic data conversion, and clear the option to remove leading zeros.
Common mistakes
Lookups fail after formatting
A cell shown as 02134 by a custom format still holds the number 2134. Looking up the text "02134" will not find it. Make both sides the same type: use TEXT(A2,"00000") on the number side, or VALUE on the text side.
Long numbers lose their last digits
Excel keeps only 15 significant digits, so a 16-digit card or account number has its last digit turned into 0. Store long IDs as text (apostrophe or Text format) before typing or importing.
Saving to CSV and reopening
Excel writes 02134 to the CSV, but double-clicking the file to reopen it strips the zero again. Reopen it with Data > From Text/CSV and set the column to Text.
Trying to SUM TEXT results
TEXT returns text, and SUM ignores it. That is fine for IDs. If you need math, keep the number and use a custom format instead.
FAQ
Why does Excel remove the leading zeros?
Excel turns anything that looks like a number into a number, and numbers have no leading zeros. Format the cells as Text before typing, or show the zeros with a custom format like 00000.
How do I add a zero in front of a number in Excel?
For a fixed width use =TEXT(A2,"00000"). To add exactly one zero regardless of length, use ="0"&A2. Both return text.
How do I keep leading zeros in a ZIP code?
Select the cells, press Ctrl+1 and choose Special > Zip Code, or Custom with 00000. When importing, set the ZIP column to Text so the zeros are never dropped.
How do I remove leading zeros in Excel?
If the value is text, convert it to a number with =VALUE(A2) or --A2. The number drops the zeros automatically.
Functions used
Related guides
- How to convert numbers stored as text in Excel
- How to combine text with numbers and dates in Excel
- VLOOKUP not working: 7 causes and fixes
- How to concatenate with a space in Excel
- How to add days to a date in Excel
- How to calculate percentage in Excel
Updated