Mask Sensitive Data (Show Last 4)

Excel Formulas › Text

All versionsREPTRIGHTLEN

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.


Quick formula: to mask all but the last 4 characters of A2:
=REPT("*", LEN(A2)-4) & RIGHT(A2, 4)
REPT builds a row of asterisks as long as the hidden part; RIGHT keeps the last 4 characters.

Functions used (tap for the full reference guide):

The example

Account numbers with only the last 4 shown.

AB
1NumberMasked
24111111111116789************6789
3100200300*****0300

The formula

The masked value:

=REPT("*", LEN(A2)-4) & RIGHT(A2, 4) // "...6789" → "************6789"

How it works

Build the mask, keep the tail:

  1. LEN(A2)-4 is how many characters to hide — everything except the last 4.
  2. REPT("*", …) repeats an asterisk that many times, building the mask.
  3. RIGHT(A2, 4) keeps the last 4 characters visible.
  4. 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

Live demo

Type a value and how many trailing characters to show.

Masked:

Variations

Show first few instead

Keep the start, hide the rest:

=LEFT(A2, 3) & REPT("*", LEN(A2)-3)

Mask the middle

Show both ends:

=LEFT(A2,2) & REPT("*", LEN(A2)-4) & RIGHT(A2,2)

Mask an email

Hide the username, keep the domain:

=LEFT(A2,2) & "***@" & TEXTAFTER(A2,"@")

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

📊
Download the free Mask Sensitive Data (Show Last 4) practice workbook
Account numbers with the live mask formula, the show-first, mask-middle, and email variants, plus 4 challenges with answers. No sign-up required.

Frequently asked questions

How do I mask a number but show the last 4 digits in Excel?
Use =REPT("*", LEN(A2)-4) & RIGHT(A2, 4). REPT builds the asterisk mask for the hidden part and RIGHT keeps the last four characters visible.
How do I mask the middle of a value?
Show both ends: =LEFT(A2,2) & REPT("*", LEN(A2)-4) & RIGHT(A2,2).
Is formula masking secure?
No. It only hides the value visually; the original is still in the source cell. For real protection, paste the masked text as a value and remove the original data.

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: Repeat text for in-cell bars · Pad numbers with leading zeros · Remove specific characters

Function references: REPT · RIGHT · LEN