How to Add Leading Zeros in Excel (Step-by-Step)
In this article
To keep leading zeros in Excel, the simplest method is to format the cells as text before typing the numbers, or use the TEXT function to convert existing numbers. Excel automatically strips leading zeros because it treats numeric entries as numbers, so you need to tell it to treat the entry as text or apply a custom number format.
What You'll Need
- Microsoft Excel (desktop or web version)
- A column or range of cells where you want to preserve leading zeros
- Your data: either numbers you'll type manually or existing values you want to reformat
Step-by-Step
Method 1: Format Cells as Text (Best for Manual Entry)
- Select the cell or range of cells where you'll type the numbers.
- Right-click the selection and choose Format Cells (or press Ctrl+1 on Windows, Cmd+1 on Mac).
- In the Format Cells dialog, go to the Number tab.
- Under Category, select Text.
- Click OK.
- Now type your numbers with leading zeros (e.g.,
00123). Excel will keep them exactly as typed.
Note: If you already typed the numbers before formatting, you'll need to re-enter them or use a different method (see Method 3).
Method 2: Custom Number Format (Keeps Data Numeric)
- Select the cells that contain the numbers you want to display with leading zeros.
- Right-click and choose Format Cells (or press Ctrl+1).
- Go to the Number tab and select Custom under Category.
- In the Type box, enter a format code using zeros. For example:
00000– always shows 5 digits (e.g., 123 becomes 00123)000– always shows 3 digits0000– always shows 4 digits
- Click OK. The numbers will now display with leading zeros, but the underlying value remains numeric (e.g., 00123 is stored as 123).
Important: This method only changes the display; the actual cell value stays a number. If you later use the cell in a calculation, it will treat it as the number without zeros.
Method 3: Use the TEXT Function (For Converting Existing Data)
- In a new column next to your data, click the first cell where you want the converted value.
- Type a formula like:
=TEXT(A1, "00000")– replace A1 with the actual cell reference and adjust the number of zeros to your desired length. - Press Enter. The cell now shows the number with leading zeros as text.
- Drag the fill handle down to apply the formula to the rest of the column.
- If you want to replace the original data with the text version, copy the new column, then use Paste Special > Values over the original cells.
Method 4: Use the Apostrophe (Quick Manual Entry)
- Before typing the number, type an apostrophe (
') – for example,'00123. - Press Enter. The apostrophe won't show, but the cell will be treated as text and the leading zeros will stay.
This is handy for a few entries, but not practical for large datasets.
Common Mistakes
- Formatting after typing: If you type numbers first and then apply Text format, Excel doesn't retroactively add zeros. You must re-enter the data or use the TEXT function.
- Using a number format with fewer zeros than needed: If you use
00but your data has 5 digits, the extra digits will show, but if you have a 1-digit number, it will show as 01, not 001. Match the number of zeros to your maximum needed length. - Confusing display with value: Custom formats only change appearance. If you copy the cell and paste it elsewhere, the zeros may disappear unless you paste as values.
- Importing from CSV: When opening a CSV file, Excel may strip leading zeros. To avoid this, use the Text Import Wizard and set the column data format to Text.
Tips
- For ZIP codes, product codes, or IDs, always use Text format or a custom format with the exact number of digits you need.
- If you need to combine text with numbers (e.g., "ID-00123"), use a formula like
="ID-"&TEXT(A1,"00000"). - To quickly apply a text format to an entire column, select the column header, then format.
- When using custom formats, you can also include dashes or spaces, e.g.,
000-00-0000for Social Security numbers. - Use the
LENfunction to check if your numbers are the correct length after formatting.
Troubleshooting
Leading zeros still disappear after formatting?
- Check if the cell is actually formatted as Text. Select the cell and look at the Number Format box on the Home tab – it should say "Text".
- If you used a custom format, make sure you didn't accidentally use a general format like
0instead of000. - If you're entering data from a formula, the result might be numeric. Wrap it with TEXT.
Numbers show as #####?
- This usually means the column is too narrow. Widen the column or change the format to Text.
CSV import strips zeros?
- Use the Data tab > From Text/CSV to import, and in the preview, select the column and choose "Text" as the data type.
Formulas don't see the zeros?
- If you used a custom number format, the underlying value is still numeric. If you need the zeros to be part of the value, use the TEXT function or format as Text.
Frequently Asked Questions
Why does Excel remove leading zeros?
Excel treats numbers as numeric values, and numerically, leading zeros are insignificant. So it drops them by default.
Can I add leading zeros to existing numbers without a formula?
Yes, you can use a custom number format like 00000 – it will display zeros without changing the underlying data. For a permanent text value, you'd need to use the TEXT function or re-enter.
How do I add a fixed number of zeros to the left of a number?
Use a custom format with the desired number of zeros, e.g., 0000 for 4 digits. Or use =TEXT(A1,REPT("0",5)) for 5 digits.
Does the apostrophe method work for all versions of Excel?
Yes, the apostrophe trick works in all desktop versions and in Excel for the web.
Can I use leading zeros in Excel formulas like CONCATENATE?
Yes, if the cell is formatted as text or you use the TEXT function, the zeros will be included in the concatenation.
How do I keep leading zeros when saving as CSV?
If you save a file with Text-formatted cells as CSV, the zeros will be preserved because Excel writes the text as-is. However, when reopening the CSV, you'll need to import it as text again.