Google Sheets Sort Function: How It Works

How-to basics · Updated November 23, 2026

The Google Sheets SORT function is a built-in formula that rearranges rows in a range based on one or more columns, returning a new sorted array without altering your original data. For example, =SORT(A2:B10, 1, TRUE) sorts the range A2:B10 by the first column in ascending order. Unlike the Sort menu command (Data > Sort range), which physically moves data in place, SORT is a dynamic formula that updates automatically when your source data changes.

Background: Why the SORT Function Exists

Google Sheets introduced the SORT function as part of its dynamic array toolkit, alongside FILTER, UNIQUE, and SEQUENCE. These functions were designed to let users build self-updating reports and dashboards without manual re-sorting. In older spreadsheet software, sorting always required a manual action, and if you added new rows, you had to re-run the sort. With SORT, the output is a separate range that recalculates whenever the input changes, making it ideal for live data like sales logs, attendance sheets, or inventory lists.

Excel has a similar function, also called SORT, but it was added later (in Excel 365 and Excel 2021). In Excel, SORT works the same way, but the function requires the data to be in a contiguous range, and it spills results into neighboring cells. In Google Sheets, SORT works in any web browser and also in the mobile apps, though the mobile interface hides some formula entry options.

How the SORT Function Works

The syntax is straightforward: =SORT(range, sort_column, is_ascending, [sort_column2, is_ascending2, ...]). The range is the data you want to sort, including headers if you include them. The sort_column is a number indicating which column in the range to sort by (1 = first column, 2 = second, etc.). is_ascending is TRUE for A→Z or smallest→largest, FALSE for Z→A or largest→smallest.

Example: With student names in A2:A20 and scores in B2:B20, =SORT(A2:B20, 2, FALSE) returns the list sorted by score from highest to lowest. The result appears in the cell where you enter the formula, spilling down automatically. If you want to sort by two columns, add more pairs: =SORT(A2:C20, 2, TRUE, 3, FALSE) sorts first by column 2 ascending, then by column 3 descending.

Important: The SORT function ignores blank cells in the sort column, and it treats numbers and text separately (numbers come before text in ascending order). Dates are sorted as numbers, so they work naturally.

How to Choose Between SORT Function and the Sort Menu

You have two main ways to sort in Google Sheets: the menu command and the function. Which one you pick depends on your goal.

  • Menu (Data > Sort range or Sort sheet): Use this when you want to permanently rearrange your data. It edits the original cells, and you cannot undo it easily if you close the sheet. Good for one-time cleanup.
  • SORT function: Use this when you need a live, separate view of sorted data. For example, keep a master list in one tab and a sorted summary in another. Changes to the master list automatically update the sorted output.
  • Filter views (Data > Filter views): If you want to sort without changing data and without a formula, a filter view is a lighter option, but it doesn’t create a separate range.

For most dynamic reports, the SORT function is better because it’s transparent and recalculates. But if you need to edit the sorted data directly, you’ll have to copy and paste values first, since the function output is read-only.

Common Problems and Fixes

Users often run into a few recurring issues with SORT:

  • #VALUE! error: This usually means your sort column number is larger than the number of columns in the range. Check that sort_column is within 1 to the column count.
  • Headers getting sorted: If you include header row in the range, it gets sorted too. To keep headers on top, exclude them from the range, or use a separate formula that references only the data rows.
  • Sorting mixed data types: If a column has numbers and text, SORT places all numbers first, then text. To avoid this, ensure consistent data types in each column.
  • Spill range overlap: If the SORT formula’s output would overlap with existing data, you’ll get a #REF! error. Clear the cells below the formula or move the formula to an empty area.
  • Case sensitivity: SORT is case-insensitive by default (it treats “apple” and “Apple” the same). If you need case-sensitive sorting, you’ll need a helper column with a formula like =EXACT(A2, A2) but that doesn’t directly help; actually, you can use a custom order with SORTN or a script, but it’s not built-in.

Comparison: SORT vs. SORTN vs. QUERY

