Sorting data is one of the most common things you'll do in any spreadsheet. Whether you need to rank sales reps, organize inventory alphabetically, or pull the top 10 results from a dataset, Google Sheets gives you two powerful functions: SORT and SORTN. The google sheets sort function creates a dynamic, auto-updating sorted copy of your data — and once you pair it with SORTN, FILTER, or UNIQUE, your spreadsheets practically organize themselves.

In this guide, you'll learn the exact syntax for both functions, walk through practical examples, and discover when to use formula-based sorting versus the manual Data > Sort range menu.

Key Takeaways:SORT returns a dynamically sorted copy of your data that updates automaticallySORTN lets you extract the top or bottom N results with four tie-handling modesCombine SORT with FILTER or UNIQUE for powerful one-formula data pipelinesFormula-based sorting keeps your original data intact — manual sort modifies it permanently

SORT Function Syntax

The SORT function returns a sorted version of a range or array. Here's the full syntax (you can also find it in the Google Sheets function list):

=SORT(range, sort_column, is_ascending, [sort_column2, is_ascending2, ...])
ParameterRequiredDescription
rangeYesThe data range or array to sort
sort_columnYesColumn index (1 = first column, 2 = second, etc.) to sort by
is_ascendingYesTRUE for A→Z / smallest first; FALSE for Z→A / largest first
sort_column2, is_ascending2NoAdditional sort columns for multi-level sorting

A few things to note: the sort_column number is relative to the range you provide, not the sheet. So if your range starts at column C, sort_column 1 refers to column C. And unlike manual sorting, the SORT function outputs results to a new location — your original data stays untouched.

SORT Function Examples

Sort by One Column

Let's say you have a sales table in A1:C10 with columns Name, Region, and Revenue. To sort by revenue from highest to lowest:

=SORT(A2:C10, 3, FALSE)

This sorts the entire range by the third column (Revenue) in descending order. Every time you update a revenue figure, the sorted output updates instantly.

Sort by Multiple Columns

Need to sort by Region first (A→Z), then by Revenue within each region (highest first)? Just add more pairs:

=SORT(A2:C10, 2, TRUE, 3, FALSE)

Google Sheets processes the sort columns left to right — it groups by Region first, then within each region it ranks by Revenue descending. You can chain as many sort levels as you need.

SORT with FILTER

Combining SORT with FILTER is one of the most useful patterns in Google Sheets. For example, to show only the "West" region sorted by revenue:

=SORT(FILTER(A2:C10, B2:B10="West"), 3, FALSE)

FILTER narrows down the rows first, and SORT organizes the results. This is especially powerful for dashboards where you want filtered, ranked views of your data without touching the source.

SORT with UNIQUE

The UNIQUE function removes duplicate rows, and wrapping it with SORT gives you a clean, alphabetically ordered list:

=SORT(UNIQUE(B2:B100))

This pulls every distinct region name from column B and sorts them A→Z. It's a quick way to build dropdown lists or summary headers. When you omit the sort_column and is_ascending parameters, SORT defaults to sorting by the first column in ascending order.

SORTN Function — Get Top or Bottom N Results

While SORT returns all rows sorted, SORTN returns only the top (or bottom) N rows. This is the function you want when you need "top 5 sales reps" or "bottom 10 products by margin."

=SORTN(range, n, display_ties_mode, sort_column, is_ascending, [sort_column2, is_ascending2, ...])
ParameterRequiredDescription
rangeYesThe data range or array
nNoNumber of rows to return (default: 1)
display_ties_modeNoHow to handle tied values (0, 1, 2, or 3)
sort_columnNoColumn index to sort by
is_ascendingNoTRUE or FALSE

Display Ties Modes Explained

The display_ties_mode parameter controls what happens when multiple rows share the same value in the sort column. This is the part most people overlook:

ModeBehaviorExample (top 3 from scores: 90, 90, 85, 80)
0 (default)Return exactly N rows. Ties are broken arbitrarily.Returns 3 rows: 90, 90, 85
1Return N rows plus any ties with the Nth row.Returns 3 rows: 90, 90, 85 (no tie at position 3)
2Return at most N rows, but remove duplicates in sort column.Returns 3 rows: 90, 85, 80 (deduplicates the 90s)
3Return N distinct values plus any ties with the Nth value.Returns 4 rows: 90, 90, 85, 80 (3 distinct values, but includes both 90s)

Mode 0 works for most scenarios. Use mode 1 when you can't afford to exclude tied records (think competition rankings). Mode 2 is great for deduplication. Mode 3 is perfect when you want N distinct score levels but need to show everyone at each level.

SORTN Examples

Top 5 Sales Reps by Revenue

