Text and numbers

How to Keep Leading Zeros in Excel and CSV (ZIP Codes, IDs)

By the DecodingPro teamUpdated 5 min read

Quick answer

To restore lost leading zeros, use =TEXT(A2,"00000") for a 5-digit code such as a US ZIP code, then paste the results as values. To stop Excel removing them in the first place, import the column as Text (Data, From Text/CSV, Transform Data, set the column type to Text) or format the cells as Text before you paste.

You open a customer file and the ZIP code 02134 now reads 2134. An employee ID 000457 reads 457. Nothing is wrong with the file: Excel simply treats anything that looks like a number as a number, and numbers have no leading zeros. This guide shows how to get them back and how to stop it from happening again.

Why Excel removes leading zeros

A cell in the default General format that contains 02134 is stored as the number 2134. Excel shows the number, not the typing. It happens with ZIP codes, product and barcode numbers, employee and account IDs, and phone numbers that start with 0.

The zeros are usually still in the CSV text file you were sent. They disappear when Excel opens the file and you save it again. So the safest habit is to keep the original file untouched and work on a copy.

Fix 1: add the zeros back with a formula

If every code should have the same length, rebuild it with TEXT. For a 5-digit ZIP code:

=TEXT(A2,"00000")

Use as many zeros as the final length. If some values may already be longer than the length you want, this version never cuts anything off:

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

Fill the formula down, copy the results and use Paste Special, Values over the original column. The cells are now text, which is what you want. Excel may show a small green triangle ("number stored as text"); it is safe to ignore.

Fix 2: a number format, for display only

Select the column, press Ctrl+1, choose Custom and type 00000. The cell still holds the number 2134, but it displays as 02134. This is quick for viewing and printing. Because the underlying value is still a number, check how other tools see it: save a copy as CSV and open it in Notepad to see what was written.

Fix 3: stop it when you open a CSV

Double-clicking a .csv file makes Excel guess every column type, and the guess for 02134 is "number". Import it instead:

  1. Open a blank workbook and choose Data, Get Data, From File, From Text/CSV.
  2. Pick the file and click Transform Data.
  3. Click the header of the affected column, then Data Type, then Text. Repeat for every column that holds codes.
  4. Choose Close and Load.

In Google Sheets, use File, Import and untick "Convert text to numbers, dates, and formulas".

Fix 4: when typing or pasting

  • Format the column as Text first (Home, Number format box, Text), then type or paste.
  • Or type an apostrophe before the number: '02134. The apostrophe is not stored in the cell.

Tip: format the whole column as Text before pasting data in. Formatting after the paste is too late, because the zeros are already gone.

The 15-digit limit

Excel keeps only 15 significant digits in a number. In a 16-digit ID, everything after the 15th digit silently becomes a zero, and Excel often displays the number as 1.23457E+15. Those digits cannot be recovered afterwards. Long identifiers must be text from the moment they are pasted or imported.

Warning: do not keep payment card numbers in a spreadsheet at all. They are sensitive, and a number-formatted column will also corrupt them.

Which fix for which data

DataTypical lengthBest approach
US ZIP code5 digitsTEXT(A2,"00000"), or import as Text
ZIP+4 (02134-1234)10 with a hyphenAlready text, no problem
Barcodes (EAN-13, UPC)13 or 12Import as Text; never format as Number
Employee, order or account IDFixedImport as Text, or TEXT with the right number of zeros
Phone numbersVariesKeep as text, see fixing phone numbers in Excel
Identifiers of 16 or more digits16+Text only, from the first moment

Check for damage before you use the file

To count values that are shorter than a 5-digit code should be, which may have lost zeros:

=SUMPRODUCT((LEN(A2:A5000)>0)*(LEN(A2:A5000)<5))

A result above zero means some codes need a second look.

A whole file at once

DecodingPro reads each cell as it is stored and lists every change it makes, so a text value such as 02134 is never turned into a number, and nothing is changed without appearing in the log.

