Excel 0 in Front of Number: 5 Ways to Keep Leading Zeros
Why Excel drops the 0 in front of a number and how to keep it: apostrophes, Text format, custom formats, the TEXT function, import settings and Excel's new option.
To keep a 0 in front of a number in Excel, either type an apostrophe first ('0123) or format the cells as Text before you type, so Excel stores the entry as text instead of a number. If the zeros are already gone, apply a custom number format such as 00000 or use =TEXT(A2,"00000") to add them back.
The right choice depends on whether you still need to do math with the value and whether you’re typing data by hand or importing it. The rest of this guide walks through each option and when to use it.
Why Excel drops the leading zero
Excel’s default General format treats anything that looks like a number as a number. Numerically, 00123 and 123 are the same value, so Excel throws the zeros away. Microsoft’s own support article, Keeping leading zeros and large numbers, explains that Excel automatically removes leading zeros and converts large numbers to scientific notation (like 1.23E+15) so that formulas and math work on them.
That’s helpful for prices and quantities, but wrong for identifiers: ZIP and postal codes, phone numbers, employee IDs, SKUs and account numbers. Those are labels that happen to contain digits, and they should usually be stored as text.
Quick comparison of the methods
| Method | Stored as | Math still works? | Best for |
|---|---|---|---|
Apostrophe ('0123) | Text | No | A few cells typed by hand |
| Format cells as Text first | Text | No | Columns of codes you’ll type in |
Custom number format (00000) | Number | Yes | Fixed-length numbers you still calculate with |
TEXT function | Text | No | Fixing data that already lost its zeros |
| Import column as Text / conversion setting | Text | No | CSV and other imported files |
Method 1: Type an apostrophe first
For a one-off entry, type an apostrophe before the number, for example '01234. Excel treats the entry as text and keeps the zero. The apostrophe doesn’t show in the cell itself, only in the formula bar.
Excel may flag the cell with a small green triangle warning that it’s a “number stored as text.” For codes, that’s expected and you can ignore it.
Method 2: Format the cells as Text before typing
If you’re about to enter a whole column of codes, set the format first:
- Select the cells or the whole column.
- On the Home tab, open the Number Format drop-down (it usually says General).
- Choose Text.
- Type your values. Leading zeros will stay.
The order matters. As Microsoft notes, applying Text format after the zeros were removed won’t restore them, because the zeros were never stored. For existing data, use Method 3 or Method 4.
Method 3: Use a custom number format
A custom format changes how a number is displayed without changing the value. This is the option to use when every value should be the same length and you still want it to behave as a number.
- Select the cells.
- Press Ctrl+1 (or right-click and choose Format Cells).
- On the Number tab, pick Custom.
- In the Type box, enter one zero per digit you want. For a five-digit ZIP code, type
00000. - Click OK.
Now 123 displays as 00123, while the cell still holds the number 123. That also means the zeros won’t carry over if you copy the value into another program as raw data or export it in some formats, because they’re only part of the display. Excel also has a built-in Special > Zip Code format that does the same job for US ZIP codes.
To undo it, set the format back to General.
Method 4: Add zeros with the TEXT function
When the zeros are already gone, or you need a real text value with zeros for an export or a lookup, use a formula. Microsoft’s TEXT function page notes it can be used to add back leading zeros that Excel removed.
- In an empty column next to your data, enter
=TEXT(A2,"00000"). - Fill the formula down.
- The number of zeros in the format code sets the total length.
=TEXT(A2,"0000000")turns1234into0001234. - If you want to replace the original column, copy the results and use Paste Special > Values, then delete the helper formulas.
The result of TEXT is always a text string, even though it looks like a number. Microsoft’s Format numbers as text article covers the same approach for converting numbers into text in a specific format.
Method 5: Keep zeros when importing CSV and text files
Double-clicking a CSV file opens it with default conversions, which is where many leading zeros get lost. There are two official ways around it.
Import the column as Text with Power Query
Microsoft recommends using Get & Transform (Power Query) to set individual columns to text when you import data:
- Go to Data > From Text/CSV and choose your file.
- In the preview, click Transform Data to open the Power Query Editor.
- Click the header of the column that holds codes.
- Go to Home > Transform > Data Type and choose Text. If asked, replace the existing conversion step.
- Click Close & Load.
The data type step is saved with the query, so when the source file changes you can use Data > Refresh and the zeros will be kept.
Turn off “Remove leading zeros” in Excel’s settings
Newer versions of Excel let you switch off the automatic conversion itself. According to Microsoft’s Set automatic data conversions page:
- Windows: go to File > Options > Data and find Automatic Data Conversion.
- Mac: go to Excel > Preferences > Edit and find Automatic Data Conversion.
- Clear Remove leading zeros and convert to number.
With that box cleared, Excel stores numeric entries that have leading zeros as text and keeps the zeros. A few caveats from the same documentation and other reporting:
- The setting affects new entries and imports, not cells that were already converted.
- It doesn’t directly control Power Query imports, which use their own data type settings.
- Not every version has it. If you don’t see the section in your options, your version doesn’t support it, and you’ll need one of the other methods. Availability may change as Microsoft updates Excel, so check your own Options as of November 2026.
A note on long numbers
Long identifiers such as credit card or account numbers raise a second problem: Excel shows large numbers in scientific notation, and it only keeps about 15 significant digits for numbers. Microsoft’s older guidance says custom or text formats work for codes of fewer than 16 digits. For anything longer, store the value as text from the start (apostrophe, Text format, or a Text column in Power Query) so no digits are lost. Changing the format afterwards won’t recover digits Excel has already rounded off.
Which method should you use?
- Typing a handful of codes: apostrophe.
- Building a column of IDs or ZIP codes: format as Text first.
- Numbers that must stay numeric but look padded: custom format like
00000. - Data that already lost its zeros:
TEXTfunction, then paste as values. - Regular CSV imports: Power Query with the column set to Text, plus the Automatic Data Conversion setting if your version has it.
Free apps worth trying
SponsoredSponsored links. Installing through them can earn us a commission, at no cost to you. Apps are free to download; some offer optional in-app purchases.
Frequently asked questions
Why does Excel remove the 0 in front of my number? +
When you type something that looks like a number into a cell with the General format, Excel stores it as a number, and numbers have no leading zeros. Excel does this so the value can be used in calculations, which is the wrong behavior for codes such as ZIP codes, phone numbers or product IDs.
Can I get back leading zeros that Excel already removed? +
Changing the cell to Text format afterwards will not bring them back, because the zeros were never stored. Use a custom number format such as 00000 to display them again, or a formula like =TEXT(A2,"00000") to create a text version with the zeros added.
Will a number with leading zeros still work in formulas? +
It depends on the method. A custom number format keeps the value as a real number, so math still works. An apostrophe, the Text format and the TEXT function all produce text, which is fine for lookups and labels but not for arithmetic.
How do I stop leading zeros disappearing when I open a CSV file? +
Import the file through Data > From Text/CSV (Power Query) and set the affected column's data type to Text before loading, instead of double-clicking the CSV. In current Microsoft 365 versions you can also clear the 'Remove leading zeros and convert to number' option under Automatic Data Conversion.
Sources
- Keeping leading zeros and large numbers (Microsoft Support) (support.microsoft.com)
- Set automatic data conversions (Microsoft Support) (support.microsoft.com)
- TEXT function (Microsoft Support) (support.microsoft.com)
- Format numbers as text (Microsoft Support) (support.microsoft.com)
- Enter numbers starting with zero in Excel (Office Watch) (office-watch.com)
- How to actually prevent Excel automatically removing leading zeros (Business Tech Planet) (businesstechplanet.com)