# How to extract the file extension from a file name in Excel

Take the text after the last dot: =TEXTAFTER(A2,".",-1,,,""). The last argument returns blank for names with no extension.

**Excel:** `=TEXTAFTER(A2,".",-1,,,"")` (Microsoft 365 only)

**Google Sheets:** `=IFERROR(REGEXEXTRACT(A2,"\.([^.]+)$"),"")`

## Example

Sample data (row 1 is the header):

| A | B |
| --- | --- |
| File name | Extension |
| q3-summary.xlsx |  |
| Budget 2026.final.xlsx |  |
| INV-1042.pdf |  |
| notes.txt |  |
| IMG_4471.JPG |  |
| archive.tar.gz |  |
| README |  |

Formula in B2, filled to B8: `=TEXTAFTER(A2,".",-1,,,"")`

Result: xlsx; xlsx; pdf; txt; JPG; gz; 

## How it works

File names can contain several dots, so the extension is what follows the *last* one: instance `-1`. When there is no dot at all, TEXTAFTER would return #N/A; its sixth argument, `""`, returns a blank instead.

## Other ways

- `=IFERROR(RIGHT(A2,LEN(A2)-FIND("*",SUBSTITUTE(A2,".","*",LEN(A2)-LEN(SUBSTITUTE(A2,".",""))))),"")`: Works in every version: count the dots, mark the last one with *, and take everything to its right.

## Common mistakes

- Taking the text after the first dot turns "Budget 2026.final.xlsx" into "final.xlsx".
- Double extensions like .tar.gz return only "gz".
- Extensions come in mixed case (JPG, jpg). Wrap in LOWER before counting or grouping by type.

## Questions

**How do I include the dot?**

Join it back on: `="."&TEXTAFTER(A2,".",-1)`.

**How do I count files by type?**

Count the extension column: `=COUNTIF(B2:B8,"pdf")`.

Every formula and result on this page was checked by running it in the Spreadsheet Practice formula engine on 2026-10-30.

Source: https://spreadsheetpractice.com/formulas/extract-file-extension
