How to Extract Domains From URLs in Excel Using MID and FIND Formulas

📅 Jul 15, 2026 📝 Sarah Miller

Cleaning massive lists of raw URLs in Excel to isolate clean domains is notoriously tedious and prone to manual errors. While standard tools like Text-to-Columns offer basic parsing, they lack real-time adaptability as datasets expand. Implementing a dynamic formula grants you instant, automated extraction that scales effortlessly. However, note this key stipulation: variations in URL protocols (like http:// vs https://) require precise boundary definitions. For instance, extracting "example.com" from https://www.example.com/page demands isolating specific slash and dot characters. Below, we dissect how nesting the MID and FIND functions creates a robust, reusable solution for your workflow.

How to Extract Domains From URLs in Excel Using MID and FIND Formulas

When working with large marketing reports, backlink audits, or web analytics data, you often end up with thousands of raw URLs. Analyzing these URLs as-is can be overwhelming. To draw meaningful insights, you need to group them by website-which means extracting only the root domain or subdomain from the full address.

While Excel offers modern tools like Power Query or Flash Fill for data cleaning, using standard Excel formulas remains the most dynamic, lightweight, and reliable method. When your source data changes, formulas update instantly. In this comprehensive guide, we will walk through how to construct a robust formula to extract a domain from any URL using a combination of the MID and FIND functions.

Anatomy of a URL

Before writing our Excel formulas, we must understand the structure of a URL. A typical URL can contain several components:

  • Protocol: https:// or http://
  • Subdomain: www. or blog.
  • Domain Name: example
  • Top-Level Domain (TLD): .com, .org, or .co.uk
  • Path / Subfolders: /category/page-title
  • Query Parameters: ?utm_source=newsletter

Our goal is to isolate the domain (e.g., www.example.com or example.com) from the surrounding protocol, path, and query strings. Because URLs vary in length and structure, we cannot simply extract a fixed number of characters. We must use dynamic formulas.

Understanding the Core Excel Functions

To build our extraction formula, we will leverage two primary string manipulation functions in Excel: MID and FIND.

1. The MID Function

The MID function returns a specific number of characters from a text string, starting at the position you specify. Syntax:

=MID(text, start_num, num_chars)

  • text: The cell containing the URL.
  • start_num: The position of the first character you want to extract. We will use FIND to calculate this dynamically.
  • num_chars: The number of characters to extract. We will also calculate this dynamically.

2. The FIND Function

The FIND function locates the starting position of a substring within a text string. It is case-sensitive. Syntax:

=FIND(find_text, within_text, [start_num])

  • find_text: The character or text you want to find (e.g., "//" or "/").
  • within_text: The cell containing the URL.
  • start_num (Optional): The character position at which to start searching. This parameter is critical for finding the slash that comes after the domain.

Step-by-Step: Building the Domain Extraction Formula

Let's construct the extraction formula piece by piece, assuming our raw URL is in cell A2 (e.g., https://www.example.com/blog/article-one).

Step 1: Locate the Start of the Domain

The domain starts immediately after the double slashes (//) of the protocol. We can locate the position of these double slashes using:

=FIND("//", A2)

For https://www.example.com/..., the double slashes start at character position 6. Since we want to extract characters starting after the double slashes, we add 2 to this result:

=FIND("//", A2) + 2

This tells Excel that our domain starts at position 8 (which is the first 'w' in 'www').

Step 2: Locate the End of the Domain

The domain ends at the first single forward slash (/) that appears after the protocol. To find this specific slash, we use the optional third argument of the FIND function, instructing Excel to start searching from our domain's starting position:

=FIND("/", A2, FIND("//", A2) + 2)

This formula searches for a forward slash in cell A2, but it bypasses the https:// part because it starts searching from position 8. It successfully locates the slash after .com.

Step 3: Calculate the Length of the Domain

Now that we have the starting position and the ending position, we can calculate the exact length of the domain. Subtract the starting position from the ending position:

=FIND("/", A2, FIND("//", A2) + 2) - (FIND("//", A2) + 2)

For our example, this math computes the exact number of characters comprising www.example.com.

Step 4: Putting It Together with MID

Now we plug these calculations into our MID function:

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

This formula successfully extracts www.example.com from https://www.example.com/blog/article-one.

Handling Edge Cases

While the formula above is highly effective, real-world data contains edge cases that can cause it to return errors. Let's fix those issues.

Edge Case A: URLs with No Path (e.g., https://example.com)

If a URL does not have a trailing slash or subfolder path (e.g., just https://example.com), the second FIND function will fail to locate a third slash and return a #VALUE! error.

To solve this, we can temporarily append a trailing slash ("/") to the URL inside the search parameter using concatenation (& "/"). This guarantees a slash will always be found:

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

Edge Case B: URLs with No Protocol (e.g., www.example.com/page)

If your list contains some URLs that do not start with http:// or https://, the formula will return an error because it cannot find the double slash (//). To make the formula bulletproof for all URL types, we can use an IFERROR statement, or clean the data beforehand by ensuring all URLs have a protocol.

Alternatively, the formula below dynamically handles both protocol and protocol-free URLs:

=IF(ISNUMBER(FIND("//", A2)), MID(A2, FIND("//", A2) + 2, FIND("/", A2 & "/", FIND("//", A2) + 2) - (FIND("//", A2) + 2)), MID(A2, 1, FIND("/", A2 & "/") - 1))

Advanced: Removing "www." from the Domain

If you want to clean your data further by stripping the standard www. prefix so you're left with just the core root domain (e.g., example.com instead of www.example.com), you can wrap your entire extraction formula inside a SUBSTITUTE function:

=SUBSTITUTE(MID(A2, FIND("//", A2) + 2, FIND("/", A2 & "/", FIND("//", A2) + 2) - (FIND("//", A2) + 2)), "www.", "")

The SUBSTITUTE function searches for "www." within your extracted domain and replaces it with nothing (""), leaving you with a clean root domain.

Quick Reference Guide

Objective Excel Formula (Assuming URL in A2)
Extract domain with subdomains (standard) =MID(A2, FIND("//", A2) + 2, FIND("/", A2 & "/", FIND("//", A2) + 2) - (FIND("//", A2) + 2))
Extract domain and remove "www." =SUBSTITUTE(MID(A2, FIND("//", A2) + 2, FIND("/", A2 & "/", FIND("//", A2) + 2) - (FIND("//", A2) + 2)), "www.", "")
Fail-safe formula (handles protocol-free URLs) =IF(ISNUMBER(FIND("//", A2)), MID(A2, FIND("//", A2) + 2, FIND("/", A2 & "/", FIND("//", A2) + 2) - (FIND("//", A2) + 2)), MID(A2, 1, FIND("/", A2 & "/") - 1))

Summary

Extracting domains from paths in Excel using MID and FIND is a highly versatile skill. By understanding how to calculate starting positions and lengths dynamically, you can clean messy marketing datasets, prepare link-building lists, and compile site-level analytics with minimal effort. Bookmark these formulas or save them to your Excel personal workbook to keep them handy for your next data analysis project!

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.