How to Mask All but the Last Four Digits in Excel
Hide sensitive numbers behind asterisks while keeping the last four digits — for account numbers, cards and email addresses.
You will learn to
- Mask a variable-length number keeping the last four digits
- Mask a card number in a fixed display format
- Mask the local part of an email address
How it works
To share a report without exposing full account numbers, show only the last four characters: =REPT("*",LEN(B2)-4)&RIGHT(B2,4). LEN-4 works out how many characters to hide, REPT draws that many asterisks, and RIGHT keeps the visible tail — so the masked value is the same length as the original.
For card numbers a fixed pattern is clearer: ="**** **** **** "&RIGHT(C2,4). Email addresses can be masked too: keep the first letter, hide the rest of the name and keep the domain. Remember that masking with formulas only hides the value in that column — delete or protect the original column before sharing.
=REPT("*",LEN(B2)-4)&RIGHT(B2,4)