With a table in A1:C50 (Name, Region, Revenue), here's how to pull the top 5 performers:

=SORTN(A2:C50, 5, 0, 3, FALSE)

This returns exactly 5 rows, sorted by column 3 (Revenue) in descending order. If two reps are tied at position 5, one gets cut — mode 0 is strict about the count.

Want to include ties? Switch to mode 1:

=SORTN(A2:C50, 5, 1, 3, FALSE)

Now if three reps are tied at position 5, you'll get 7 rows instead of 5. This is fairer for leaderboards.

Bottom 10 Products by Margin

To find underperforming products, sort ascending and grab the bottom 10:

=SORTN(A2:D100, 10, 0, 4, TRUE)

Since is_ascending is TRUE, the lowest margins appear first, and SORTN clips the result to 10 rows. This gives you an instant "needs attention" list.

Remove Duplicates and Keep First Occurrence

SORTN with mode 2 is a powerful deduplication tool. Say column A has customer names that repeat across multiple orders, and you want one row per customer (keeping the one with the highest order value in column C):

=SORTN(SORT(A2:C200, 3, FALSE), 9^9, 2, 1, TRUE)

Here's the trick: first, SORT orders everything by revenue descending so the biggest order per customer comes first. Then SORTN with 9^9 (a very large number meaning "return all") and mode 2 deduplicates by column 1 (customer name). The result: one row per customer, showing their largest order. This technique pairs well with large datasets — and if you're importing CSV or Excel files with thousands of rows into Google Sheets, SmoothSheet handles the import via server-side processing so your browser doesn't freeze.

SORT vs Manual Sort (Data > Sort Range) — When to Use Each

Google Sheets gives you two ways to sort: the SORT/SORTN functions and the manual menu at Data > Sort range. They serve different purposes.

FeatureSORT / SORTN FunctionData > Sort Range
Output locationSeparate cells (new range)Modifies data in-place
Auto-updatesYes — recalculates on every changeNo — one-time sort
Original dataPreservedPermanently rearranged
Top/Bottom NYes (SORTN)No
Combine with FILTERYesNo
Ease of useRequires formula knowledgePoint-and-click
Performance on large dataCan slow down with 50K+ rowsInstant (one-time operation)

Use SORT/SORTN when: you need a live, auto-updating sorted view, want to combine sorting with other functions, or need top/bottom N results. Use manual sort when: you just need a quick one-time rearrangement and don't mind modifying the original data.

For large datasets, keep in mind that formula-based sorting recalculates every time you edit the sheet. If you're working with tens of thousands of rows imported from CSV files, it helps to structure your data efficiently. The CSV Transpose & Pivot tool can reshape your data before import so you start with a cleaner structure.

Also worth noting: the QUERY function has its own ORDER BY clause that works similarly to SORT but lets you write SQL-like statements. If you're already using QUERY for filtering and aggregation, adding sorting within the same QUERY formula keeps things cleaner than nesting SORT around it.

FAQ

Can I sort by color or font style in Google Sheets?

No. The SORT and SORTN functions only sort by cell values, not by formatting. The manual Data > Sort range option also sorts by values only. If you need to sort by cell color, you'd need a helper column with a script (using getBackground()) to extract color codes, then sort by that column.

Why does my SORT formula return a #REF! error?

A #REF! error usually means the output is trying to spill into cells that already contain data. SORT and SORTN are array functions — they need enough empty cells below (and to the right) to display all results. Clear the cells in the output area, or move your formula to a spot with enough room. For more on fixing reference errors, see our guide on fixing #REF! errors in Google Sheets.

What is the difference between SORT and SORTN?

SORT returns all rows from the range, just reordered. SORTN returns only the top or bottom N rows and includes a display_ties_mode parameter for handling tied values. Use SORT when you want a full sorted copy; use SORTN when you only care about a specific number of results.

Can I use SORT with data imported from CSV or Excel files?

Absolutely. SORT works on any data range in your sheet, regardless of how it got there — whether typed manually, pasted, or imported from CSV/Excel. If you're importing large files (100K+ rows), SmoothSheet processes the upload server-side so your browser stays responsive, and once the data is in your sheet, SORT and SORTN work on it just like any other range.

Conclusion

The SORT function gives you dynamic, auto-updating sorted views of your data, and SORTN takes it further by letting you extract exactly the top or bottom N results with fine-tuned tie handling. Combined with FILTER and UNIQUE, these functions turn Google Sheets into a surprisingly powerful data analysis tool — no manual re-sorting required.

Start with a simple =SORT(range, column, FALSE) to rank your data, then experiment with SORTN's display ties modes to get exactly the results you need. For more formula techniques, check out our QUERY function guide to add SQL-like sorting and filtering to your toolkit.