How to Extract the Root Domain From a URL in Excel

📅 Mar 15, 2026 📝 Sarah Miller

Analyzing bloated URL lists during SEO audits is a tedious chore that drains analytical productivity. While digital departments often secure standard funding sources for costly enterprise scraping software, leveraging native Excel capabilities grants immediate, budget-friendly autonomy over your datasets.

Under the stipulation that your data consistently contains standard protocol prefixes (such as https://), this formulaic approach successfully isolates the root domain from complex paths, easily processing sites like github.com/user/repo down to their core.

Below, we will demonstrate the exact nested LEFT, FIND, and SUBSTITUTE formulas required to automate this transformation.

How to Extract the Root Domain From a URL in Excel

In the realms of digital marketing, search engine optimization (SEO), and web analytics, data is often delivered in raw, unorganized heaps. One of the most common data-cleaning challenges involves managing lists of URLs. Whether you are analyzing backlink profiles, auditing website crawls, or tracking referral traffic in Google Analytics, you will frequently find yourself with a list of deep-page URLs when what you actually need is the base domain.

Trimming a URL like https://subdomain.example.com/category/page-title?utm_source=active down to its base domain (e.g., https://subdomain.example.com or simply example.com) is essential for aggregating data, finding patterns, and performing high-level domain analyses. Fortunately, Microsoft Excel offers several powerful formulas and tools to automate this process. In this guide, we will explore the best Excel formulas-ranging from classic, backward-compatible methods to modern Excel 365 functions-to extract and trim URL paths to their base domains.

Anatomy of a URL: What Are We Trimming?

Before writing formulas, it helps to understand the structure of the string we are manipulating. A typical URL consists of several components:

  • Protocol: https:// or http://
  • Subdomain: www. or blog.
  • Domain Name (SLD & TLD): example.com
  • Path: /category/product-page/
  • Query Parameters: ?search=excel& sort=true

Depending on your analytical goals, "trimming to the base domain" might mean keeping the protocol and subdomain (e.g., https://subdomain.example.com) or stripping everything away to get the clean root domain (e.g., example.com). We will cover formulas for both scenarios.


Method 1: The Modern Excel 365 Way (Using TEXTBEFORE)

If you are using Excel 365 or Excel for the Web, extracting the base domain is incredibly straightforward thanks to the introduction of modern text manipulation functions. The most efficient function for this task is TEXTBEFORE.

Formula to Keep the Protocol (e.g., https://example.com)

To extract everything before the third forward slash (/), which marks the end of the domain and the start of the path, use this formula:

=TEXTBEFORE(A2, "/", 3, , , A2)

How It Works:

  • A2: The cell containing the full URL.
  • "/": The; are looking for.
  • 3: The instance of the delimiter. Because URLs begin with http:// or https://, the first two slashes occur immediately after the protocol. The third slash marks the end of the domain.
  • The empty arguments (, ,): These skip optional parameters like match case and match end.
  • The final A2: This is the match_end behavior. If a URL does not have a third slash (e.g., https://example.com), the formula would normally return an error. By setting this argument to A2, Excel safely returns the entire original URL if no path exists.

Method 2: The Classic Excel Formula (Universal Compatibility)

If you are working on an older version of Excel (such as Excel 2016, 2019, or 2021) or need your spreadsheet to be fully backward-compatible with legacy versions, you must rely on a combination of LEFT, FIND, and IFERROR.

The Formula:

=LEFT(A2, IFERROR(FIND("/", A2, 9) - 1, LEN(A2)))

How This Formula Works Step-by-Step:

  1. FIND("/", A2, 9): This searches for the forward slash (/) in cell A2. Crucially, the third argument (9) tells Excel to start searching from the 9th character onward. This safely skips past the protocol prefix (http:// is 7 characters, https:// is 8 characters), ensuring that Excel ignores the double slash after the colon and targets the third slash.
  2. FIND(...) - 1: Once Excel locates the position of the third slash,; subtract 1 so that; capture only the characters *before* that slash.
  3. IFERROR(..., LEN(A2)): If a URL does not have a path (e.g., https://example.com), there is no third slash, and the FIND function will return a #VALUE! error. The IFERROR function catches this and simply returns the length of the entire string (LEN(A2)), meaning the whole URL is preserved.
  4. LEFT(A2, ...): Finally, the LEFT function extracts the specified number of characters starting from the left side of the string.

Method 3: Extracting the Root Domain Only (No Protocol, No Path)

Sometimes, keeping the https:// protocol or the www. subdomain is undesirable. If you want a clean list of root domains (like example.com) to run VLOOKUPs or merge datasets, you need to strip away both the prefix and the suffix.

The Excel 365 LET Formula (Recommended for Readability)

Using the LET function allows us to declare variables, making complex text manipulation formulas dramatically easier to read and debug:

=LET(
    no_protocol, SUBSTITUTE(SUBSTITUTE(A2, "https://", ""), "http://", ""),
    clean_domain, SUBSTITUTE(no_protocol, "www.", ""),
    TEXTBEFORE(clean_domain, "/", 1, , , clean_domain)
)

How It Works:

  • no_protocol: We use nested SUBSTITUTE functions to remove both https:// and http:// from the URL.
  • clean_domain: We strip out the www. prefix if it exists.
  • TEXTBEFORE(...): Finally,; extract everything before the first remaining slash (which is now the slash separating the root domain from the path). If no slash exists, it returns the whole clean string.

The Classic Formula Alternative:

If you do not have Excel 365, you can achieve the exact same clean root domain result using this traditional formula:

=LEFT(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A2,"https://",""),"http://",""),"www.",""),IFERROR(FIND("/",SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A2,"https://",""),"http://",""),"www.",""))-1,LEN(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A2,"https://",""),"http://",""),"www.",""))))

