ExcelReady
CourseMock testsFunction guidesBlog
Start freeStart learning for free
ExcelReady

Be Excel-ready before day one. Hands-on practice in your browser, with instant feedback.

Learn

  • Course
  • Mock tests
  • Function guides
  • Blog

Test prep

  • Excel level test
  • Excel test practice
  • Free screening quiz
  • Certificate

Company

  • Editorial policy
  • Contact
  • Terms
  • Privacy

© 2026 ExcelReady. All rights reserved.

  1. Blog
  2. Text
  3. How to Add or Keep Leading Zeros in Excel

How to Add or Keep Leading Zeros in Excel

By ExcelReady Team·Updated November 1, 2026·5 min read

The short answer

To add leading zeros in Excel, use =TEXT(A2,"00000"), which pads a number to five digits, so 742 becomes 00742. To keep the cell a number, apply a custom number format of 00000 instead. To type an ID with zeros and keep them, format the cells as Text first or start the entry with an apostrophe, like '00742.

Key takeaways

  • Excel drops leading zeros because it treats 00742 as the number 742.
  • =TEXT(A2,"00000") adds zeros to make five digits, but the result is text.
  • A custom number format of 00000 shows the zeros and keeps the value a real number.
  • For codes you type, format the cells as Text first or start with an apostrophe.
  • =RIGHT("00000"&A2,5) pads codes that are already text.
On this page+
  1. Why does Excel remove leading zeros?
  2. How to add leading zeros with the TEXT function
  3. How to show leading zeros with a custom number format
  4. How to keep leading zeros when you type
  5. How to pad codes that are already text
  6. How to keep leading zeros when opening a CSV file
  7. Practise it

To add leading zeros in Excel, you either turn the number into padded text with =TEXT(A2,"00000") or tell Excel to display zeros with a custom number format. Excel removes the zeros because it reads 00742 as the number 742. This guide shows four ways to add or keep them, and which to use for IDs, ZIP codes and phone numbers.

Why does Excel remove leading zeros?#

Excel removes leading zeros because it treats anything that looks like a number as a number. Mathematically, 00742 and 742 are the same, so Excel stores 742 and throws the zeros away.

That's fine for prices and quantities, but wrong for codes. An employee ID, a product code, a US ZIP code like 02134 or a phone number is really a label made of digits. You never add them up, and the zeros matter.

So the fix is one of two things:

  • Store the value as text, so Excel keeps every character you type.
  • Keep it a number, but use a format that displays the zeros.
MethodResult typeBest for
Apostrophe or Text formatTextTyping new codes by hand
Custom number format 00000NumberFixed-length numbers you still sort or calculate with
=TEXT(A2,"00000")TextConverting existing numbers into padded codes
=RIGHT("00000"&A2,5)TextPadding values that are already text

How to add leading zeros with the TEXT function#

Use TEXT with a format code made of zeros, one for each digit you want. For five-digit IDs:

Excel formula
=TEXT(A2,"00000")

Each 0 in the format code means "show a digit here, or a zero if there isn't one". So:

A2FormulaResult
742=TEXT(A2,"00000")00742
1088=TEXT(A2,"00000")01088
35=TEXT(A2,"00000")00035
20417=TEXT(A2,"00000")20417

A number longer than the format code isn't cut. =TEXT(123456,"00000") returns 123456.

TEXT always returns text. That's what you want when you join the code to other text, such as ="EMP-"&TEXT(A2,"00000") for EMP-00742. It also helps when you need to match these IDs against a list stored as text. The TEXT function guide lists more format codes, and the guide to adding text to the start or end of cells shows more ways to build codes like this.

How to show leading zeros with a custom number format#

A custom number format displays the zeros but keeps the value a real number. To apply one:

  1. Select the cells.
  2. Open Format Cells (Windows: Ctrl+1; Mac: ⌘1).
  3. On the Number tab, choose Custom.
  4. In the Type box, enter 00000 and click OK.

The cell now shows 00742, but the formula bar still shows 742. Sorting, SUM and lookups against other numbers all keep working, because nothing about the value changed.

The catch: the zeros exist only on screen. If you copy the cells into another program or export to CSV, you may get 742 again. And a lookup against text IDs like "00742" won't match a number 742. If the zeros must travel with the data, convert to text with TEXT.

How to keep leading zeros when you type#

Start the entry with an apostrophe, or format the cells as Text before you type. Both tell Excel to keep exactly what you enter.

  • Apostrophe: type '00742. The cell shows 00742 and the apostrophe stays hidden. It only appears in the formula bar.
  • Text format: select the column, choose Home > Number Format > Text, then type. This is better when you'll type many codes.

Formatting a column as Text after typing doesn't bring back the zeros. Excel already stored 742, so you'd have to retype the values.

Excel may show a small green triangle with the warning "Number stored as text". For codes, that's expected. Choose Ignore Error if it bothers you. The comparison of TEXT and VALUE explains when you want text and when you want numbers.

Recent Microsoft 365 versions also have File > Options > Data > Automatic data conversion, where you can turn off removing leading zeros for new data. On a shared file, don't rely on everyone having that setting.

