CSV guide

How to Keep Leading Zeros in a CSV

Why Excel removes the zeros from your IDs, zip codes, and phone numbers when you open a CSV, and four reliable ways to keep them.

Rowlum · Updated November 2026 · 4 min read

Double-clicked openzeros lost
7701
8544
1020
Imported as text kept
07701
08544
01020
The same CSV column — zip codes — opened two different ways.

Why Excel eats your leading zeros

A CSV is just plain text, like 00123,Jane,07701. It doesn’t know if 00123 is a product code or the number one hundred and twenty-three. When Excel opens the file, it guesses the type of every column, and anything that looks like a number is stored as a number. Numbers don’t have leading zeros, so 00123 becomes 123 on screen.

Here’s what most guides miss: your data isn’t actually broken. If you open the same CSV in a text editor, the zeros are still there. The problem is only with how Excel reads the file, so every fix below is about controlling the import, not fixing the data itself.

Four ways to keep the zeros

1

Import with Text to Columns

Don’t double-click the CSV. Open a blank workbook, then Data → From Text/CSV (or the legacy Text to Columns wizard). On the final step, select the affected column and choose Text as its type before loading. The zeros survive because Excel never treats the column as a number.

2

Use Power Query

This is the modern version of the same idea. Load the file through Get & Transform, and in the preview set the column’s type to Text. Power Query remembers this step, so if you refresh the file later, the zeros stay in place. This is useful for reports you need to reopen.

3

Custom number format (display only)

Select the cells, open Format Cells → Custom and enter a mask like 00000 (or use Special → Zip Code). This displays the zeros, but the underlying value is still a number. If you export back to CSV, the zeros disappear again. This method is fine for viewing, but not for data you plan to save again.

4

TEXT() in a helper column

In a spare column, use =TEXT(A2,"00000") to pad each value to a fixed width. The result is real text, so copy it and use Paste Special → Values to replace the original before saving. This method takes a few extra steps, but it works reliably.

The catch nobody mentions: CSV has no memory

Here’s why this problem keeps coming back. A CSV file stores no formatting at all, only raw values separated by commas. Even if you fix the zeros in Excel, as soon as you Save As → CSV, all formatting is lost and the next person who opens it will see 123 again.

FAQ

Why does Excel remove leading zeros from a CSV?

When Excel opens a CSV, it auto-detects each column’s type, and a value like 00123 looks like a number. Numbers have no leading zeros. The zeros are still in the raw CSV file; Excel just displays the value as 123. The fix is to tell Excel to read that column as text instead.

Does saving as .xlsx keep leading zeros?

Yes, as long as the cells are formatted as Text or a custom format before you save. Unlike a CSV, an .xlsx file stores formatting together with the data, so the zeros stay with the file. A plain CSV stores no formatting, which is why the problem keeps coming back.

How do I keep leading zeros for a whole column like zip codes or IDs?

Format the entire column as Text before you type or paste the data, or import the file with Text to Columns or Power Query and set that column’s type to Text. Applying this to the whole column, not just cell by cell, keeps new entries safe too.

Keep going