Every time you ask "which is bigger?", "are these the same?", or "what changed?" you are trying to compare the values in front of you. The method that gets you the right answer depends entirely on the type of data involved — two numbers, two strings, two spreadsheet columns, two JSON payloads, or two versions of a file all require different techniques. This guide covers all of them in one place. If you have never worked with text diffs before, our introduction to what a diff actually means is a useful primer before you dive in.

The Short Answer

What are you comparing? Numbers Text / Strings Lists / Data Files / JSON A − B or > / < / == ops === / == or localeCompare() Set ops or COUNTIF Line-level or semantic diff
Choose your comparison method based on data type: numbers use arithmetic operators, strings use equality or locale methods, lists use set operations, and files use diff tools.

The fastest way to compare the values in any situation:

  • Two numbers: subtract one from the other, or use > / < / == operators. The sign of the result tells you which is larger; zero means equal.
  • Two text strings: use your language's built-in equality operator (=== in JavaScript, == in Python) for exact matches; use localeCompare() or strcmp() for ordering.
  • Two lists or columns: sort both, then diff — or use set operations (intersection, difference) to find what is in one but not the other.
  • Two files, JSON objects, or code blocks: run a diff tool. A visual side-by-side diff highlights every line that changed, added, or was removed.

The rest of this guide expands each of these paths with code examples, spreadsheet formulas, and tool recommendations.

What "Comparing Values" Actually Means

To compare the values of two things means to evaluate them against a shared scale and produce a result — typically one of three outcomes: A is greater than B, A equals B, or A is less than B. In formal terms this is called a total order when every pair of elements can be compared, and a partial order when some pairs are incomparable (as with nested objects that have different keys).

The challenge is that "value" means different things depending on context:

  • For numbers, value is magnitude — 42 is greater than 17 on an absolute numeric scale.
  • For strings, value is lexicographic order — "banana" comes after "apple" because "b" > "a" in Unicode.
  • For booleans, value is truth — true and false are the only two possibilities.
  • For dates, value is chronological order — a later timestamp is "greater than" an earlier one.
  • For objects or documents, value is structural content — equality means every field at every level matches.

Mixing these up is the root cause of most comparison bugs. A classic example: comparing the string "10" to the number 10 using loose equality (== in JavaScript) returns true, but comparing "10" to "9" lexicographically returns false because "1" < "9" — even though the numeric value 10 > 9. Type awareness is the first discipline of value comparison.

Comparison Operators: < > = != Explained

Operator Meaning Example Result == Equal to 5 == 5 true != Not equal to 5 != 3 true < Less than 3 < 7 true > Greater than 9 > 4 true <= Less than or equal to 5 <= 5 true >= Greater than or equal to 8 >= 10 false
The six standard comparison operators: each returns a boolean (true or false) when applied to two values.

Comparison operators are the building blocks of every decision in code, spreadsheets, and databases. They evaluate the values on their left and right sides and return a boolean — true or false. The six standard operators work the same way across most languages and tools (see the Wikipedia article on relational operators for a language-by-language reference):

Operator Meaning Example Result
== Equal to 5 == 5 true
!= Not equal to 5 != 3 true
< Less than 3 < 7 true
> Greater than 9 > 4 true
<= Less than or equal to 5 <= 5 true
>= Greater than or equal to 8 >= 10 false

== versus === in JavaScript

JavaScript and PHP add a second equality tier. The loose equality operator (==) coerces types before comparing — so 0 == false returns true because both coerce to a falsy value. The strict equality operator (===) compares both value and type without coercion — 0 === false returns false because 0 is a number and false is a boolean.

Best practice: always use === and !== in JavaScript. The loose operators produce results that are notoriously hard to predict and are a common source of subtle bugs. Python, Java, and Go do not have a loose equality operator at all — == always compares values of the same type.

Not-equal in SQL

SQL has two notations for "not equal": != and <>. Both are valid in most databases (PostgreSQL, MySQL, SQL Server, SQLite). The ANSI standard is <>, but != is more commonly written in practice. Note that NULL != NULL is not true in SQL — any comparison with NULL returns NULL (unknown), so you must use IS NULL or IS NOT NULL instead.

How to Compare Two Numbers

A < B A − B is negative B is greater A = B A − B is zero Values are equal A > B A − B is positive A is greater 0 25 50 75 100 A B A − B = +ve → A > B
A number line illustrating the three outcomes when comparing two values: A minus B positive means A is greater, zero means equal, negative means B is greater.

To compare two numbers and find which is larger, compute the difference A − B. If the result is positive, A is greater; if negative, B is greater; if zero, they are equal. This is the mathematical foundation behind every comparison operator.

In spreadsheets (Excel / Google Sheets)

Several formulas cover the common cases when you want to compare two numbers:

  • =A1-B1 — signed difference (positive if A > B)
  • =ABS(A1-B1) — absolute difference, always positive
  • =IF(A1>B1,"A is larger",IF(A1<B1,"B is larger","Equal")) — three-way label
  • =MAX(A1,B1) — returns whichever value is larger
  • =(A1-B1)/B1*100 — percentage difference relative to B

When you compare two numbers as percentages, use the percentage-difference formula rather than a raw subtraction so that the result is meaningful across different magnitudes. A difference of 5 between 10 and 15 is large (50%); the same difference between 1,000 and 1,005 is negligible (0.5%).

In Python

a = 42
b = 17

print(a > b)    # True
print(a == b)   # False
print(a - b)    # 25  (signed difference)
print(abs(a - b))  # 25  (absolute difference)

In JavaScript

const a = 42;
const b = 17;

console.log(a > b);   // true
console.log(a === b);  // false
console.log(a - b);    // 25

Floating-point caution

Never use == to compare two floating-point numbers directly. The expression 0.1 + 0.2 === 0.3 returns false in JavaScript because binary floating-point representation introduces tiny rounding errors. Instead, compare within a tolerance (epsilon):

Math.abs(0.1 + 0.2 - 0.3) < 1e-10;  // true

In Python, use math.isclose(a, b, rel_tol=1e-9). In Java, avoid float/double equality checks altogether; use BigDecimal for financial values.

How to Compare Text and Strings

String A String B H e l l o vs h e l l o Different character Matching character "Hello" === "hello" → false | "Hello".toLowerCase() === "hello" → true
Character-level comparison of "Hello" vs "hello": only the first character differs in case, so a strict case-sensitive comparison returns false while a case-insensitive comparison returns true.

String comparison is more nuanced than numeric comparison because text has encoding, case, locale, and normalization to consider. When comparing two strings, start by deciding whether you need exact equality, case-insensitive equality, or ordered comparison (i.e., alphabetical sorting).

Exact equality

Most languages compare strings for exact equality with == or ===:

  • Python: "hello" == "Hello"False
  • JavaScript: "hello" === "Hello"false
  • Java: "hello".equals("Hello")false — never use == for Java String objects; it compares references, not values
  • Go: "hello" == "Hello"false

Our string compare guide covers code examples for Python, JavaScript, Java, C#, Go, and C++ in one place.

Case-insensitive comparison

  • Python: "Hello".lower() == "hello".lower()
  • JavaScript: "Hello".toLowerCase() === "hello".toLowerCase()
  • SQL: LOWER(col_a) = LOWER(col_b) — or use a case-insensitive collation
  • Excel: =LOWER(A1)=LOWER(B1) (the default = operator is already case-insensitive; use EXACT when you need case sensitivity)

Ordered comparison (lexicographic)

For ordering strings — for example, to sort a list alphabetically — use:

  • Python: "apple" < "banana"True
  • JavaScript: "apple".localeCompare("banana")-1 (negative means first argument comes earlier)
  • Java: "apple".compareTo("banana") → negative integer
  • C: strcmp("apple", "banana") → negative integer

For user-facing comparisons that must follow locale rules (accents, ligatures, regional sorting conventions), use locale-aware methods — Intl.Collator in JavaScript, java.text.Collator in Java — rather than raw Unicode code point ordering.

Visual text diff

When the goal is to find where two strings differ rather than just whether they do, a character-level or line-level diff is more useful than a boolean. Paste both strings into Diff Checker to see every insertion, deletion, and change highlighted side by side.

How to Compare Lists and Data Sets

List A List B Only in A set(A) - set(B) {1, 2} In both set(A) ∩ set(B) {3, 4, 5} Only in B set(B) - set(A) {6, 7} Example: A = [1,2,3,4,5] · B = [3,4,5,6,7]
Venn diagram showing list comparison: elements only in A, elements shared by both lists (intersection), and elements only in B — mapped to Python set operations.

Comparing two lists means answering one or more of these questions: What items are in both? What is in A but not B? What is in B but not A? Are the lists identical, in the same order? The right approach depends on which question you are asking.

Set operations

The cleanest way to find differences across two lists is with set operations. Sets treat lists as unordered collections, which means duplicates are collapsed and order is ignored:

# Python — compare two lists with set operations
a = [1, 2, 3, 4, 5]
b = [3, 4, 5, 6, 7]

in_both = set(a) & set(b)      # {3, 4, 5}
only_in_a = set(a) - set(b)    # {1, 2}
only_in_b = set(b) - set(a)    # {6, 7}
are_equal = set(a) == set(b)   # False

For Python-specific list comparison patterns including DeepDiff for nested lists, see our Python compare 2 lists guide.

In Excel and Google Sheets

To find values in column A that are missing from column B, use COUNTIF:

=IF(COUNTIF($B:$B, A1)=0, "Only in A", "In both")

Apply this formula down column C alongside column A to label every row. Filtering column C on "Only in A" surfaces the differences instantly. Our guide to comparing two lists covers VLOOKUP, XLOOKUP, Power Query, and conditional formatting approaches in depth.

Order-sensitive comparison

If list order matters — for example, comparing two sorted result sets from an API — an element-by-element comparison is appropriate:

# Python — order-sensitive equality
a = [1, 2, 3]
b = [1, 3, 2]

print(a == b)      # False (order differs)
print(sorted(a) == sorted(b))  # True (same elements)

Data set comparison

For larger data sets — CSV exports, database query results, analytics snapshots — a columnar diff approach is more practical than a row-by-row loop. Export both data sets to text, then run a line-by-line diff to see which rows changed, appeared, or disappeared. This is the same technique used in data pipeline testing and database migration validation.

How to Compare Files, JSON, and Code

file-a.txt (old) file-b.txt (new) 1 version: "1.0.0" name: "alpha" debug: true 4 timeout: 30 5 retries: 3 logLevel: "warn" 1 version: "1.0.0" + name: "beta" + debug: false 4 timeout: 30 5 retries: 3 + logLevel: "error" Removed (−) Added (+) Unchanged
Side-by-side diff view: removed lines are highlighted in red with a minus sign, added lines in green with a plus sign, and unchanged lines remain white — the standard format used by Git and visual diff tools.

When the values you are comparing live inside files — configuration files, API responses, source code, contracts, exported data — the unit of comparison shifts from individual values to lines, blocks, or structured nodes. Three categories cover most real-world cases.

Text and code files

A line-by-line diff is the standard method for comparing text files and source code. On the command line, the Unix diff utility produces a unified diff:

diff -u file-a.txt file-b.txt

Lines prefixed with - were removed; lines prefixed with + were added; lines with neither were unchanged. The unified format is what Git uses for every commit diff. For a visual browser-based alternative with no terminal required, paste both files into Diff Checker's side-by-side panels.

JSON files and API responses

Comparing two JSON objects is trickier than a plain text diff because JSON key order does not matter — {"a":1,"b":2} and {"b":2,"a":1} are semantically identical, but a text diff would flag them as different. A proper JSON diff tool parses both documents first, then compares them structurally, ignoring irrelevant key-order changes.

In JavaScript, a quick deep-equality check is:

JSON.stringify(objA) === JSON.stringify(objB);

This works for simple cases but fails when key order differs or when values include undefined, NaN, or circular references. For production use, prefer fast-deep-equal or Lodash's _.isEqual(). For a visual comparison with a browser tool, see our guide to comparing JSON objects online.

XML, HTML, and structured markup

XML and HTML comparison faces the same key-ordering problem as JSON, plus attribute ordering and whitespace normalization. A semantic XML diff compares the document tree, not the raw text, so insignificant whitespace and attribute reordering are not flagged as differences. Our XML compare guide covers both command-line and browser approaches.

Database schemas and SQL

Comparing two database schemas — for example, production versus staging — requires a schema diff tool that understands table structure, indexes, constraints, and stored procedures. A plain text diff of two CREATE TABLE dumps works for simple cases but misses semantic equivalences like column reordering. Dedicated tools such as Flyway, Liquibase, or the DB comparison tools we reviewed handle this correctly.

Best Online Tools to Compare Values in 2026

Diff Checker Text & Code Side-by-side diff AI summaries Runs in browser Free Excel / Sheets Numbers & Lists IF, EXACT COUNTIF, VLOOKUP Live formulas Sheets: Free JSONDiff.com JSON / API Structural diff Ignores key order Browser-based Free Beyond Compare Folders & Binary Three-way merge Folder sync FTP support 30-day trial WinMerge Text (Windows) Open source Image diff Folder diff Free (open src)
Five leading tools to compare values in 2026: Diff Checker for text and code, Excel/Sheets for numeric and list work, JSONDiff for structured JSON, Beyond Compare for folders, and WinMerge for Windows users.

The right tool depends on your data type and the level of detail you need. Here are the most reliable options in 2026:

Tool Best For Key Feature Free Tier
Diff Checker (diffchecker.pro) Text, code, files Side-by-side diff + AI summary in the browser Yes
Excel / Google Sheets Numbers, lists, columns IF, EXACT, COUNTIF, VLOOKUP formulas Sheets: yes
JSONDiff.com JSON files and API responses Structural diff ignores key order Yes
Beyond Compare Folders, binary files, FTP Three-way merge, folder sync 30-day trial
WinMerge Text and folders on Windows Open source, image diff Yes (free)

Diff Checker for browser-based comparison

Diff Checker runs entirely inside your browser as a Chrome extension. Paste two blocks of text, code, or file content into the side-by-side panels and every difference is highlighted instantly — added lines in green, removed lines in red, changed characters within a line underlined. The AI-powered diff summary explains what changed in plain English, which is useful when reviewing long documents where the raw diff output is dense. (Note: The AI summary feature requires your own OpenAI API key and sends the diff text to OpenAI; the comparison itself runs locally.)

Because the comparison happens locally in the extension, nothing is uploaded to a server. This makes it safe for sensitive content — contracts, configuration files with secrets, proprietary code — that you would not want to send to a third-party web service.

Spreadsheet tools for numeric and list comparison

Excel and Google Sheets remain the fastest environment to compare two numbers interactively, because formulas update live as you change input cells. The combination of conditional formatting (color cells where values differ) and COUNTIF (count how many items match) gives you both a visual and a quantitative picture of the comparison in seconds.

Command-line tools for developers

For developers, the command-line diff, cmp, and comm utilities on Linux and macOS handle most file comparison tasks without a GUI. Git's built-in git diff is the most commonly used diff tool for code because it understands version history, not just two static files.

Common Mistakes When Comparing Values

⚠ Mistake 1 Comparing different types "5" == 5 → true (JS!) ⚠ Mistake 2 Float == comparison 0.1+0.2 === 0.3 → false ⚠ Mistake 3 Wrong case handling "Email" ≠ "email"? ⚠ Mistake 4 List order assumptions [1,2,3] ≠ [3,2,1] ⚠ Mistake 5 Text diff on JSON/XML Key reorder = false diff ⚠ Mistake 6 Unverified tool output Check with 2 tools
Six common mistakes when comparing values: type coercion surprises, floating-point equality, incorrect case handling, list order assumptions, semantic vs. text diffs on structured data, and unverified tool output.

Mistake 1 — Comparing different types

The most common bug: comparing a string to a number using == in a language that does type coercion. In JavaScript, "5" == 5 is true, but "5" > 3 is also true because the string is coerced to a number before comparison. Always normalise types before comparing — parse strings to numbers explicitly, or use strict equality.