Note: While this classic nested formula looks complex, it operates on the exact same logic of stripping prefixes first and then isolating the characters before the first remaining slash.


Method 4: The Fast, Non-Formula Way (Flash Fill)

If you only need to clean your URL data once and do not require dynamic formulas that update when data changes, Excel's Flash Fill tool is incredibly fast and requires zero coding.

  1. Insert a blank column next to your list of URLs.
  2. In the first cell of the new column (e.g., B2), manually type the exact base domain you want to extract from A2. (e.g., Type example.com).
  3. Press Enter to move to the next row (B3).
  4. Begin typing the base domain for A3. Excel will likely detect the pattern and show a light gray preview of the filled-down column.
  5. If the preview looks correct, press Enter. Alternatively, you can highlight cell B2, drag down to select the range, and press Ctrl + E (or navigate to Data > Flash Fill).

Flash Fill parses the URL structure automatically based on your manual input, instantly cleaning thousands of rows.


Summary of Methods: Which One Should You Choose?

Requirement Best Method Pros / Cons
Keep protocol, simple clean-up (Excel 365) =TEXTBEFORE(A2, "/", 3, , , A2) Highly readable, fast, requires modern Excel.
Keep protocol, legacy compatibility =LEFT(A2, IFERROR(FIND("/", A2, 9) - 1, LEN(A2))) Works on all versions of Excel, slightly complex syntax.
Clean root domain only (no protocol/www) LET function with SUBSTITUTE Creates highly structured, standard domain names for data analysis.
One-time data preparation Flash Fill (Ctrl + E) No formulas required, but will not auto-update if source URLs change.

Conclusion

Trimming URL paths in Excel does not require expensive add-ons or complex scripts. By mastering these formulaic approaches-whether you leverage the modern simplicity of TEXTBEFORE or the absolute compatibility of LEFT and FIND-you can clean web analytics and SEO data in seconds. Choose the formula that matches your version of Excel and your specific format requirements, and enjoy cleaner, more actionable spreadsheets.

Disclaimer:
The documents and templates provided on this page are for informational and illustrative purposes only. They do not constitute professional, legal, or financial advice, and should not be relied upon as such. Because individual circumstances and regulatory requirements vary, these materials may not be suitable for your specific needs. We recommend consulting with a qualified professional before adapting or using any of these examples for official or commercial purposes.