How to pad codes that are already text#

When codes arrive as text of different lengths, join zeros to the front and keep the last few characters:

Excel formula
=RIGHT("00000"&A2,5)

For A2 = 742, the join makes 00000742, and RIGHT keeps the last five characters: 00742. This works whether A2 holds a number or text, and it's handy for mixed data.

Another option is REPT, which repeats a character a set number of times:

Excel formula
=REPT("0",5-LEN(A2))&A2

For 742, 5-LEN(A2) is 2, so it adds two zeros. Be careful: if A2 is already longer than five characters, the count goes negative and REPT returns #VALUE!. The RIGHT version just cuts to five characters instead.

How to keep leading zeros when opening a CSV file#

Import the file instead of opening it, and set the ID column to Text. When you double-click a CSV, Excel converts every number-looking column on its own and the zeros are gone before you see them.

  1. Go to Data > From Text/CSV and pick the file.
  2. In the preview, click Transform Data.
  3. Click the ID column's type icon in the header and choose Text.
  4. Click Close & Load.

The zeros stay because Excel loads the column as text from the start. The same steps help with long card or account numbers, which Excel would otherwise round after 15 digits.

Practise it#

Knowing when a value should be text and when it should be a number is a skill job tests check often. Practise TEXT and VALUE in a live spreadsheet: you type the formulas and get instant feedback. Then see how the same format codes help you combine a date with text, or try the exercise on this page first.

Try it yourself

This is a live spreadsheet. Type the formula in the green cell and press Enter.

Employee IDs must always have five digits. Click B2 and use TEXT to show the number in A2 with leading zeros, so 742 becomes 00742.

fx
ABCD
1
ID
Padded ID
2
742
3
1088
4
35
5
20417
6
9
7
8
9

Tip: The format code needs one 0 for each digit you want: five digits means "00000" in double quotes.

Practise this in a lesson

LessonTEXT and VALUE: numbers to text and backFormat dates and dollar amounts inside sentences with TEXT, and turn digits stored as text into real numbers with VALUE.Function guideTEXTFormat dates, prices and percentages inside labels with Excel's TEXT function. Format codes, common mistakes and a live practice exercise.

Frequently asked questions

Why does Excel remove leading zeros?

+

Excel sees 00742 as a number, and numbers don't have leading zeros, so it stores 742. To keep the zeros, store the entry as text or use a number format that displays them.

How do I add leading zeros to a number in Excel?

+

Use =TEXT(A2,"00000") to pad the number to five digits as text, or apply the custom number format 00000 to keep it a number. Use as many zeros as the total length you want.

How do I keep leading zeros when I type a number?

+

Type an apostrophe first, like '00742, or format the cells as Text before you type. The apostrophe doesn't show in the cell.

How do I keep leading zeros when opening a CSV file?

+

Don't double-click the CSV. Import it with Data > From Text/CSV and set the ID column's data type to Text before loading, so Excel doesn't convert it to a number.

Should I use TEXT or a custom number format?

+

Use a custom format when the value must stay a number for maths or sorting. Use TEXT when you need the padded code as text, for example to join it with other text or match it against text IDs.

Sources

  • TEXT function - Microsoft Support
  • Create a custom number format - Microsoft Support
  • Convert numbers stored as text to numbers - Microsoft Support

Written and checked by the ExcelReady Team. First published November 1, 2026. The practice exercise runs in the same formula engine as our lessons. Found a mistake? Read our editorial policy or email hello@excelready.app.

On this page

  1. Why does Excel remove leading zeros?
  2. How to add leading zeros with the TEXT function
  3. How to show leading zeros with a custom number format
  4. How to keep leading zeros when you type
  5. How to pad codes that are already text
  6. How to keep leading zeros when opening a CSV file
  7. Practise it

Keep reading

Text· 6 min read

Combine a Date With Text in Excel (Without Numbers)

To combine a date and text in Excel, wrap the date in TEXT before you join it: ="Due "&TEXT(B2,"d mmm yyyy") returns Due 15 Mar 2024. Joining the date directly, as in ="Due "&B2, shows the serial number instead, like Due 45366, because Excel stores dates as numbers. The format code inside TEXT controls how the date looks.

Text· 6 min read

How to Add Text to the Start or End of Cells

To add text to a cell, join it with the & sign in a helper column: ="SKU-"&A2 adds text to the start, and =A2&" kg" adds it to the end. Put the added text in double quotes. For numbers, wrap them in TEXT to keep their format. To show text without changing the value, use a custom number format instead.

Dates· 5 min read

Get the Month Name From a Date in Excel

To get the month name from a date in Excel, use =TEXT(A2,"mmmm") for the full name, like March, or =TEXT(A2,"mmm") for the short name, like Mar. The result is text. To show the name but keep the real date, apply a custom number format of mmmm instead. To turn a month number into a name, use =TEXT(DATE(2024,B2,1),"mmmm").

Don't just read about Excel. Do it.

Practise real formulas in a live spreadsheet with instant feedback, right in your browser. Nothing to download.

Start learning for free