Excel Formula for Last 4 Digits: RIGHT and Fixes

Formulas & functions · Updated November 18, 2026

To return the last four characters from a value in cell A2, use =RIGHT(A2,4). For example, if A2 contains 5551234567, the result is 4567; the result is text, which matters when the ending includes a leading zero.

The basic RIGHT formula

RIGHT is the simplest way to get the end of a text value in Excel. Its first argument is the cell or text to read, and its second argument is how many characters to return. With the value to check in A2, the formula is =RIGHT(A2,4). If A2 contains the text 847261, Excel returns 7261.

The count means characters, not a numerical calculation. Excel starts at the far right and takes four characters moving left. If the source has fewer than four characters, RIGHT returns all of them rather than an error. For example, if A2 contains 73, the formula returns 73. It does not add leading zeroes to make the result four characters long.

To use it in a worksheet:

  1. Select the cell where you want the result, such as B2.
  2. Type =RIGHT(A2,4) and press Enter.
  3. Change A2 to the cell containing your value, then copy the formula down if you have more rows.

The comma separates the function’s arguments in standard English-language Excel settings. Some regional settings use a semicolon as the argument separator. If Excel reports a formula error when you enter the comma version, check the separator your installation expects.

What RIGHT returns: text, not a number

RIGHT returns text, even when the extracted characters look like a number. That is usually helpful for account references, phone-number endings, product codes, and other identifiers: the extracted characters stay intact, and Excel does not treat them as something to add or calculate with.

For instance, with the text value 543210 in A2, =RIGHT(A2,4) returns the text 3210. If the last four characters are 0082, the result remains 0082 rather than becoming 82. A cell’s number format can affect how a result is displayed, but it does not turn the text returned by RIGHT into a numeric value.

If you specifically need a number for later arithmetic, convert the extracted text with VALUE. With a value in A2 whose last four characters are numeric, use =VALUE(RIGHT(A2,4)). For example, if A2 contains 543210, the result is the number 3210. Do not use this version for codes where leading zeroes are meaningful: converting 0082 to a number produces 82. Keep the RIGHT result as text when the exact characters matter.

Last four characters or last four digits?

There is an important distinction between taking the final four characters and finding the final four numeric digits. RIGHT does the first. It does not inspect whether the characters are digits. If A2 contains the text AB12-34, =RIGHT(A2,4) returns 2-34, including the hyphen. That is correct for “last four characters,” but may not answer a request for “last four digits.”

When a value contains only digits, the two requests amount to the same thing. When it contains spaces, punctuation, or letters, decide which result you need before choosing a formula:

  • Use RIGHT when you want the final four characters exactly as stored, including any punctuation.
  • Remove known separators first when the input follows a predictable format, such as a phone number with dashes.
  • Filter out non-digits when formats vary and you need the final four numeric characters wherever they appear.

This distinction also helps explain why a formula can appear to give an incorrect answer: Excel may be returning the last four characters accurately even though the source contains separators that were not meant to count.

Preserve leading zeroes and long identifiers

Identifiers are not quantities. A phone number, postal code, membership number, or account reference may begin with zero, and dropping that zero can make the result wrong. RIGHT preserves zeroes that are present in the source text. For example, if A2 contains the text 004681, =RIGHT(A2,4) returns 4681; if it contains 0068, the result is 0068.

For a short source such as 0068, make sure Excel has actually stored the entry as text if you need those zeroes retained. If Excel already interpreted the entry as the number 68, RIGHT cannot recover the two zeroes that were discarded. You can import identifier columns as text or enter a leading apostrophe before an identifier; the apostrophe marks the entry as text and is not displayed as part of the cell value.

Long identifiers need similar care. Excel numeric values have a precision limit of 15 significant digits. A longer identifier entered as a number can lose or change digits, and formatting the cell as Text afterward does not restore the original value. For long IDs, store or import the source as text before extracting its ending. This is especially important for card, tracking, and reference numbers: use only the portion needed for identification, and avoid exposing or sharing full sensitive numbers unnecessarily.

Ignore spaces and punctuation when needed

If the text contains separators and you need the last four digits, Excel for Microsoft 365 can build a string from the numeric characters and then take its final four. Assume A2 contains a phone number as text, such as 1 (212) 555-0198. Use =RIGHT(TEXTJOIN("",TRUE,IFERROR(MID(A2,SEQUENCE(LEN(A2)),1)*1,"")),4). The formula returns 0198: it ignores the spaces, parentheses, hyphen, and other non-numeric characters.

