Spreadsheet Practice

How to extract the domain from a URL in Excel

Excel formula

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

Drop everything up to // and everything from the next /, then remove www.: =SUBSTITUTE(TEXTBEFORE(TEXTAFTER(A2,"//",,,,A2)&"/","/"),"www.","").

Result on the example
one result per row in B2, filled down to B7
Works in
Microsoft 365 only
Google Sheets
Different formula, see below

See it work

The formula is already in B2, filled down to B7. Change any input and the result updates, or edit the formula to experiment.

How it works

TEXTAFTER drops the protocol by returning what follows //; its sixth argument returns the whole URL when there is no protocol. Adding a / to the end means TEXTBEFORE always finds one, so a bare domain like "adatum.example" still works. SUBSTITUTE then removes www..

In Google Sheets, REGEXEXTRACT returns the bracketed part: everything after the optional protocol and www. up to the first /, ? or #.

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

Result"northwind.example"

  1. A2"https://www.northwind.example/shop/chairs?id=42"

    The value in A2.

  2. TEXTAFTER(A2,"//",,,,A2)"www.northwind.example/shop/chairs?id=42"

    TEXTAFTER: Text after a delimiter.

    • textA2"https://www.northwind.example/shop/chairs?id=42"
    • delimiter"//"
    • instance_num(omitted)
    • match_mode(omitted)
    • match_end(omitted)
    • if_not_foundA2"https://www.northwind.example/shop/chairs?id=42"
  3. TEXTAFTER(A2,"//",,,,A2)&"/""www.northwind.example/shop/chairs?id=42/"

    The & operator joins as text.

  4. TEXTBEFORE(TEXTAFTER(A2,"//",,,,A2)&"/","/")"www.northwind.example"

    TEXTBEFORE: Text before a delimiter.

    • textTEXTAFTER(A2,"//",,,,A2)&"/""www.northwind.example/shop/chairs?id=42/"
    • delimiter"/"
  5. SUBSTITUTE(TEXTBEFORE(TEXTAFTER(A2,"//",,,,A2)&"/","/"),"www.","")"northwind.example"

    SUBSTITUTE: Replaces matching text.

    • textTEXTBEFORE(TEXTAFTER(A2,"//",,,,A2)&"/","/")"www.northwind.example"
    • old_text"www."
    • new_text""

In Google Sheets

Google Sheets needs a different formula: =REGEXEXTRACT(A2,"^(?:https?://)?(?:www\.)?([^/?#]+)"). On the same data it gives the same result. Here it is running in Google Sheets mode.

Other ways to do it

Each one was run on the same example sheet.

FormulaResultWhen to use it
=SUBSTITUTE(LEFT(MID(A2,IFERROR(FIND("//",A2)+2,1),LEN(A2))&"/",FIND("/",MID(A2,IFERROR(FIND("//",A2)+2,1),LEN(A2))&"/")-1),"www.","")northwind.example, contoso.example, blog.fabrikam.example…Works in every version: MID starts after the // (or at the first character when there is none), and LEFT stops at the next slash.

Common mistakes

  • Subdomains are kept: "blog.fabrikam.example" stays as it is. See the FAQ for the root domain.
  • A URL with a query but no path, like https://x.example?id=1, keeps the ?id=1 in the Excel formula. Cut it with another TEXTBEFORE(…,"?",,,,…); the Google Sheets pattern already stops at ?.
  • Ports stay attached ("example.com:8080"). Remove them with TEXTBEFORE(…,":",,,,…).

Try it yourself

Same data, empty answer cell. Your formula is graded instantly, then re-checked on changed data, so a typed-in number won't pass.

Extract the domain from a URL

In B2, extract the domain from the URL, without http://, https://, www. or the path. Fill down to B7.

Questions

How do I get the root domain without the subdomain?

Keep the last two parts: =TEXTAFTER(B2,".",-2,,,B2) turns "blog.fabrikam.example" into "fabrikam.example". It gets two-part endings like .co.uk wrong.

How do I get the path instead?

Take what follows the domain: =TEXTAFTER(TEXTAFTER(A2,"//",,,,A2),"/",,,,"").

Checked by running on 2026-10-30: every formula and result on this page was calculated by the Spreadsheet Practice formula engine, in both Excel and Google Sheets modes.