To force numbers to a fixed width with leading zeros — turning 42 into 00042 for IDs, SKUs, or ZIP codes — use the TEXT function with a 0 format. The result is text, which is exactly what an identifier should be.
0 is a required digit slot; numbers shorter than the pattern get leading zeros, so 42 becomes “00042.”
The example
IDs padded to 5 digits.
| A | B | |
|---|---|---|
| 1 | ID | Padded |
| 2 | 42 | 00042 |
| 3 | 1750 | 01750 |
| 4 | 9 | 00009 |
The formula
The padded ID in B2:
How it works
The format code defines the width:
- In a TEXT format, each
0is a digit placeholder that always shows — padding with a zero if there’s no digit there. "00000"means “at least 5 digits,” so 42 gets three leading zeros →"00042".- Numbers already 5+ digits are shown in full — nothing is truncated.
- The output is text, which is correct for IDs (you don’t do math on a ZIP code).
Just want it to display padded while staying a real number? Use a custom cell format (Ctrl+1 → Custom → 00000) instead of TEXT — the underlying value stays numeric.
Try it: interactive demo
Enter a number and a width.
Variations
Pad to a width with REPT
Alternative that pads any text, not just numbers:
Add a fixed prefix
Build a code like INV-00042:
Display-only padding (keep the number)
Custom number format, not a formula:
Pitfalls & errors
TEXT returns text. You can’t sum or do math on the result. If you need a real number that merely looks padded, use a custom cell format instead.
Leading zeros vanish on import. If a CSV column of IDs lost its zeros, the original numbers were stored numerically — re-pad with TEXT, or import the column as text.
Width too small truncates nothing — but be sure your pattern has enough 0s for your largest value, or longer numbers simply show in full (no padding), which may misalign columns.
Practice workbook
Frequently asked questions
How do I add leading zeros to numbers in Excel?
How do I keep leading zeros but still have a number?
Why did my IDs lose their leading zeros?
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