# How to extract the domain from a URL in Excel

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

**Excel:** `=SUBSTITUTE(TEXTBEFORE(TEXTAFTER(A2,"//",,,,A2)&"/","/"),"www.","")` (Microsoft 365 only)

**Google Sheets:** `=REGEXEXTRACT(A2,"^(?:https?://)?(?:www\.)?([^/?#]+)")`

## Example

Sample data (row 1 is the header):

| A | B |
| --- | --- |
| URL | Domain |
| https://www.northwind.example/shop/chairs?id=42 |  |
| http://contoso.example/about |  |
| https://blog.fabrikam.example/2026/03/launch |  |
| www.litware.example |  |
| https://adatum.example |  |
| https://www.proseware.example/contact/ |  |

Formula in B2, filled to B7: `=SUBSTITUTE(TEXTBEFORE(TEXTAFTER(A2,"//",,,,A2)&"/","/"),"www.","")`

Result: northwind.example; contoso.example; blog.fabrikam.example; litware.example; adatum.example; proseware.example

## 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 `#`.

## Other ways

- `=SUBSTITUTE(LEFT(MID(A2,IFERROR(FIND("//",A2)+2,1),LEN(A2))&"/",FIND("/",MID(A2,IFERROR(FIND("//",A2)+2,1),LEN(A2))&"/")-1),"www.","")`: 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(…,":",,,,…)`.

## 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),"/",,,,"")`.

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-domain-from-url
