To hide most of a number while keeping the last few visible — a card or account like ****6789 — combine REPT for the mask with RIGHT for the visible tail. Quick redaction for screenshots and reports.
The example
Account numbers with only the last 4 shown.
| A | B | |
|---|---|---|
| 1 | Number | Masked |
| 2 | 4111111111116789 | ************6789 |
| 3 | 100200300 | *****0300 |
The formula
The masked value:
How it works
Build the mask, keep the tail:
LEN(A2)-4is how many characters to hide — everything except the last 4.REPT("*", …)repeats an asterisk that many times, building the mask.RIGHT(A2, 4)keeps the last 4 characters visible.- The
&joins the mask and the tail —************6789.
This is visual masking, not security. The full value is still in the source cell (and in the formula’s reference). For real protection, store the masked text as a value and remove the original, or don’t keep the sensitive data in the sheet at all.
Try it: interactive demo
Type a value and how many trailing characters to show.
Variations
Show first few instead
Keep the start, hide the rest:
Mask the middle
Show both ends:
Mask an email
Hide the username, keep the domain:
Pitfalls & errors
Short values go wrong. If the value has 4 or fewer characters, LEN-4 is 0 or negative and REPT errors or shows nothing. Guard with MAX(LEN(A2)-4, 0).
It’s not encryption. The underlying data is still present. Treat this as redaction for display, not security.
Result is text. A masked number is a string — don’t expect to do math on it.
Practice workbook
Frequently asked questions
How do I mask a number but show the last 4 digits in Excel?
How do I mask the middle of a value?
Is formula masking secure?
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