This formula works by making a sequence of character positions, examining each character, and retaining those that can be converted to a number. TEXTJOIN combines the retained characters without adding a separator, and RIGHT takes the final four. The digit zero is retained, so the answer keeps the leading zero in 0198. SEQUENCE is available in Microsoft 365 and Excel 2021 or later; this is not the best choice for older Excel versions.

It is more elaborate than RIGHT alone, so use it only if separators genuinely need to be ignored. If every value has the same known formatting, cleaning that formatting first may be easier to understand and maintain. Also note that the formula filters characters that Excel can interpret as numeric digits; it is intended for ordinary digit strings, not for validating whether an input is a correctly formatted phone number or ID.

Copy the formula down a column

Once the first result is correct, you can fill the formula down for other rows. If the source is in A2 and the result formula is in B2, copying B2 to B3 normally adjusts the reference to A3 automatically. This is a relative reference, which makes the same formula useful for each row of a list.

In Microsoft Excel for Microsoft 365 on Windows, use the fill handle—the small square at the lower-right corner of the selected cell—to drag the formula down. If the neighboring column has a continuous list, double-clicking the fill handle can fill alongside it. On Mac, the fill handle works as well. You can also copy the formula cell and paste it into the destination range.

Check a few results at the top, middle, and bottom of the data before relying on a filled formula. Look for blank source cells, shorter values, and rows with a different format. If you need the results to remain fixed after removing or changing the source values, copy the result cells and use Paste Special > Values. That replaces formulas with their current outputs.

Common problems and how to fix them

  • The result contains a hyphen or space. RIGHT counts those as characters. Use a digit-filtering approach if punctuation should be ignored, or clean the known separators first.
  • A leading zero disappears. Check whether the source was stored as a number instead of text. Use RIGHT without VALUE for text-based identifiers, and preserve the original input as text.
  • The result differs from what the cell visibly shows. A number format can display leading zeroes, commas, or other formatting that is not part of the stored value. RIGHT works from the value, not necessarily the formatted appearance. If the displayed representation is what you need, convert or prepare the source as text deliberately.
  • Excel shows a formula error after entry. Confirm the parentheses and quotation marks in any longer formula, and check whether your regional settings require semicolons rather than commas.
  • The extracted digits are wrong for a very long ID. The source may already have been altered by numeric precision limits. Re-import the original identifier as text; changing its format now cannot reconstruct lost digits.

When a different method is better

For a single cell or a regularly updated list, RIGHT is usually preferable because the result updates when the source changes. A formula is also easier to audit than manually typing the final four characters. If your data arrives with inconsistent punctuation, the longer digit-filtering formula can automate cleanup, but document what it removes so another person understands the result.

Flash Fill can be a practical one-time alternative for a small, consistently formatted list. Type the desired ending beside an example, then use Data > Flash Fill in Excel for Windows or Mac and inspect the results. Flash Fill creates values rather than a formula that recalculates when the source changes, so it is not a substitute for a live extraction in a changing dataset. For repeatable work, use a formula and keep the original source column unchanged.

Whatever method you choose, treat the extracted four characters as a partial identifier, not proof that two full records are the same. Many different records can share the same final four digits. Use other appropriate fields when matching records, and restrict access to sensitive source data.

Frequently Asked Questions

What is the Excel formula for the last four digits?
With the value in A2, use =RIGHT(A2,4). It returns the final four characters. If the source contains punctuation, the formula includes punctuation among those characters.

How do I get the last four digits without losing zeroes?
With the identifier stored as text in A2, use =RIGHT(A2,4) and do not wrap it in VALUE. The source must already contain the zeroes; a formula cannot recover zeroes Excel discarded when it stored the entry as a number.

How do I return blank when the source cell is blank?
With the source in A2 and the result in another cell, use =IF(A2="","",RIGHT(A2,4)). This returns a blank result for an empty source and extracts four characters otherwise. It also treats a formula that returns an empty string as blank.

Does RIGHT return a number or text?
RIGHT returns text. That preserves leading zeroes, but the result is not a numeric value for arithmetic. Convert it only when calculation is genuinely needed and leading zeroes have no meaning.

Can I get the last four digits from a phone number with punctuation?
Yes. If A2 contains a phone number as text, the Microsoft 365 formula in the punctuation section removes non-digit characters before returning the final four. Check that the result matches the intended country and number format; extracting digits does not validate a phone number.

Related

Try it: the Formula Explainer: paste any formula and see each function and reference in plain English.

More in Formulas & functions

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.