FormulaCraft

How to extract a file extension from a filename in Excel and Google Sheets

Topic:Text manipulation
Excel & Google Sheets
=RIGHT(A2,LEN(A2)-FIND("*",SUBSTITUTE(A2,".","*",LEN(A2)-LEN(SUBSTITUTE(A2,".","")))))

Verified example

Computed by a real spreadsheet engine on the sample data below.

Filename
report.xlsx
image.final.png
data.csv
archive.tar.gz

=RIGHT(A2,LEN(A2)-FIND("*",SUBSTITUTE(A2,".","*",LEN(A2)-LEN(SUBSTITUTE(A2,".","")))))xlsx

Try it with your data

Edit the grid or formula, then run it through a real spreadsheet engine — no signup.

Sample data — click any cell to edit

Runs server-side · free · no signup

Step by step

  1. 1Count the number of periods in the filename: LEN(A2)-LEN(SUBSTITUTE(A2,".","")).
  2. 2Use SUBSTITUTE to replace only the last period with a unique marker (*): SUBSTITUTE(A2,".","*",count_of_periods).
  3. 3Use FIND to locate the * marker and determine the position of the last period.
  4. 4Extract everything after it with RIGHT: =RIGHT(A2, LEN(A2)-position_of_last_period).
  5. 5Combined: =RIGHT(A2,LEN(A2)-FIND("*",SUBSTITUTE(A2,".","*",LEN(A2)-LEN(SUBSTITUTE(A2,".",""))))).

Tips

Need it for your exact data?

Describe your columns in plain English and get the precise formula for your sheet, with the right Excel or Sheets syntax.

Frequently asked

What if the filename has no extension?

FIND will error because there's no period. Wrap in IFERROR(…,"") to return an empty string for extensionless files.

What about double extensions like .tar.gz?

The formula returns 'gz' (after the last dot). If you need 'tar.gz', adjust the SUBSTITUTE count to target the second-to-last period.

More on Text manipulation

See all →

Formulas used

Written and reviewed by FormulaCraft Team. Each formula on this page is run through our verification engine before publishing.

Last reviewed: