Checking a numeric median against textual sorting
Sorting 1, 2 and 10 as numbers gives a middle value of 2. Sorting the same tokens as text puts 10 before 2 and gives a different middle. This guide shows why the statistics tools sort numerically.
Two orders for the same three tokens
Numerically, the values 1, 2 and 10 are ordered 1 < 2 < 10, and the middle value, the median, is 2. As text, the tokens are compared character by character from the left. The strings "1" and "10" start with the same character, and the shorter one comes first, so "1" precedes "10". Then "10" is compared with "2": the first character 1 comes before 2 in character order, so "10" precedes "2". The text order is "1", "10", "2", and the middle token is "10". Same tokens, same count, two different middles: 2 and 10. The mean, median and mode tool sorts numerically, so it returns 2.
Why text sorting works that way
Text comparison, called lexicographic order, treats each token as a sequence of characters and compares them one at a time using the character codes. Digits come in the order 0 to 9 in ASCII and Unicode, so 1 is below 2, and a string is placed by its first differing character. This is the rule used by dictionaries, and it produces the right order for words. Digits in a number carry positional weight, though, and a longer digit string is a larger number when there are no leading zeros. Lexicographic order ignores that weight, so 9 comes after 10 and 100 comes before 20. Many programming languages default to this order when sorting strings, and a few even sort numbers as text unless told otherwise. JavaScript's Array sort without a comparison function is the best-known case: it converts elements to strings first.
A control with the input shuffled
The second case on the page enters the list as 10, 1, 2 and gets the same median, 2. The median is defined on the sorted values, so the order in which you type them has no effect. This is a useful sanity test for any statistic that claims to be order independent. If you got a different answer after shuffling, the tool would be treating the entries by position or by text. Other statistics, such as the median of a time series by windows or a moving average, do depend on the order, but the plain median, mean, mode, range and percentile do not.
A second example with an even count
Take 1, 2, 10, 20. Numerically the middle two values are 2 and 10, so the median is their average, 6. As text, the order is "1", "10", "2", "20", and the middle two tokens are "10" and "2". There is no average of text, so a text-based tool would either fail or pick one of them. A shorter case is 2, 10, 9: numerically 2, 9, 10 gives a median of 9, while the text order "10", "2", "9" would give "2". These examples show the error can be large, since the text answer is not close to the numeric answer, and it is not even a consistent distance away.
Where text ordering shows up by accident
Spreadsheets sort a column by type, but a column imported as text sorts as text, which is why a list of invoice numbers or ages can appear in the wrong order. Command-line tools such as sort compare text unless asked for numeric order. Databases sort a varchar column lexicographically even if every entry looks like a number. File managers have spent years adding natural sort so that file2 appears before file10. Dates in the ISO 8601 form YYYY-MM-DD are a happy exception: because the fields are fixed width and ordered from largest to smallest, text order matches time order, which is one reason that format is recommended for filenames.
Fixed width can rescue text order
Padding with leading zeros makes text order agree with numeric order for nonnegative integers of the same length: 001, 002, 010 sorts correctly as text. That is why serial numbers and version tags are often zero-padded. The trick fails when the lengths vary, and it does not handle negative numbers or decimals, since the minus sign and the decimal point have their own places in the character order. If you must use a text-based sorter on numbers, pad to a fixed width and handle signs separately. In most cases it is simpler to convert the column to numbers first.
Converting a string column safely
The conversion should preserve valid numbers and report entries that fail to parse, so a stray word or unit does not silently become zero or disappear. Before converting, trim whitespace, decide on the decimal mark and the grouping, and check for placeholder text such as N/A or a dash. Afterward, compare the count of converted values with the count of rows. Keep the original text column next to the converted one, so any entry that looks odd after conversion can be traced to its source, and record how many entries failed and what was done about them. The mismatch between the two is the list of problem entries. Automatic type guessing in import tools can hide this step, and the median of a column that was partly converted can be computed from fewer values than you think.
Mixed-length entries in practice
The error is easiest to make with identifiers and survey codes imported from files. Imagine a column of ages typed in a form: 7, 12, 9, 65, 41. Numerically they sort as 7, 9, 12, 41, 65, with a median of 12. As text they sort as "12", "41", "65", "7", "9", and the middle token is "65". A person glancing at the text-sorted column might read the middle row and report 65 as the typical age, which is the oldest person in the group. Such errors survive because both orders look orderly at a glance. Making a habit of checking the smallest and largest values after sorting exposes the problem quickly: in the text order, 7 sits near the bottom while 12 sits at the top, which no numeric sort would produce.
What the comparison proves
The cases show that for the list 1, 2, 10 this tool returns a numeric median of 2 in either input order. They do not test unusual tokens or very large lists, and they do not claim that text sorting is a defect, since for words it is the right behavior. The point is to know which order a tool uses before interpreting its middle value.
Reproduce the checks
Numeric median
Open the Mean Median Mode Calculator and enter:
- Numbers
1,2,10
Expected output:
Median
2The numeric middle value is two.
Order-independent control
Open the Mean Median Mode Calculator and enter:
- Numbers
10,1,2
Expected output:
Median
2Input order does not change the sorted numeric median.
References and implementation scope
The examples describe the behavior of the linked Computandum tools. A successful local check does not establish that another application accepts the same format or applies the same limits.
Sources
- Primary definition and convention reference ↗ · 2026-10-08