ExcelReady
CourseMock testsFunction guidesBlog
Start freeStart learning for free
ExcelReady

Be Excel-ready before day one. Hands-on practice in your browser, with instant feedback.

Learn

  • Course
  • Mock tests
  • Function guides
  • Blog

Test prep

  • Excel level test
  • Excel test practice
  • Free screening quiz
  • Certificate

Company

  • About
  • Editorial policy
  • Contact
  • Terms
  • Privacy

© 2026 ExcelReady. All rights reserved.

  1. Blog
  2. Text
  3. Extract the Domain From a URL in Excel

Extract the Domain From a URL in Excel

By ExcelReady Team·Updated November 3, 2026·7 min read

The short answer

To extract the domain from a URL in Excel, take the text after the "//" of https:// and before the next "/", which starts the page path. In Microsoft 365 or Excel 2024, use =TEXTBEFORE(TEXTAFTER(A2,"//")&"/","/"). In any version, use =MID(A2,FIND("//",A2)+2,FIND("/",A2&"/",FIND("//",A2)+2)-FIND("//",A2)-2). Wrap either one in SUBSTITUTE(...,"www.","") to drop the www part.

Key takeaways

  • A URL's domain sits between the "//" after the protocol and the first "/" of the path.
  • Adding "/" to the end of the URL (A2&"/") stops errors on URLs that have no path.
  • SUBSTITUTE(...,"www.","") removes www; TEXTBEFORE with several delimiters also strips ports and query strings.
  • TEXTAFTER(host,".",-2) gives the last two parts of a domain, but not for endings like co.uk.
On this page+
  1. How a URL splits into parts
  2. Extract the domain from a URL with TEXTAFTER and TEXTBEFORE
  3. Extract the domain with MID and FIND (any version)
  4. Remove www from the domain
  5. Get the root domain without subdomains
  6. Get the page path instead
  7. Count links by domain
  8. Why your domain formula returns an error
  9. Practise it

To extract the domain from a URL in Excel, take the text after the // of the protocol and before the next /. In Microsoft 365 that is =TEXTBEFORE(TEXTAFTER(A2,"//")&"/","/"); in any version, MID and FIND do the same job. This guide is for anyone cleaning a list of web links, from marketing reports to backlink audits, and it shows how to drop www, ports and query strings too.

How a URL splits into parts#

A URL has a fixed order of parts, and the domain is always the piece right after //:

PartExampleEnds at
Protocolhttps://The //
Host (domain)www.contoso.comThe next /, ?, # or :
Port (rare):8080The next /
Path/blog/postThe ?
Query string?id=3The end

So the job is: find //, then find the first / after it, and take what's in between. That makes URLs trickier than email addresses, which have exactly one @. If you need the domain from an email instead, see how to extract the domain from an email address.

All the examples use this list in A2:A6:

ADomain wanted
2https://www.contoso.com/blog/post?id=3contoso.com
3http://shop.fabrikam.net/cartshop.fabrikam.net
4https://contoso.co.uk:8080/logincontoso.co.uk
5www.northwindtraders.com/aboutnorthwindtraders.com
6https://tailspintoys.com?ref=emailtailspintoys.com

Extract the domain from a URL with TEXTAFTER and TEXTBEFORE#

In Microsoft 365 or Excel 2024, two nested functions do it. TEXTAFTER takes everything after //, and TEXTBEFORE keeps everything before the next /:

Excel formula
=TEXTBEFORE(TEXTAFTER(A2,"//")&"/","/")

For A2 this returns www.contoso.com. The &"/" adds a slash to the end, so a URL with no path, like https://tailspintoys.com, still has a / to stop at. Without it, TEXTBEFORE would return #N/A.

The guide to TEXTBEFORE and TEXTAFTER explains both functions, and you can practise them in the TEXTBEFORE and TEXTAFTER lesson.

Handle URLs without https://#

Row 5 has no protocol, so TEXTAFTER can't find // and returns #N/A. Its sixth argument, if_not_found, fixes that. Tell it to return the whole URL instead:

Excel formula
=TEXTBEFORE(TEXTAFTER(A2,"//",,,,A2)&"/","/")

The four commas skip the optional arguments in between. Now row 5 returns www.northwindtraders.com.

Strip ports and query strings too#

TEXTBEFORE accepts a list of delimiters in curly braces and stops at whichever comes first. Add ?, # and : to the list:

Excel formula
=TEXTBEFORE(TEXTAFTER(A2,"//",,,,A2)&"/",{"/","?","#",":"})

Row 4 now returns contoso.co.uk instead of contoso.co.uk:8080, and row 6 returns tailspintoys.com instead of tailspintoys.com?ref=email.

