How to Add Leading Zeros in Excel

How-to basics · Updated November 27, 2026

Adding leading zeros in Excel is a common need when working with ZIP codes, employee IDs, product codes, or any data that must maintain a fixed number of digits. The simplest way is to format the cells as text before typing, but for existing numbers you can use the TEXT function. This guide covers all reliable methods, including custom formatting, the TEXT function, and the newer BASE function, with step-by-step instructions for Microsoft 365 on Windows (noting Mac differences where relevant).

What You’ll Need

  • Microsoft Excel 2016 or later (the BASE function requires Excel 2013 or later; TEXT works in all versions).
  • A column of numbers you want to convert, or cells where you’ll type new values.
  • If you plan to use a formula, a destination column for the results.

Step-by-Step

Method 1: Custom Number Format (best for display only)

  1. Select the cells or range containing your numbers.
  2. Press Ctrl+1 (Windows) or Cmd+1 (Mac) to open the Format Cells dialog.
  3. Go to the Number tab, then select Custom in the Category list.
  4. In the Type box, delete the existing text and type the desired number of zeros. For example, type 00000 to force 5 digits. If you need a prefix like a letter, use quotes: "ID-"0000.
  5. Click OK. The numbers now display with leading zeros, but the underlying value remains a number. This method is ideal for visual formatting without changing data.

Method 2: TEXT Function (converts to text)

  1. In a new column, click the first empty cell (e.g., B2).
  2. Type the formula: =TEXT(A2,"00000") – replace A2 with your actual cell and 00000 with the number of digits you want.
  3. Press Enter. The result appears as text with leading zeros.
  4. Drag the fill handle down to apply to the rest of the column.
  5. If you want to replace the original data, copy the formula column, then use Paste Special > Values over the original cells, and delete the temporary column.

Method 3: Text format before typing

  1. Select the cells where you’ll enter data.
  2. Go to the Home tab, in the Number group, click the arrow next to the Number Format box.
  3. Choose Text from the dropdown.
  4. Now type your numbers – leading zeros will be preserved automatically. Note: this only works for data you type after the format is applied; existing numbers won’t change.

Method 4: BASE function (for numbers up to 2^53)

  1. In a new cell, type =BASE(A2,10,5) where A2 is the number and 5 is the total length. The second argument 10 means decimal.
  2. Press Enter. Excel returns the number as text with leading zeros.
  3. Copy down as needed. This function works in Excel 2013 and later.

Method 5: Power Query (for large datasets)

  1. Select your data range and go to Data > From Table/Range (if your data isn’t a table, Excel will prompt you to create one).
  2. In Power Query Editor, select the column(s) with numbers.
  3. Go to Add Column > Custom Column.
  4. Enter a formula like Text.PadStart(Text.From([ColumnName]), 5, "0") – replace ColumnName with your actual column name and 5 with the desired length.
  5. Click OK, then Close & Load to bring the result back to Excel.

Common Mistakes

  • Using a number format after data is entered – If you apply a custom format to existing numbers, it works, but if you apply the Text format, it won’t change existing numbers.
  • Forgetting that TEXT returns text – This can break calculations like SUM or VLOOKUP. Use it only when you need text output.
  • Not enough zeros – If your number has more digits than the zeros you specify, Excel will show the full number without truncating, which may not be what you want. For example, TEXT(123456,"000") returns “123456” not “000123”.
  • Apostrophe trick – Typing an apostrophe before a number (e.g., ‘00123) forces text, but it’s easy to forget and it clutters the cell with a hidden character.

Tips

  • To add a fixed number of zeros to a varying-length number, use the REPT function: =REPT("0",5-LEN(A2))&A2 – this pads to 5 digits.
  • If you need to combine leading zeros with a delimiter like a dash, use =TEXT(A2,"000-00") for formats like 001-23.
  • For ZIP codes, remember that the US Postal Service uses 5-digit ZIP codes, but extended ZIP+4 uses 9 digits. Use 00000 or 00000-0000 accordingly.
  • When importing data from CSV files, Excel often strips leading zeros. Use the Text Import Wizard and set the column format to Text to prevent this.
  • If you need to keep the original numbers but display zeros, the custom format method is best because it doesn’t alter the underlying data.

Troubleshooting

My zeros don’t show up after applying a custom format. Make sure you selected Custom, not Text. Also check that the number of zeros matches or exceeds the number of digits in your data. If your number is 123 and you use “0000”, it shows 0123. If you use “00”, it shows 123 because the format just adds zeros only when needed.

The TEXT function returns a #VALUE! error. This usually means the cell reference is not a number. Check that the cell contains a numeric value, not text. If it’s text that looks like a number, convert it to a number first using =VALUE(A2).

Leading zeros disappear when I sort or filter. This happens when the cells are formatted as General. Apply a custom format or convert to text before sorting. If you sort after converting to text, the sort order may be lexicographic (e.g., 10 before 2) – be aware.

I used the apostrophe method, but the apostrophe shows in the cell. The apostrophe is a hidden character; it doesn’t display. If you see it, you might have typed a regular apostrophe in the cell. Delete it and retype the number with a leading apostrophe (e.g., ‘00123).

My formula column shows zeros but the original column still lacks them. That’s expected – you need to replace the original data with the formula results. Copy the formula column, then use Paste Special > Values over the original cells, then delete the temporary column.

Frequently Asked Questions

Q: How do I add leading zeros to a whole column at once?
A: Use the TEXT function in an adjacent column and drag down, or use Power Query for a large dataset. For a quick fix, you can also select the column, press Ctrl+1, and apply a custom format like 00000.

Q: Can I use leading zeros in calculations?
A: If you use a custom number format, the underlying value remains a number, so calculations work. If you use TEXT or Text format, the result is text and won’t work in arithmetic. Convert back with =VALUE() if needed.

Q: Why does Excel remove leading zeros when I type them?
A: Excel automatically treats numbers as numeric values and strips leading zeros. To prevent this, format the cells as Text before typing, or type an apostrophe before the number.

Q: How do I add leading zeros to a phone number?
A: Phone numbers often need a leading zero for country codes. Use a custom format like 0000000000 for 10 digits, or TEXT formula. For international numbers, consider using a text format to preserve the plus sign and dashes.

Q: What’s the difference between TEXT and BASE functions?
A: TEXT is more flexible and can format numbers with commas, decimals, and custom patterns. BASE is simpler, specifically for padding with zeros, and works with numbers up to 2^53. Both return text.

Q: Can I add leading zeros without changing the data type?
A: Yes, use a custom number format (Method 1). This only changes the display, not the actual cell value, so the data remains numeric.

Related

Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.

More in How-to basics

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.