How To Keep Leading Zeros In Excel (2026)
Type 00123 into an Excel cell and it turns into 123.
Excel treats ZIP codes, ID numbers and phone numbers as ordinary numbers, so it drops the leading zeros and shortens long numbers.
This guide shows the four ways Microsoft documents for keeping them, based on its support pages for Excel for Microsoft 365, Excel 2024, 2021 and earlier.
Table of Contents
- Quick answer: pick the method that fits
- Why Excel removes the zeros
- Format the cells as Text first
- Type an apostrophe before the number
- Use a custom number format for codes
- Restore zeros with the TEXT function
- Keep zeros when importing a file
- Long numbers such as card numbers
- A newer setting in Microsoft 365 and Excel 2024
- What to expect from text numbers
- Related Excel guides
- Sources
- More Word, Excel and PowerPoint guides
Quick answer: pick the method that fits
| Situation | Best method |
|---|---|
| Typing a few codes by hand | Type an apostrophe first, such as '00123 |
| A whole column to fill in | Format the cells as Text before typing |
| Codes under 16 digits that should stay numbers | Custom number format such as 00000 |
| Zeros already lost in a column | =TEXT(A1,”00000″) in a new column |
| Importing a CSV or text file | Convert the column to Text in Power Query |
Why Excel removes the zeros
Excel reads digits as a number, and a number has no use for a leading zero.
Excel also keeps only 15 significant digits, so in a number with 16 or more digits, such as a credit card number, every digit after the 15th is rounded down to zero.
Microsoft notes that long numbers can also switch to scientific notation, such as 1.23E+15.
Format the cells as Text first
This is the simplest fix for a column you are about to fill in.
- Select the cells.
- On the Home tab, in the Number group, open the Number Format list.
- Choose Text, scrolling to the bottom of the list if you do not see it.
- Type your numbers.
You can format empty cells this way, and numbers typed into them afterward are stored as text.
Microsoft also gives a shortcut: select the cells, press Ctrl+1, open the Number tab and choose Text.
Formatting only affects numbers entered after you apply it, so it does not bring back zeros that are already gone.
Type an apostrophe before the number
For a one-off entry, type an apostrophe before the digits.
- Click the cell.
- Type ' and then the number, for example '00123.
- Press Enter.
Microsoft says the apostrophe makes Excel treat the entry as text.
Use a custom number format for codes
A custom format keeps the value numeric but shows a fixed number of digits, and it works for codes under 16 digits.
- Select the cells and press Ctrl+1.
- Open the Number tab and choose Custom.
- In the Type box, enter a pattern made of zeros.
- Click OK.
| Data | Pattern Microsoft gives |
|---|---|
| Postal code | 00000 |
| Social Security number | 000-00-0000 |
| Phone number | 00-0-000-000-0000 |
| Any code, 10 characters | 0000000000 |
The Special category inside Format Cells also has built-in options for ZIP code, ZIP code + 4, phone number and Social Security number.
As with the Text format, a custom format does not restore zeros that were already removed.
Restore zeros with the TEXT function
If the zeros are already gone, rebuild them in a spare column.
- In an empty column next to your data, enter =TEXT(A1,”00000″).
- Change the number of zeros so it matches the total length you want.
- Copy the formula down the column.
Microsoft’s examples include =TEXT(A1,”000-00-0000″) for Social Security numbers, and a code of “0000000” turns 1234 into 0001234.
Keep in mind that TEXT returns text, which can get in the way of later calculations, so Microsoft suggests keeping the original value in one cell and TEXT in another.
To turn a TEXT result back into a number, Microsoft says to multiply it by 1 or use the double-unary operator (—).
Keep zeros when importing a file
For a CSV or other text file, Microsoft’s method is to convert the column to Text while importing through Power Query.
- Go to Data > From Text/CSV and load your file.
- Select Edit to open the Query Editor.
- Select the column, then go to Home > Transform > Data Type > Text.
- In the Change Column Type box, choose Replace Current.
- Select Close & Load.
You can Ctrl+click several columns to convert them together, and Data > Refresh applies the same steps again to updated files.
Long numbers such as card numbers
Because of the 15-digit limit, a custom format cannot save a number with 16 or more digits.
Microsoft says to store these as text instead, using either the Text format or the apostrophe before you type.
A newer setting in Microsoft 365 and Excel 2024
Microsoft lists Automatic Data Conversions, available only in Microsoft 365 and Excel 2024 versions, as a way to change how Excel handles leading zeros, 15-digit truncation, numbers containing “E” and letter-and-number strings that turn into dates.
Microsoft’s page does not spell out the menu path here, so check your version’s Options if you want that control.
What to expect from text numbers
Text-formatted numbers are left-aligned, which makes them easy to spot.
Microsoft warns that numbers stored as text can cause calculation errors and odd sort orders, so convert them back when you need to calculate.
Our guide to converting numbers stored as text covers that step.
Related Excel guides
You may also want how to split text into columns and how to combine text from two cells.
Sources
Steps come from Microsoft Support: Keeping leading zeros and large numbers, Format numbers as text and TEXT function.
More Word, Excel and PowerPoint guides
- How To Save Word And Excel Files To Your PC By Default (2026)
- How To Show The Formula Bar And Gridlines In Excel (2026)
- How To Fix Excel Arrow Keys Scrolling The Sheet (2026)
- How To Fix Excel Column Headings Showing Numbers (2026)
- Excel Error: There Isn't Enough Memory To Complete This Action
- How To Wrap Text And Merge Cells In Excel (2026)