Extract the domain with MID and FIND (any version)#

In Excel 2021 or older, use MID to cut out the text between two positions, and FIND to locate them. It's easiest to understand in three helper cells:

CellFormulaResult for A2What it finds
C2=FIND("//",A2)+29First character of the domain
D2=FIND("/",A2&"/",C2)24The next /, searching from C2
E2=MID(A2,C2,D2-C2)www.contoso.comThe text in between

FIND's third argument tells it where to start searching, so it skips the two slashes in https://. Put it all in one cell by replacing C2 and D2 with their formulas:

Excel formula
=MID(A2,FIND("//",A2)+2,FIND("/",A2&"/",FIND("//",A2)+2)-FIND("//",A2)-2)

For URLs that might lack a protocol, use IFERROR(FIND("//",A2)+2,1) as the start, so the domain is taken from the first character. The FIND function guide and the MID function guide show both syntaxes, and the article on FIND vs SEARCH explains how the two differ (FIND is case-sensitive and has no wildcards). You can also practise FIND and SEARCH in a live sheet.

Remove www from the domain#

Wrap either formula in SUBSTITUTE to delete www.:

Excel formula
=SUBSTITUTE(TEXTBEFORE(TEXTAFTER(A2,"//",,,,A2)&"/","/"),"www.","")

Row 2 now gives contoso.com. SUBSTITUTE replaces every www. it finds, which is fine for real host names. If you want to remove it only from the start, test the first four characters instead: =IF(LEFT(B2,4)="www.",MID(B2,5,LEN(B2)),B2), where B2 holds the host. See the SUBSTITUTE function guide for more.

Get the root domain without subdomains#

Sometimes you want fabrikam.net, not shop.fabrikam.net. Take the last two dot-separated parts with a negative instance number, which counts from the end:

Excel formula
=TEXTAFTER(B2,".",-2,,,B2)

Here B2 holds the host. shop.fabrikam.net becomes fabrikam.net, and the fallback returns contoso.com unchanged when it has only one dot. Be careful with two-part endings: contoso.co.uk would become co.uk. Excel has no list of these endings, so check them by hand or with a small lookup table.

Get the page path instead#

The same pieces give you the rest of the URL. Everything after the domain's first / is the path:

Excel formula
=TEXTAFTER(TEXTAFTER(A2,"//",,,,A2),"/",,,,"")

Row 2 returns blog/post?id=3, and a URL with no path returns an empty cell instead of an error. To cut off the query string as well, see how to remove text after a character. For more patterns like this, the guide to extracting text between two characters is a good next read.

Count links by domain#

Once each URL has a clean domain in column B, counting is simple:

Excel formula
=COUNTIF(B2:B500,"contoso.com")

