Category: FUNCTION | Updated: 2026-11-22

How to Use the MID Function in Google Sheets | Extract Characters from a Specified Position

How to Use the MID Function

The MID function extracts a specified number of characters from a text string starting at a specified position. It is commonly used to pull out middle segments such as a year or department code from standardized ID strings.

Syntax

=MID(string, starting_at, extract_length)
  • string: The source text string or cell reference to extract from (required).
  • starting_at: The starting position from the beginning of the string, as an integer of 1 or greater (required).
  • extract_length: The number of characters to extract from the starting position, as an integer of 0 or greater (required).

Example Using a Table

Here is an example of extracting the 4-digit hire year (4 characters starting at position 4) from employee IDs such as JP-2026-884.

Row Column A (Employee ID) Column B (Result: Hire Year)
1 Employee ID Hire Year
2 JP-2026-884 =MID(A2, 4, 4) → 2026
3 US-2024-102 =MID(A3, 4, 4) → 2024
4 JP-2025-519 =MID(A4, 4, 4) → 2025
  • Formula: =MID(A2, 4, 4)
  • Result: 2026

Counting from the first character—J (1), P (2), - (3), 2 (4)—we specify 4 as the starting position and 4 as the extract length.

Common Errors and Notes

  • Starting Position < 1 or Negative Length Causes #VALUE!: Passing 0 or a negative number for starting_at, or a negative number for extract_length, results in a #VALUE! error.
  • Starting Position Beyond String Length: No error occurs; an empty string "" is returned. If extract_length extends past the end of the string, MID extracts everything from starting_at to the end.
  • No Distinction Between Full-Width and Half-Width Characters: Both starting_at and extract_length count every character equally as 1 character, regardless of whether it is full-width or half-width.

Frequently Asked Questions

Q. Does the starting position in MID count from 0 or 1?

A. It counts from 1. The first (leftmost) character of the text string is position 1.

Q. What should I do if the extraction starting position varies for each row?

A. Embed FIND or SEARCH in the second argument (starting_at). For example, to extract 3 characters right after a hyphen, write "=MID(A2, FIND("-", A2) + 1, 3)".