Space complexity is defined as how much additional space the algorithm needs in terms of the N elements. And even though according to the docs, the sort method sorts a list in place, it does use some additional space, as stated in the description of the implementation:

timsort can require a temp array containing as many as N//2 pointers, which means as many as 2*N extra bytes on 32-bit boxes. It can be expected to require a temp array this large when sorting random data; on data with significant structure, it may get away without using any extra heap memory.

Therefore the worst case space complexity is O(N) and best case O(1)

Answer from damores on Stack Overflow
๐ŸŒ
Quora
quora.com โ€บ What-is-the-time-complexity-of-the-Python-built-in-sorted-function
What is the time complexity of the Python built-in sorted function? - Quora
Answer (1 of 5): {n}\log_{2}{n}. As others have mentioned, the built-in sorting algorithm of Python uses a special version of merge sort, called Timsort, which runs in {n}\log_{2}{n} time. Thatโ€™s pretty good; we generally canโ€™t get much better than {n}\log_{2}{n} (with the exception of sorts wh...
๐ŸŒ
Medium
medium.com โ€บ @bhargavacharanreddy โ€บ do-you-know-the-time-complexity-of-pythons-sorted-function-1ae9e7d712b1
Do you know the time complexity of Pythonโ€™s Sorted() function? - Charan - Medium
February 1, 2022 - This sorted function is based on the Time sort algorithm which was created by Tim peters. This particular soring algorithm is a hybrid sorting algorithm based on insertion and mergesort algorithms internally. This is really fascinating. Following are the time and space complexities of this ...
๐ŸŒ
CodeRivers
coderivers.org โ€บ blog โ€บ python-sort-time-and-space-complexity
Python Sort Time and Space Complexity: A Comprehensive Guide - CodeRivers
April 6, 2025 - Similar to time complexity, it is expressed in Big O notation. For example: - O(1) (Constant Space): The algorithm uses a fixed amount of extra memory, regardless of the input size. - O(n) (Linear Space): The amount of extra memory used is proportional to the size of the input. sorted(): This ...
Find elsewhere
๐ŸŒ
Wikipedia
en.wikipedia.org โ€บ wiki โ€บ Timsort
Timsort - Wikipedia
February 17, 2026 - This optimization reduces the number of required element movements, the running time and the temporary space overhead in the general case. Example: two runs [1, 2, 3, 6, 10] and [4, 5, 7, 9, 12, 14, 17] must be merged. Note that both runs are already sorted individually.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ space-complexity-of-list-operations-in-python
Space Complexity of List Operations in Python - GeeksforGeeks
July 23, 2025 - If a new list is created for sorting (e.g., with sorted()), the space complexity would be O(n), since a new sorted list is returned. reverse() method is used to reverse the elements of a list in place.
๐ŸŒ
Pythoncomplexity
pythoncomplexity.com โ€บ builtins โ€บ sorted
Sorted - Python Big-O: Time & Space Complexity
# O(n*k + n log n) - key computed once per element, then cached def expensive_key(x): # O(m) - expensive computation return sum(range(x)) numbers = list(range(1000)) result = sorted(numbers, key=expensive_key) # Complexity: O(n*m + n log n) - key called n times, then n log n comparisons # Better: ...
๐ŸŒ
Analytics Vidhya
analyticsvidhya.com โ€บ home โ€บ complete guide on sorting techniques in python [2025 edition]
Complete Guide on Sorting Techniques in Python [2025 Edition] - Analytics Vidhya
November 28, 2024 - Stability refers to whether the ... sorting algorithms is the Quicksort algorithm. It has an average time complexity of O(n log n) and a space complexity of O(log n)....
๐ŸŒ
Medium
medium.com โ€บ @manyu.a โ€บ exploring-selection-sort-time-and-space-complexity-analysis-in-python-day-1-e4ff224ad12f
Exploring Selection Sort: Time and Space Complexity Analysis in Python โ€” Day 1 | by Abhimanyu Vashistha | Medium
April 21, 2024 - Python Implementation: Below is a Python implementation of Selection Sort for reference: def selection_sort(arr): n = len(arr) for i in range(n): min_index = i for j in range(i + 1, n): if arr[j] < arr[min_index]: min_index = j arr[i], arr[min_index] = arr[min_index], arr[i] Selection Sort, despite its simplicity, serves as a foundational algorithm in the study of sorting techniques. Understanding its time and space complexity in Python helps in making informed decisions about its usage, especially when dealing with small datasets or educational purposes.
๐ŸŒ
PrepBytes
prepbytes.com โ€บ home โ€บ python โ€บ sort function in python
Sort() Function in Python
July 13, 2023 - Python sort() function time complexity is O(n log n) for average and worst cases.
๐ŸŒ
Software Testing Help
softwaretestinghelp.com โ€บ home โ€บ python โ€บ python sort: sorting methods and algorithms in python
Python Sort: Sorting Methods And Algorithms In Python
April 1, 2025 - Best Case: The best time complexity for Heap sort isO(n log(n)). ... It is mostly used because of its productivity. It can be implemented as an in-place algorithm. It does not require large storage.
๐ŸŒ
CodeSignal
codesignal.com โ€บ learn โ€บ courses โ€บ sorting-and-searching-algorithms-in-python โ€บ lessons โ€บ mastering-quick-sort-implementation-and-complexity-analysis-in-python
Mastering Quick Sort: Implementation and Complexity ...
With Quick Sort, the space complexity stems primarily from its recursive nature. Each recursive call requires additional space on the call stack, proportional to the depth of recursion.
๐ŸŒ
Real Python
realpython.com โ€บ sorting-algorithms-python
Sorting Algorithms in Python โ€“ Real Python
November 27, 2023 - O(n), then, is the best-case runtime complexity of bubble sort. But keep in mind that best cases are an exception, and you should focus on the average case when comparing different algorithms.
๐ŸŒ
Python
wiki.python.org โ€บ moin โ€บ TimeComplexity
TimeComplexity - Python Wiki
The Average Case times listed for dict objects assume that the hash function for the objects is sufficiently robust to make collisions uncommon. The Average Case assumes the keys used in parameters are selected uniformly at random from the set of all keys. Note that there is a fast-path for dicts that (in practice) only deal with str keys; this doesn't affect the algorithmic complexity, but it can significantly affect the constant factors: how quickly a typical program finishes.
๐ŸŒ
Built In
builtin.com โ€บ machine-learning โ€บ fastest-sorting-algorithm
Sorting Algorithms: Slowest to Fastest | Built In
Hence the total time complexity is O(n log n). Since we are recursively calling the MergeSort function, an internal stack is used to store these function calls. There will be at most n calls in the stack, and hence, the space complexity will ...