For a full summary in Microsoft 365, list each domain once with =UNIQUE(B2:B500) in D2, then count each one in E2 with =COUNTIF(B2:B500,D2#). Always clean the domains first: Contoso.com and contoso.com count together because COUNTIF ignores case, but www.contoso.com does not, which is why removing www. matters.

Why your domain formula returns an error#

Each error points to a specific problem in the URL or the formula:

What you seeLikely causeFix
#VALUE! from the MID versionThe URL has no //Use IFERROR(FIND("//",A2)+2,1) as the start
#N/A from TEXTAFTERThe URL has no //Add the if_not_found argument: TEXTAFTER(A2,"//",,,,A2)
#N/A from TEXTBEFOREThe URL has no / after the domainAdd &"/" before TEXTBEFORE looks for it
#NAME?TEXTBEFORE or TEXTAFTER in Excel 2021 or olderUse the MID and FIND version
Domain still has spacesSpaces were copied with the URLWrap A2 in TRIM first

Blank cells return errors too. Wrap the finished formula in IFERROR(...,"") so empty rows stay empty, but only after you've checked the real URLs work, because IFERROR also hides genuine mistakes.

Practise it#

Text extraction is a common task in data and marketing tests. Practise TEXTBEFORE and TEXTAFTER in a live spreadsheet: you split real text at a delimiter and each answer is checked instantly. Then practise FIND and SEARCH to build the MID version that works in every Excel, and try the exercise on this page.

Try it yourself

This is a live spreadsheet. Type the formula in the green cell and press Enter.

Get the bare domain from the URL in A2. In B2, use MID and FIND to take the text between "//" and the next "/" (search A2&"/"), then wrap it in SUBSTITUTE to remove "www.".

fx
ABCD
1
Page URL
Domain
2
https://www.contoso.com/blog/post?id=3
3
http://shop.fabrikam.net/cart
4
https://tailspintoys.com/
5
6
7

Tip: Start at FIND("//",A2)+2. The length is FIND("/",A2&"/",start) minus start. Then SUBSTITUTE(…,"www.","").

Practise this in a lesson

LessonTEXTBEFORE and TEXTAFTERSplit emails, "Last, First" names and file paths at a delimiter with TEXTBEFORE and TEXTAFTER, including picking which occurrence to split at.LessonFIND and SEARCHLocate a character or word inside text with FIND or SEARCH, then use that position to split names and pull out order numbers.Function guideFINDLocate a character inside text with Excel's FIND, then use it with LEFT, MID and RIGHT. Case rules, #VALUE! fixes and a live exercise.Function guideMIDPull characters from any position with Excel's MID. Extract IDs, email domains and text between brackets with FIND. Examples and live practice.Function guideSUBSTITUTESwap or strip characters with Excel's SUBSTITUTE: clean phone numbers, change one occurrence and count characters with LEN. Practice it live.

Frequently asked questions

How do I get the domain name from a URL in Excel?

+

In Microsoft 365 or Excel 2024, use =TEXTBEFORE(TEXTAFTER(A2,"//")&"/","/"). In older versions, use MID with FIND to take the text between "//" and the next "/".

How do I remove https:// and www from a URL in Excel?

+

Take the text after "//" with TEXTAFTER or MID, then remove www. with SUBSTITUTE: =SUBSTITUTE(TEXTAFTER(A2,"//"),"www.",""). Add TEXTBEFORE to also cut the page path.

How do I extract the domain when some URLs have no https://?

+

Give TEXTAFTER a fallback with its sixth argument: TEXTAFTER(A2,"//",,,,A2) returns the whole URL when there is no "//". In older Excel, use IFERROR(FIND("//",A2)+2,1) as the start position.

How do I get the root domain without the subdomain?

+

Use =TEXTAFTER(B2,".",-2,,,B2) on the host name. It returns the last two parts, so shop.fabrikam.net becomes fabrikam.net. It gives the wrong answer for two-part endings like co.uk, so check those by hand.

Sources

  • TEXTAFTER function - Microsoft Support
  • MID, MIDB functions - Microsoft Support
  • SUBSTITUTE function - Microsoft Support

Written and checked by the ExcelReady Team. First published November 3, 2026. The practice exercise runs in the same formula engine as our lessons. Found a mistake? Read our editorial policy or email hello@excelready.app.

On this page

  1. How a URL splits into parts
  2. Extract the domain from a URL with TEXTAFTER and TEXTBEFORE
  3. Extract the domain with MID and FIND (any version)
  4. Remove www from the domain
  5. Get the root domain without subdomains
  6. Get the page path instead
  7. Count links by domain
  8. Why your domain formula returns an error
  9. Practise it

Keep reading

Text· 7 min read

Extract the Domain or Username From an Email in Excel

To extract the domain from an email address, take everything after the @ sign. In Microsoft 365, use =TEXTAFTER(A2,"@"). In any version, use =MID(A2,FIND("@",A2)+1,LEN(A2)). For the username, take everything before the @: =TEXTBEFORE(A2,"@") or =LEFT(A2,FIND("@",A2)-1). Wrap either in IFERROR for cells without an @.

Text· 7 min read

TEXTBEFORE and TEXTAFTER in Excel

TEXTBEFORE returns the text before a delimiter, and TEXTAFTER returns the text after it. =TEXTBEFORE(A2,"@") gives the username of an email, and =TEXTAFTER(A2,"@") gives the domain. A third argument picks which occurrence: -1 means the last one. They need Microsoft 365, Excel for the web or Excel 2024; in older Excel, use LEFT or MID with FIND.

Text· 6 min read

Extract Text Between Two Characters in Excel

To extract text between two characters in Microsoft 365, nest TEXTAFTER inside TEXTBEFORE: =TEXTBEFORE(TEXTAFTER(A2,"("),")") returns what sits between the brackets. In any version, use MID and FIND: =MID(A2,FIND("(",A2)+1,FIND(")",A2)-FIND("(",A2)-1). FIND gives the positions of the two characters, and MID takes the text between them.

More on text

  • How to Extract the First Word in Excel
  • Extract the Last Word From a Cell in Excel
  • Extract Numbers From Text in Excel
  • Find the Nth Occurrence of a Character in Excel
  • Find the Position of Text in a Cell (FIND and SEARCH)
  • How to Format Phone Numbers in Excel
All text articles →

Don't just read about Excel. Do it.

Practise real formulas in a live spreadsheet with instant feedback, right in your browser. Nothing to download.

Start learning for free