Data Cleaning: Standardize ZIP Codes To Five Digits

Excel Formulas › Data Cleaning

All versions

Excel drops the leading zero from a ZIP like 02134 the moment it is typed as a number, and mailing lists often mix five-digit and ZIP+4 values in one column. This recipe pads short ZIPs back to five characters with REPT and cuts longer ones to five with LEFT, leaving a consistent text ZIP.


Quick formula: Pad with zeros if shorter than five characters, otherwise keep the first five:
=IF(LEN(B2)<5,REPT("0",5-LEN(B2))&B2,LEFT(B2,5))

2134 becomes 02134 and 75201-1234 becomes 75201.

Functions used (tap for the full reference guide):

The example

Four ZIPs in different shapes. The padded ones gain characters; the ZIP+4 value loses its extension.

ABCD
1CaseZIP as enteredClean ZIPChars changed
2Boston2134021341
3Dallas75201-123475201-5
4Hartford6103061031
5Austin78701787010

The formula

Check the length; pad if short, trim if long:

=IF(LEN(B2)<5,REPT("0",5-LEN(B2))&B2,LEFT(B2,5)) // clean ZIP; characters changed = LEN(clean) - LEN(original)

How it works

Here is the logic, one piece at a time:

  1. LEN(B2)<5 detects ZIPs that lost their leading zeros.
  2. REPT("0",5-LEN(B2)) builds exactly the number of zeros needed.
  3. &B2 glues the zeros in front, keeping the result as text.
  4. LEFT(B2,5) keeps only the first five characters of longer ZIPs, removing the ZIP+4 extension.

Format the result column as Text before pasting values, or Excel will strip the zero again.

Try it: interactive demo

Interactive

Type a ZIP code (any length).

Variations

Strip spaces and dashes first

Clean stray characters before measuring length.

=IF(LEN(SUBSTITUTE(B2,"-",""))<5,REPT("0",5-LEN(SUBSTITUTE(B2,"-","")))&SUBSTITUTE(B2,"-",""),LEFT(SUBSTITUTE(B2,"-",""),5))

Use TEXT for numeric ZIPs

If the ZIPs are true numbers, TEXT does the padding.

=TEXT(B2,"00000")

Pitfalls & errors

If the source ZIP is a real number, Excel has already dropped the zero; the value 2134 looks like four characters, so this formula pads it correctly, but the original is a number and displays 2134 until the result is formatted as Text.

Canadian and UK postal codes do not fit this pattern; apply it only to US ZIPs.

Add a data validation rule on the clean column that only allows five-character text.

Practice workbook

📊
Download the free Data Cleaning: Standardize ZIP Codes To Five Digits practice workbook
Edit the yellow ZIP cells; the clean ZIP and characters changed recalculate.

Frequently asked questions

Will this keep the ZIP as text?
Yes. Both branches return text, so leading zeros are preserved when you copy and paste as values.
What about ZIPs with spaces?
Wrap the reference in TRIM or use the SUBSTITUTE variation first.

Stop fighting formulas. Learn them in a day.

This recipe is one of hundreds of real-world formulas we teach. Our Excel Formulas & Functions class covers lookups, logic, text, and dynamic arrays hands-on — live in Dallas–Fort Worth, Houston, Austin, Oklahoma City, Denver, or online.

See the Formulas & Functions Class

Related formulas: Standardize Phone Number Format · Build a Normalized Match Key · Pad Numbers with Leading Zeros

Function references: IFLENREPTLEFT