Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

How to Put Zero Before a Number in Excel

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Excel strips leading zeros because it treats any entry that looks like a number as a number, and 007 is just 7 to a spreadsheet. To keep the zero, you have to tell Excel the entry is text, apply a custom number format, or use a formula that rebuilds the string. The quickest fix is to type an apostrophe before the value (') — Excel then stores it as text and displays the zero. For whole columns of codes, a custom format like 00000 is cleaner because the cells still behave as numbers. The steps below cover both, plus the formula route and the import route.

What You'll Need

  • Excel on Windows, Mac, or the web (the ribbon labels below are for the desktop app; the web version has the same commands under slightly different grouping).
  • The column of numbers or codes you want to pad.
  • No add-ins required — everything here uses built-in features.

Step-by-Step

Method 1: Type an apostrophe (fastest for a few cells)

  1. Click the cell where you want the zero to appear.
  2. Type an apostrophe first, then the value: '007.
  3. Press Enter. Excel displays 007 and stores the cell as text. The apostrophe itself is not shown.
  4. Repeat for each cell, or copy the cell down if the rest of the column needs the same treatment.

This is the right choice for postal codes, employee IDs, and phone extensions that should never be used in arithmetic. The downside is that text values sort and calculate differently from numbers, so do not use this method on a column you plan to sum.

Method 2: Custom number format (best for a whole column)

  1. Select the cells, or click the column letter to select the whole column.
  2. Press Ctrl+1 (Windows) or Cmd+1 (Mac) to open Format Cells. You can also right-click and choose Format Cells.
  3. On the Number tab, choose Custom at the bottom of the category list.
  4. In the Type box, enter a zero for each digit you want to display. For a five-digit code, type 00000. For a three-digit code, type 000.
  5. Click OK. Every value in the selection now shows leading zeros, but the underlying value is unchanged — 7 still calculates as 7.

This is the method to use for part numbers, invoice numbers, and account codes that need to look right but may still be compared or sorted. If a value is longer than the format, Excel shows it in full rather than truncating it.

Method 3: TEXT formula (when you need a new text column)

  1. In an empty column next to your data, click the first cell.
  2. Enter =TEXT(A2,"00000"), replacing A2 with your first source cell and 00000 with the number of digits you need.
  3. Press Enter, then drag the fill handle down to apply the formula to the rest of the column.
  4. If you want to replace the original values, copy the formula column, then paste it back over the original using Paste Special > Values. This removes the formulas and leaves plain text.

The TEXT function returns text, so the result cannot be summed. It is the cleanest option when you are exporting a file to another system that expects fixed-width codes.

Method 4: Keep zeros during import (CSV and text files)

  1. Open the file with Data > From Text/CSV rather than double-clicking it, so the import wizard runs.
  2. In the preview, click Transform Data to open Power Query.
  3. Select the column that is losing its zeros and set its data type to Text.
  4. Click Close & Load. The zeros are preserved because Excel never converts the column to numbers.

If you double-click a CSV, Excel converts anything that looks numeric on open, and the zeros are gone before you can stop it. Always use the import path for files with ID columns.

Method 5: Format as Text before typing

  1. Select the cells or column.
  2. Press Ctrl+1 and choose Text on the Number tab, then click OK.
  3. Now type 007 and press Enter. Excel keeps the leading zero because the cell is already text.

Set the format first — changing it after the value is entered does not bring the zero back, because the zero was already discarded.

Common Mistakes

  • Formatting after typing. If you type 007 into a General cell, Excel stores 7. Applying Text format afterwards shows 7, not 007. Set the format first or re-enter the value.
  • Using Text format on a column you need to calculate. Text values are ignored by SUM and produce #VALUE! errors in arithmetic. Use a custom number format instead if the column must still add up.
  • Assuming the zeros are gone. A custom format only changes display. If you copy the cell to another program, the underlying 7 may be what gets pasted. Use Paste Special > Values only after converting with TEXT if the receiving system needs the zeros.
  • Double-clicking a CSV. This is the most common way leading zeros disappear in bulk. Use the import wizard.
  • Typing a space instead of an apostrophe. A leading space is invisible but breaks lookups and sorting. Use the apostrophe or a proper format.

Tips

  • Use the custom format 00000 for a fixed-width code and 0#### for a variable-length code that should show at least one digit.
  • The apostrophe method is fine for a handful of cells; for a whole column, custom format or TEXT scales better.
  • If you need both display and calculation, keep the number in one column and the padded text in another, then hide the helper column.
  • For phone numbers, a custom format like 000-000-0000 keeps the grouping readable without converting to text.
  • When pasting data from another system, use Paste Special > Text or paste into a pre-formatted Text column to stop Excel reinterpreting the values.

Troubleshooting

  • The zero still disappears after formatting. The value was probably entered before the format was applied. Re-type it, or use the TEXT formula to rebuild it.
  • Custom format shows more zeros than expected. The format string has more digits than the value needs. Reduce the number of zeros in the Type box.
  • The column shows a green triangle warning. Excel is flagging numbers stored as text. That is expected with the apostrophe and Text methods. You can ignore it, or use the custom format method to avoid the warning entirely.
  • Sorting puts 10 before 2. Text values sort alphabetically. If order matters, use a custom number format so the cells remain numeric.
  • Zeros vanish again after saving as CSV. CSV stores the display value, but some systems re-read it as a number. If the receiving system needs text, check its import settings or use a fixed-width export.

Frequently Asked Questions

Why does Excel remove leading zeros?

Excel treats any entry that looks like a number as a number, and leading zeros have no numeric value, so they are dropped. You have to force text or apply a format to keep them.

Does the apostrophe show up in the cell?

No. The apostrophe is a prefix that tells Excel to treat the entry as text; it is not displayed and is not part of the value.

Can I keep the zeros and still use the numbers in formulas?

Yes, with a custom number format such as 00000. The cell displays five digits but the stored value stays numeric, so SUM and other functions work normally.

What is the fastest way to fix a whole column of IDs?

Select the column, open Format Cells with Ctrl+1, choose Custom, and enter one zero per digit you need. That fixes every cell at once without re-typing.

Why did my CSV lose its zeros when I opened it?

Double-clicking a CSV lets Excel convert numeric-looking text on open. Use Data > From Text/CSV and set the column type to Text during import instead.

Do these methods work in Excel for the web?

The apostrophe, Text format, and custom format methods all work in Excel for the web. The import wizard is more limited there, so for large CSV files the desktop app is the safer choice.