Try it on your own file

You start with 100 free credits. Every change is logged, and anything unclear is flagged, never guessed.

Fix a spreadsheet

Questions people ask

Why does Excel show 1.23E+11 instead of my number?

A long number in the General format is shown in scientific notation when the column is too narrow or the number has many digits. Up to 15 digits the value is intact: widen the column or format it as Number with no decimals. Beyond 15 digits the extra digits are already lost.

Can I get the zeros back after saving the file?

Only if you know the right length. If all codes should have 5 digits, a formula can rebuild them. If the lengths varied, the original values are gone and you need the source file.

Does Google Sheets have the same problem?

Yes. Format the column as Plain text (Format, Number, Plain text) before pasting, and untick the conversion option when importing a CSV.

Are the zeros lost in the CSV file itself?

Not unless you opened and re-saved it in Excel as numbers. Open the file in a plain text editor such as Notepad to see what is really inside.

Keep reading

01Excel data cleaningHow to Clean Messy Excel Data: A Step-by-Step GuideThe fixed order that stops one fix from undoing another, with the formulas for every step.10 min read03CSV and importsHow to Clean a CSV File Before Importing It Into a CRMSeven fixes that prevent duplicate contacts, rejected rows and scrambled characters, and the 10-row test to run first.4 min read04DatesHow to Fix Dates in Excel and CSV Files (Mixed Formats)Text dates, day-month swaps, two-digit years and the one rule that makes dates safe to share.8 min read05Phone numbersHow to Fix Phone Numbers in Excel: Format and Country CodesLeading zeros, 9.19E+11, country codes and the international format that every system accepts.6 min read06DuplicatesHow to Remove Duplicates in Excel Without Losing DataExact, near and partial duplicates: decide what counts, mark before you delete, keep the best record.6 min read07DuplicatesHow to Find and Highlight Duplicates in ExcelFind repeats safely first: highlight them, count them, keep the first one, and spot the near-duplicates Excel does not see.3 min read08NamesHow to Standardize Names in Excel: Proper Case and ExceptionsWhat PROPER gets wrong, how to protect names that are already right, and how to flip "Smith, John" into "John Smith".4 min read09Email addressesHow to Fix Email Typos in Excel: gmial.com, .con and Missing @The typos that make campaigns bounce, and the formulas and checks that fix them without guessing.4 min read10Email addressesHow to Clean an Email List Before You Send a CampaignA five-step routine that removes the avoidable bounces from a list without deleting anyone you should keep.3 min read11NamesHow to Split Full Names into First and Last Name in ExcelFlash Fill, Text to Columns and formulas for splitting names, and the names that trip each one up.4 min read12Text cleanupHow to Remove Extra Spaces in Excel (TRIM, CLEAN and Non-Breaking Spaces)Why TRIM sometimes does nothing, and the one formula that removes every kind of stray space.3 min read13Text cleanupHow to Remove Special Characters and Line Breaks in ExcelThe characters you cannot see, the smart quotes you can, and the exact formula or shortcut that removes each one.4 min read14NumbersHow to Convert Text to Numbers in Excel (Numbers Stored as Text)Why sums show zero, why numbers sit on the left, and four ways to turn text back into real numbers.3 min read15Excel data cleaningHow to Clean Data with Power Query in Excel (Step by Step)Record your cleaning steps once and replay them on every new file, without formulas and without touching the original data.4 min read16Comparing dataHow to Compare Two Lists in Excel and Find What Is MissingFind the names, IDs or emails that are in one list and not the other, with formulas that scale.3 min read17CSV and importsFix Garbled Characters and Broken CSV Imports (UTF-8)UTF-8, delimiters, leading zeros, quotes and a checklist that makes a file safe to import.7 min read18Data entryData Entry Accuracy: How to Check, Measure and Improve ItWhat the research says about error rates, why proofreading fails and the checks that actually work.9 min read