Excel and Google Sheets how-to
Add leading zeros to numbers
Type 00021 and Excel or Google Sheets shows 21, because to them it is just the number 21. Here is how to get the zeros back, and keep them.
| A | B | C | |
|---|---|---|---|
| 1 | Name | Typed | ID |
| 2 | Ava | 21 | 00021 |
| 3 | Ben | 8090 | 08090 |
| 4 | Cal | 7 | 00007 |
| 5 | Dee | 1234 | 01234 |
| 6 | Eli | 123456 | 123456 |
Sample data. IDs typed as numbers in column B, the formula in C2 is copied down.
The formula
Click the first ID cell (C2 here) and type:
=TEXT(B2,"00000")C2 shows 00021. Copy it down: 8090 becomes 08090 and 7 becomes 00007.
- B2 is the number to pad.
- "00000" is the pattern: each 0 is one digit, and any digit the number does not have is filled with a zero.
Use as many zeros as the length you want: "000" turns 21 into 021. A number longer than the pattern is not cut, so 123456 stays 123456.
Keep it a number: use a custom format
TEXT gives you text, so the result is no longer a number. If you only want the zeros to show, keep the number and change how it is displayed:
- Excel: select the cells, press Ctrl+1, choose Custom and type 00000 in the Type box.
- Google Sheets: Format, Number, Custom number format, type 00000, Apply.
The cell shows 00021 but still holds 21, so sums and lookups against other numbers keep working.
Codes with letters, or a mix
TEXT only pads numbers. For codes that can contain letters, join zeros in front and keep the last five characters:
=RIGHT("00000"&B2,5)21 becomes 00021 and AB becomes 000AB. One catch: RIGHT cuts anything longer than five, so 123456 comes back as 23456. Use TEXT when the numbers can be longer than the pattern.
Add one zero in front, whatever the length
Join a zero to the number with &:
="0"&B221 becomes 021 and 8090 becomes 08090. The result is text, like the TEXT version.
Type it with the zeros
To type 00021 and keep it, start with an apostrophe: '00021. The apostrophe does not show in the cell and the entry is stored as text. You can also set the column to text before you type (Excel: Ctrl+1, Text; Google Sheets: Format, Number, Plain text).
Excel marks text that looks like a number with a small green triangle in the corner. It is a warning, not an error.
When a CSV file loses its zeros
Opening a CSV file in Excel turns 00021 into 21 as it loads. In Microsoft 365 you can switch that off once: File, Options, Data, Automatic Data Conversion, and untick Remove leading zeros and convert to a number (on a Mac: Excel, Preferences, Edit). Zeros already lost can be put back with the TEXT formula above.
Turn it back into a number
VALUE turns the padded text back into a number:
=VALUE(C2)00021 comes back as 21. TEXT, RIGHT and VALUE work in every version of Excel and in Google Sheets.
Templates with the math already done
Rather skip the formulas? These templates come with every formula built and checked, plus a filled-in sample.
- Invoice Template and TrackerInvoices with a payment tracker for paid and overdue.
- Inventory SpreadsheetStock tracker with a reorder list and a stock in and out log.
- Checkbook Register SpreadsheetA running balance, a cleared balance and a reconcile tab for one bank account.
More how-tos
- Find a price by its code with XLOOKUPType a product code, get its price back from your price list. One formula, no helper columns.
- Total each category with SUMIFSAdd up all the Fuel, all the Office, all the Meals: one formula per category, and more rules when you need them.
- Check two conditions at once with IF and ANDFree shipping only when the order is 50 or more and ships in Canada: one IF, one AND, done.
- Fix #DIV/0! in an averageAn average of nothing is a division by zero, so AVERAGE shows #DIV/0! until the first number arrives. One IF fixes it.
- Count rows that meet two conditions with COUNTIFSHow many of Ana's deals were 500 or more? COUNTIFS answers it in one cell, and takes as many rules as you need.
- Calculate percentage changeSales went from 400 to 500. That is a 25% increase, and one short formula works it out for every row.
- Free pricing calculatorsPrice a job from your real costs and margin. No sign up.






