Skip to content

RIGHT

Returns the last characters of a piece of text, counting from the right.

Syntax

=RIGHT(, )

Text

All versions of Excel.

Try it

Edit the formula in C2 or change the inputs. The sheet recalculates as you type.

C2
A
B
C
1
Invoice
Amount
Last 4
2
INV-2025-0457
1,840
0457
3
INV-2025-0458
625
4
INV-2025-0459
3,120
5

C2 =RIGHT(A2,4) returns 0457

How RIGHT works

RIGHT returns the last characters of a piece of text. Use it to read the suffix of a code, the last four digits of an account number, or a file extension.

The arguments

  • text is the text to read, normally a cell reference.
  • num_chars is how many characters to keep, counted from the last character. It is optional and defaults to 1, so =RIGHT(A2) returns the final character.

If num_chars is longer than the text, RIGHT returns the whole text. If it is 0, you get an empty string. A negative number returns #VALUE!.

RIGHT returns text

Like LEFT, RIGHT always returns text, even when the characters are digits. =RIGHT("INV-2025-0457",4) returns the text "0457", including the leading zero. That is often what you want for an ID. If you need a number for a sum or a lookup, use =VALUE(RIGHT(A2,4)), which gives 457.

RIGHT reads the stored value. On a date cell showing 15-Mar-2025 the stored value is the serial 45731, so =RIGHT(B2,2) returns "31", which is not the day. Use DAY, MONTH, YEAR or TEXT for parts of a date.

When the length varies

A fixed count works when every item has a suffix of the same size, such as the last four digits of a card or account number. When the size varies, work it out from the position of a separator. To get a file extension from report.xlsx and budget.csv, find the dot with FIND and subtract it from the total length with LEN:

=RIGHT(A2,LEN(A2)-FIND(".",A2))

For budget.csv, LEN is 10 and the dot is at position 7, so RIGHT takes 3 characters: csv. This assumes there is only one dot. If a name can contain more than one, find the last one instead, or use TEXTAFTER with a negative instance number: =TEXTAFTER(A2,".",-1), available in Microsoft 365 and Excel 2024.

Masking and trimming

RIGHT is also how you hide most of an ID. ="****"&RIGHT(A2,4) shows only the last four characters. To remove the last characters instead of keeping them, use LEFT: =LEFT(A2,LEN(A2)-4).

Trailing spaces

A trailing space counts as a character. If a cell contains "0457 ", then =RIGHT(A2,4) returns "457 ". Data pasted from other systems often has hidden trailing spaces, so wrap the cell in TRIM when the result looks wrong: =RIGHT(TRIM(A2),4).

Arguments

text
The text to take characters from. Usually a cell such as A2. A number is treated as the text it would show in a General-format cell.
num_charsoptional
How many characters to return, counted from the end. If you leave it out, RIGHT returns 1 character. A value larger than the text returns all of the text. A negative value returns #VALUE!.

Examples

Each example is a live sheet. Change the inputs or the formula and watch the result.

Example 1

Last four digits of a reference

C2 =RIGHT(A2,4)

Result: 0457

The result is the text "0457". The leading zero is kept because it is text, not a number.

C2
A
B
C
1
Invoice
Amount
Last 4
2
INV-2025-0457
1,840
0457
3
INV-2025-0458
625
4
INV-2025-0459
3,120
5

C2 =RIGHT(A2,4) returns 0457

Example 2

Mask all but the last four characters

C2 ="****"&RIGHT(A2,4)

Result: ****8877

RIGHT keeps the last four characters, and the ampersand puts the typed asterisks in front.

C2
A
B
C
1
Account
Owner
Masked
2
40218877
Cardigan Ltd
****8877
3
4

C2 ="****"&RIGHT(A2,4) returns ****8877

Example 3

File extension when the length varies

C3 =RIGHT(A3,LEN(A3)-FIND(".",A3))

Result: csv

budget.csv has 10 characters and the dot is at position 7, so RIGHT takes the last 3. The same formula in C2 returns xlsx.

C3
A
B
C
1
File
Owner
Extension
2
report.xlsx
Finance
3
budget.csv
Planning
csv
4

C3 =RIGHT(A3,LEN(A3)-FIND(".",A3)) returns csv

Example 4

Everything after the last dash with TEXTAFTER

C3 =TEXTAFTER(A3,"-",-1)

Result: B12

A negative instance number counts delimiters from the end, so this returns the text after the last dash. It needs Microsoft 365 or Excel 2024.

C3
A
B
C
1
Batch code
Qty
Lot
2
PW-24-0113-A7
400
3
GL-24-0207-B12
250
B12
4

C3 =TEXTAFTER(A3,"-",-1) returns B12

Your turn.

Solve it in the sheet. Every answer is checked, with hints if you need them.

Task 1 of 2

In B2, return the last four characters of the file name in A2.

Answer in B2.

B2
A
B
C
D
1
File
Year (last 4)
Extension
Owner
2
sales-2025
Finance
3
forecast-2024
Planning
4
budget.csv
Finance
5
report.xlsx
Ops
6
7

Common mistakes

  • RIGHT returns text, even for digits. =RIGHT("INV-0457",4) is the text "0457", which won't match the number 457 in a lookup. Use VALUE(RIGHT(...)) if you need a number.
  • RIGHT reads the stored value, not the display. On a date such as 15-Mar-2025, =RIGHT(B2,2) returns "31" from the serial number 45731. Use DAY, MONTH, YEAR or TEXT.
  • A fixed num_chars fails when suffix lengths vary. Use LEN and FIND to work out the length, or TEXTAFTER in Microsoft 365.
  • Trailing spaces are characters. =RIGHT(A2,4) on "0457 " returns "457 ". Wrap the cell in TRIM when data comes from another system.
  • FIND returns #VALUE! when the separator is missing, and that error passes through RIGHT. Wrap the formula in IFERROR if some cells may have no separator.

Questions people ask

How do I get the last 4 characters of a cell in Excel?

Use `=RIGHT(A2,4)`. The second argument is the number of characters to keep from the end.

How do I remove the first character from text?

Use `=RIGHT(A2,LEN(A2)-1)`. LEN counts all characters, and RIGHT keeps all but the first. `=MID(A2,2,LEN(A2))` also works.

How do I get the text after the last space or dash?

In Microsoft 365 or Excel 2024, use `=TEXTAFTER(A2," ",-1)`. In older versions, a common trick for the last word is `=TRIM(RIGHT(SUBSTITUTE(A2," ",REPT(" ",100)),100))`, which works while the last word is under 100 characters.

Why does RIGHT lose the leading zeros, or keep them?

RIGHT keeps them: it returns text, and text keeps its zeros. They disappear only when you convert the result with VALUE, because a number has no leading zeros.

What happens if num_chars is longer than the text?

RIGHT returns the whole text without padding it. `=RIGHT("A7",10)` returns "A7".

Learn RIGHT in a real sheet.

RIGHT is taught in Logic and text, lesson 10: LEFT, RIGHT and LEN. Each lesson is a short, graded exercise like the one above.