Google Sheets offers several sorting-related functions. Knowing the difference helps you pick the right one.

  • SORT: Returns all rows, sorted by one or more columns. Simple and direct.
  • SORTN: Returns the first N rows after sorting. Useful for top-10 lists. Syntax: =SORTN(range, n, [tie_mode], [sort_column], [is_ascending], ...). Example: =SORTN(A2:B20, 5, 0, 2, FALSE) gives the top 5 scores.
  • QUERY: A powerful SQL-like function that can sort, filter, and aggregate. Sorting is done with the ORDER BY clause: =QUERY(A2:B20, "SELECT A, B ORDER BY B DESC"). QUERY is more flexible but has a steeper learning curve and different syntax rules (commas inside the query string).

For most basic needs, SORT is the easiest. Use SORTN when you only need a few rows. Use QUERY when you need to combine sorting with filtering or grouping.

Costs and Availability

The SORT function is completely free and available to all Google Sheets users, whether you have a personal Google account or a Google Workspace business account. There is no premium tier that unlocks it. It works in the web browser, Android, and iOS apps, though the mobile apps may require you to type the formula manually if the formula bar is hidden. No special add-ons or extensions are needed.

Safety and Data Integrity

Because SORT returns a copy of the data, it never modifies your original range. This is a safety advantage over the menu sort, which rewrites cells. However, be careful when copying the sorted output: if you copy and paste it elsewhere, it becomes static values, not a live formula. Also, if you delete the source data, the SORT formula will return a #REF! error. Always keep a backup of your original data if you plan to delete or overwrite source rows.

For sensitive data, note that SORT formulas are visible to anyone with edit access to the sheet. If you share a sheet, others can see the formula and the underlying data. Use protected ranges or separate sheets if you need to hide source data.

Alternatives and Advanced Tips

If SORT doesn’t fit your exact need, consider these alternatives:

  • FILTER + SORT combination: Use =SORT(FILTER(A2:B20, B2:B20>50), 2, FALSE) to sort only rows that meet a condition.
  • ARRAYFORMULA with SORT: You can wrap SORT in ARRAYFORMULA, but it’s usually unnecessary because SORT already returns an array.
  • Custom sort order: To sort by a custom list (e.g., “High, Medium, Low”), create a helper column with a numeric rank and sort by that column.
  • Stable sorting: SORT is stable, meaning rows with equal sort keys retain their original order. This is useful when sorting by multiple columns.

For Excel users, the SORT function is available in Excel 365 and Excel 2021, but not in older versions. In Excel, you must enter the formula in a single cell and it spills; if you have dynamic array disabled, you’ll get an error. The syntax is identical to Google Sheets.

Frequently Asked Questions

Does the SORT function change my original data?

No. The SORT function creates a new array in the cell where you enter the formula. Your original data remains untouched. This is different from using Data > Sort range, which physically reorders the cells.

How do I sort by column C in descending order?

Use =SORT(A2:C20, 3, FALSE). The 3 tells Sheets to sort by the third column in the range, and FALSE means descending (largest to smallest). Adjust the range to match your data.

Can I sort by two columns at once?

Yes, add additional sort column pairs. For example, =SORT(A2:C20, 2, TRUE, 3, FALSE) sorts by column B ascending, then by column C descending. The first sort key takes priority.

Why does my SORT formula return #VALUE!?

This error usually means the sort column number is out of range. For instance, if your range has 3 columns and you use =SORT(A2:C20, 4, TRUE), column 4 doesn’t exist. Check that the sort column number is between 1 and the number of columns in your range.

Can I sort and keep the header row on top?

Yes, but you must exclude the header row from the range. If your headers are in row 1 and data starts in row 2, use =SORT(A2:B20, 1, TRUE). The formula output will start in the cell where you enter it, so place it below the header row.

Is the SORT function available in Excel?

Yes, but only in Excel 365 and Excel 2021. Older versions (Excel 2019 and earlier) do not have the SORT function. In those versions, you would use the Sort dialog box or a pivot table.

Related

Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.

More in How-to basics

Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources

Spotted an error in this guide? Let us know.