The RIGHT function returns the last characters from a text string, based on how many characters you specify. It is a simple way to pull suffixes, codes, or trailing digits out of longer text.
=RIGHT(text, [num_chars])What does RIGHT do?
The RIGHT function is a text function that extracts a specified number of characters from the end of a text string. You give it the text and the number of characters you want, and it returns those characters starting from the right side. For example, =RIGHT("INV-2024-001", 3) returns 001.
This matters because office workers and students often receive data where the useful part is buried at the end of a longer string: order numbers with a store code suffix, full names where you need the initial, or product codes where the last two characters indicate the size. RIGHT lets you pull that piece out without retyping or manually splitting the text.
A common real situation is a sales report where invoice numbers follow a pattern like INV-1001-LON. You need the three-letter location code at the end for a pivot table. Instead of editing each cell by hand, you use RIGHT to extract the last three characters into a new column, then sort or filter by that code.
When to use RIGHT
- Extracting a location or store code from the end of an invoice or order number
- Pulling the last four digits of a phone number or account number for verification
- Getting the file extension from a file name, such as
xlsxfromreport.xlsx - Isolating a size or colour suffix from a product code like
SHIRT-RED-XL - Removing a standard prefix by keeping only the trailing portion of a code
- Extracting the year from a text date or reference number that ends with four digits
RIGHT syntax
=RIGHT(text, [num_chars])| Argument | Required? | What to enter |
|---|---|---|
text | Required | The text string or cell reference you want to extract characters from. For example, A2 or "INV-1001". |
num_chars | Optional | The number of characters to return from the right side of the text. If omitted, Excel assumes 1. It must be zero or greater. |
What it returns: A text string containing the specified number of characters from the end of the original text. If num_chars is greater than the length of the text, the entire text is returned.
RIGHT examples
1 Extract the last three characters of a simple code
This example shows the basic behaviour of RIGHT. The goal is to pull the last three characters from a short code in column A. The formula =RIGHT(A2, 3) looks at the text in A2 and counts three characters from the right. It returns 001 for the first code, and the same logic applies to the other rows.
| A | B | C | D | |
|---|---|---|---|---|
| 1 | Code | |||
| 2 | AB-001 | 001 | ||
| 3 | AB-002 | |||
| 4 | AB-003 | |||
| 5 | AB-004 | |||
| 6 | AB-005 | |||
| 7 |
2 Get the last four digits of a phone number
Here the goal is to show only the last four digits of each phone number for a privacy-friendly display. The formula =RIGHT(B2, 4) takes the phone number in B2 and returns the four rightmost characters. For 555-123-4567, it returns 4567. This is useful when you need to confirm identity without showing the full number.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Name | Phone | |||
| 2 | Alice Brown | 555-123-4567 | 4567 | ||
| 3 | Ben Carter | 555-987-6543 | |||
| 4 | Chloe Davis | 555-222-3333 | |||
| 5 |
3 Extract the file extension from a file name
The goal is to list the file type for each document. The formula =RIGHT(A2, 4) returns the last four characters of the file name in A2. For report.xlsx, the last four characters are xlsx. Note that this works because the extension is always four characters; for three-character extensions you would use 3 instead.
| A | B | C | D | |
|---|---|---|---|---|
| 1 | File Name | |||
| 2 | report.xlsx | xlsx | ||
| 3 | budget.xlsx | |||
| 4 | notes.xlsx | |||
| 5 | data.xlsx | |||
| 6 |
4 Pull the location code from an invoice number
In this business case, invoice numbers end with a three-letter location code. The goal is to extract that code into its own column for reporting. The formula =RIGHT(A2, 3) takes the invoice number in A2 and returns the last three characters, such as LON. You can then use this column to group sales by location.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Invoice | Amount | |||
| 2 | INV-1001-LON | 1200 | LON | ||
| 3 | INV-1002-NYC | 850 | |||
| 4 | INV-1003-PAR | 430 | |||
| 5 | INV-1004-LON | 990 | |||
| 6 |
5 Get the size suffix from a product code
This example extracts the size from a product code that ends with a hyphen and a size. The goal is to separate the size for inventory counts. The formula =RIGHT(A2, 2) returns the last two characters of the code in A2, which is the size for codes like SHIRT-RED-XL (returns XL). For a one-character size like M, you would use 1 instead.
| A | B | C | D | E | |
|---|---|---|---|---|---|
| 1 | Product Code | Price | |||
| 2 | SHIRT-RED-XL | 25 | XL | ||
| 3 | SHIRT-BLU-L | 25 | |||
| 4 | SHIRT-GRN-M | 22 | |||
| 5 | SHIRT-YEL-S | 22 | |||
| 6 |
Common RIGHT errors and how to fix them
| Error | Why it happens | How to fix it |
|---|---|---|
| #VALUE! | The num_chars argument is negative or not a number. | Make sure num_chars is zero or a positive number. Use a number or a cell reference that contains a number. |
| #NAME? | The function name is misspelled, such as RIGTH. | Check the spelling: it must be RIGHT. |
| Unexpected result (too few or too many c | The num_chars value does not match the actual length of the suffix you want. | Count the characters in the suffix carefully, or use a function like LEN to help determine the correct number. |
| Returns the whole text instead of a port | num_chars is greater than or equal to the length of the text. | Reduce num_chars to the exact number of characters you need from the right. |
Tips for using RIGHT
- If you omit num_chars, RIGHT returns only the last character, which is useful for quick checks.
- Use RIGHT together with
LENandFINDto extract text after a specific delimiter, such as everything after a hyphen. - Remember that RIGHT always returns text, even if the result looks like a number. Use
VALUEif you need to do maths with it. - To extract characters from the left side instead, use the
LEFTfunction. - If your data has inconsistent suffix lengths, consider using
TEXTAFTER(Excel 365) or a combination ofMIDandFINDfor more flexibility.
Frequently asked questions
What does the RIGHT function do in Excel?
RIGHT returns the last characters of a text string. You specify how many characters you want, and it gives you that many characters from the right end.
How do I get the last 4 characters in Excel?
Use =RIGHT(A2, 4) where A2 is the cell containing the text. This returns the four rightmost characters.
Can RIGHT return a number instead of text?
RIGHT always returns text. If you need a number, wrap it in the VALUE function, for example =VALUE(RIGHT(A2, 4)).
What happens if num_chars is larger than the text length?
RIGHT returns the entire text string, because there are not enough characters to extract the requested number.
Related functions
Every example on this page was recalculated by SheetSkill’s spreadsheet engine. RIGHT reference