Extract the File Extension from a Filename

Excel Formulas › Text

All versions

Grabbing a file's extension means finding the text after the last dot — easy with TEXTAFTER, and still doable in older Excel with a SUBSTITUTE trick.


Quick formula: TEXTAFTER with a -1 instance grabs the text after the final dot:
=TEXTAFTER(A2,".",-1)

The -1 tells TEXTAFTER to count delimiters from the end, so multi-dot names work.

Functions used (tap for the full reference guide):

The example

Filenames with one or more dots; you want just the extension.

AB
1FilenameExtension
2report.xlsxxlsx
3q3.final.docxdocx
4photo.backup.jpgjpg

The formula

Modern Excel makes this one function:

=TEXTAFTER(A2,".",-1) // -1 = after the last dot

How it works

Why the -1 matters:

  1. TEXTAFTER returns the text after a delimiter you choose — here a dot.
  2. A positive instance counts from the left; a negative instance counts from the right.
  3. -1 means 'the last dot', so q3.final.docx correctly returns docx.
  4. In older Excel, the SUBSTITUTE/REPT trick below does the same job.

Add LOWER() around it if you want extensions normalised to lowercase.

Try it: interactive demo

Interactive

Type a filename — the extension after the last dot appears live.

Variations

Works in older Excel

Push the last segment to the right with padded spaces, then trim.

=TRIM(RIGHT(SUBSTITUTE(A2,".",REPT(" ",50)),50))

Get the name without extension

TEXTBEFORE with -1 returns everything before the final dot.

=TEXTBEFORE(A2,".",-1)

Pitfalls & errors

A filename with no dot makes TEXTAFTER return #N/A. Wrap it in IFERROR to show a blank or the whole name.

Hidden double extensions (file.xlsx.txt) return the real last one (txt) — useful for spotting mislabelled files.

Practice workbook

📊
Download the free Extract the File Extension from a Filename practice workbook
Edit the yellow filenames; the Extension column re-parses using a version that works in any Excel.

Frequently asked questions

Why not just take the last three characters?
Extensions vary in length (jpg, xlsx, json), so a fixed RIGHT(...,3) breaks. Splitting on the last dot is reliable.
What if there's no extension?
TEXTAFTER returns #N/A; wrap it in IFERROR(...,"") to leave the cell blank instead.
Does this work with full file paths?
Yes — the last dot is in the filename, so a path like C:\\docs\\a.b.pdf still returns pdf.

Stop fighting formulas. Learn them in a day.

This recipe is one of hundreds of real-world formulas we teach. Our Excel Formulas & Functions class covers lookups, logic, text, and dynamic arrays hands-on — live in Dallas–Fort Worth, Houston, Austin, Oklahoma City, Denver, or online.

See the Formulas & Functions Class

Function references: TEXTAFTERRIGHTSUBSTITUTE