Mistake 2 — Using == on floating-point numbers

As noted in the numbers section, 0.1 + 0.2 === 0.3 is false in every IEEE 754 floating-point language. Use an epsilon-based comparison for any computation involving decimal arithmetic. This is particularly important in financial and scientific code where two nominally equal values may differ by 1e-15.

Mistake 3 — Ignoring case when case matters (or vice versa)

Email addresses and usernames are typically case-insensitive; passwords are always case-sensitive. Applying the wrong comparison to the wrong field produces either false mismatches (rejecting a valid login because the user typed their email in uppercase) or false matches (accepting a password that differs only in case).

Mistake 4 — Comparing lists without normalising order

Two lists with identical elements in different orders are not equal if you compare them element by element — but they are equal as sets. Decide which semantics you need and choose the method accordingly. API response testing often requires order to be ignored; sort-order testing requires order to be enforced.

Mistake 5 — Treating a text diff as a semantic diff

A line-level text diff on a JSON file will flag a key reordering as a change even though the data is identical. A text diff on minified HTML will show enormous changes after a formatter runs, even if no content changed. For structured data, always use a parser-aware diff that understands the format's semantics.

Mistake 6 — Not verifying the comparison tool itself

Some online "diff" tools normalise whitespace silently, strip trailing newlines, or re-encode characters — which means they can make two different files look identical, or flag identical files as different. When accuracy matters, run the same comparison in two tools and check that the results agree.

Frequently Asked Questions

How do you compare two values?

Choose the method that matches your data type. For numbers, use subtraction (A − B) or a comparison operator (>, <, ==) to find which is larger or whether they are equal. For text and strings, use your language's built-in equality operator (=== in JavaScript, == in Python) for exact equality, or localeCompare() / strcmp() for locale-aware ordering. For files, JSON, and documents, a diff tool shows differences line by line. In spreadsheets, the IF and EXACT functions cover most comparison tasks.

What are comparison operators (< > = !=)?

Comparison operators are symbols that compare two values and return a boolean result (true or false). The six standard operators are: == (equal to), != (not equal to), < (less than), > (greater than), <= (less than or equal to), and >= (greater than or equal to). In JavaScript and PHP, === and !== are strict equality operators that also check data type, while == and != allow type coercion. In SQL, the not-equal operator is written as <> in some dialects.

What is the difference between == and === in programming?

In JavaScript and PHP, == (loose equality) compares values after type coercion — so 0 == false returns true because both coerce to the same falsy value. === (strict equality) compares both value and type without any coercion — so 0 === false returns false because one is a number and the other is a boolean. Best practice in JavaScript is to always use === and !== unless you have a specific reason to allow coercion, because == produces surprising results that are hard to debug.

How do you compare values in Excel or Google Sheets?

Use the = operator inside an IF formula to compare the values in two cells: =IF(A1=B1,"Match","Mismatch"). For case-sensitive text comparison, use EXACT: =EXACT(A1,B1). To compare two numbers and find the numerical difference, use =A1-B1 or =ABS(A1-B1) for the absolute difference. To find which of two numbers is larger, use =MAX(A1,B1) or =IF(A1>B1,"A is larger","B is larger"). For comparing two lists, COUNTIF identifies values present in one column but not the other.

Can I compare files visually online?

Yes. Diff Checker lets you compare two text files, code files, or any text-based content side by side in your browser — no upload required, nothing leaves your machine. Paste two blocks of text into the panels and differences are highlighted line by line. The Chrome extension adds AI-powered diff summaries that explain what changed in plain English. For JSON files specifically, JSON diff tools parse the structure first so that key reordering is not flagged as a change.

Compare Any Two Values Side by Side — Free

Diff Checker runs entirely in your browser. Paste two blocks of text, code, JSON, or any file content into the side-by-side panels and every difference is highlighted instantly. The built-in AI summary explains what changed in plain English — no upload, no account, nothing leaves your machine.

Add Diff Checker to Chrome — Free