Hey folks,
Let’s say that you’re writing code to calculate a delivery charge for your food delivery app. Each order has a base fee, a per-kilometer charge, and a small platform tax. You need one formula that works for any distance.
You can’t write separate code for 2 km, 5 km, and 10 km. That would be insane. Instead you’d write something like:
total = base_fee + (rate_per_km * distance) + tax
And now your formula works for any distance, any rate, any tax.
While we think we can achieve this is software engineering, Mathematics actually invented this trick thousands of years before programming did. They call the changing parts variables, and the whole formula an expression. Once you understand these two ideas, a huge chunk of algebra just clicks to you.
What Is a Variable?
A variable is just a placeholder for a number that can change.
Think of it like a labeled box. The box has a name on it (like $x$ or $n$ or $price$), and you can put any number inside. The label tells you what the box is for. The number inside is the actual value.
It is same as in software engineering.
In math, we typically use single letters: $x$, $y$, $a$, $b$, $n$. The letter itself doesn’t matter at all. When mathematicians write $x$, they mean “whatever number we decide to use here.”
Naming Variables
Just right above I said that the letter itself doesn’t matter at all. However, Mathematicians tend to use certain letters by convention:
- $x$, $y$, $z$ - generic unknowns, especially in geometry
- $n$ - counts of things (number of items, steps, users)
- $t$ - time
- $r$ - rate or radius
- $a$, $b$, $c$ - constants or general-purpose variables
But the truth is that any letter works. Let’s say that you’re modeling price, you could call it $p$. If you’re modeling weight, call it $w$. The math doesn’t care what you name it, as long as you’re consistent within a problem.
You can even use words to name the variables. Say you wanna calculate the area of a rectangle. We know that the area of a rectangle is the product (multiplication) of length and breadth.
The general way that mathematicians write this formula is,
$$l \times b$$But we can even write it as,
$$length \times breadth$$or even,
$$len \times brd$$or even (please don’t do this often),
$$a1 \times a2$$There is no problem in naming our variables. We just have to keep it consistent.
What Is an Expression?
An expression is a combination of numbers, variables, and mathematical operations. It doesn’t have an equal sign.
Think of it like a recipe. A recipe says: take these ingredients, do these things to them, and you get a result. An expression is very similar and says the same. It tells you how to compute something, but it doesn’t tell you what the final answer is until you plug in specific values.
Here are some expressions:
- $5 + 3$ - just numbers, no variables
- $2x + 7$ - one variable
- $3a - 2b + 1$ - two variables
- $x^2 + 5x - 3$ - variable raised to a power
Every expression has something called terms. They are the individual pieces separated by mathematical operations.
$$3x^2 \underbrace{-}_{\text{separates}} 5x \underbrace{+}_{\text{separates}} 8$$Here, $3x^2$, $5x$, and $8$ are three separate terms.
Each term has:
- A coefficient (the number in front): $3$, $5$, $8$
- A variable part: $x^2$, $x$.
Note that we don’t have any variable in-front of $8$. This means 8 is a constant term.
No matter what is the value of $x$, the value of the term $8$ will not change.
But the value of terms $3$ and $5$ will change based on the value of $x$.
A term with no variable is called a constant term because it never changes.
Understanding terms is important because they’re the atoms of algebra. At least, that’s what I call them.
Evaluating an Expression
“Evaluating” just means, swap the variable for an actual number and calculate.
It’s the mathematical equivalent of calling a function with an argument:
f(x) = 2x + 3
f(5) → replace x with 5 → 2(5) + 3 = 13
Let’s do this step by step. Suppose you have the expression $2x + 3$ and you want to evaluate it when $x = 5$.
Step 1: Write the original expression.
$$2x + 3$$Step 2: Replace every $x$ with $5$.
$$2(5) + 3$$Step 3: Follow the order of operations - multiply first, then add.
$$10 + 3 = 13$$So when $x = 5$, the expression $2x + 3$ equals $13$.
What if $x = 10$?
$$2(10) + 3 = 20 + 3 = 23$$What if $x = 0$?
$$2(0) + 3 = 0 + 3 = 3$$The variable $x$ changes. The structure of the expression never changes. That’s the whole point.
Let’s try a more complex one. Evaluate $3x^2 - 2x + 1$ when $x = 4$.
Step 1: Replace $x$ with $4$.
$$3(4)^2 - 2(4) + 1$$Step 2: Handle the exponent first. $4^2 = 16$.
$$3(16) - 2(4) + 1$$Step 3: Multiply.
$$48 - 8 + 1$$Step 4: Add and subtract from left to right.
$$= 41$$When $x = 4$, the expression equals $41$.
The rule about order of operations - exponents before multiplication before addition/subtraction - keeps everyone getting the same answer. Without it, math would be chaos.
Building Expressions from Real Problems
Here’s where variables and expressions become genuinely powerful. You can look at a real situation, identify what’s changing, and write one expression that captures the entire relationship.
Example: Delivery charges
You charge a base fee of ₹30 for any delivery, plus ₹8 per kilometer.
- What’s changing? The distance.
- Call it $d$ (kilometers).
- Total charge = base fee + per-km rate × distance.
Now this expression works for any distance:
- 5 km: $30 + 8(5) = 30 + 40 = ₹70$
- 12 km: $30 + 8(12) = 30 + 96 = ₹126$
- 0.5 km: $30 + 8(0.5) = 30 + 4 = ₹34$
One expression. Infinite distances handled.
Example: Rectangle area
The length of a rectangle is fixed at 8 units. The width can vary.
- Variable: $w$ (width)
- Area = length × width
If $w = 3$: area $= 8(3) = 24$. If $w = 7$: area $= 8(7) = 56$.
What if both length and width can vary? Two variables:
$$\text{area} = l \times w = lw$$(When two variables or a number and variable sit next to each other with no symbol, it means multiplication. So $lw$ means $l \times w$.)
The process for building expressions is always the same:
- Identify what can change - those become your variables.
- Identify what stays fixed - those are constants.
- Write how they relate using operations.
Expressions with Two Variables
Expressions can contain multiple variables. Each one represents a different quantity that varies independently.
Say you’re building an order system. The total cost depends on the price per item $p$ and how many are bought $q$:
$$\text{total} = pq$$If price is ₹50 and quantity is 3: $50 \times 3 = ₹150$. If price is ₹120 and quantity is 2: $120 \times 2 = ₹240$.
Now add a fixed shipping fee of ₹40:
$$\text{total} = pq + 40$$You have three things at play: a variable part $pq$ that shifts with price and quantity, and a constant $40$ that never moves.
When you evaluate this expression, you need values for both $p$ and $q$:
If $p = 80$ and $q = 4$:
$$pq + 40 = 80(4) + 40 = 320 + 40 = ₹360$$Simplifying Expressions - Like Terms
Sometimes an expression has redundancy. You can write it in a shorter, cleaner form without changing its meaning.
The key idea: you can only combine terms that have the same variable and the same power.
These terms are called like terms.
The apple analogy
Imagine $x$ represents an apple.
- $2x$ means “2 apples”
- $3x$ means “3 apples”
If you have 2 apples and someone gives you 3 more, you have 5 apples. So:
$$2x + 3x = 5x$$The math works because of the distributive property:
$$2x + 3x = (2 + 3)x = 5x$$You’re just adding the coefficients.
Important: You can ONLY do this when the variable parts are identical.
| Pair | Like terms? | Can combine? |
|---|---|---|
| $2x$ and $3x$ | Yes ($x$ and $x$) | $5x$ ✓ |
| $4y$ and $7y$ | Yes ($y$ and $y$) | $11y$ ✓ |
| $2x$ and $3y$ | No (different variables) | Cannot ✗ |
| $3x^2$ and $5x$ | No (different powers) | Cannot ✗ |
| $6x^2$ and $2x^2$ | Yes ($x^2$ and $x^2$) | $8x^2$ ✓ |
A full example
Simplify $3a + 2b + 5a - b$.
Step 1: Group the like terms.
- $a$ terms: $3a$ and $5a$
- $b$ terms: $2b$ and $-b$
Step 2: Combine each group.
- $3a + 5a = 8a$
- $2b - b = b$ (since $-b$ is the same as $-1b$)
Result: $8a + b$
Verify: Let $a = 2$, $b = 3$.
- Original: $3(2) + 2(3) + 5(2) - 3 = 6 + 6 + 10 - 3 = 19$
- Simplified: $8(2) + 3 = 16 + 3 = 19$ ✓
Order of Operations Matters
When an expression has multiple operations, the order in which you calculate them matters enormously.
Consider $2 + 3 \times 4$. Two possible interpretations:
- Add first: $(2 + 3) \times 4 = 5 \times 4 = 20$
- Multiply first: $2 + (3 \times 4) = 2 + 12 = 14$
The answer depends on which you do first. So mathematics uses an agreed-upon order:
PEMDAS - Parentheses, Exponents, Multiplication/Division, Addition/Subtraction
- Whatever is inside parentheses first
- Exponents next
- Multiplication and Division (left to right)
- Addition and Subtraction (left to right)
Using PEMDAS, $2 + 3 \times 4 = 2 + 12 = 14$ (multiplication before addition).
If you want the addition to happen first, you use parentheses: $(2 + 3) \times 4 = 20$.
With variables:
Evaluate $5x^2 - 3x + 2$ when $x = 3$:
Step 1 - substitute:
$$5(3)^2 - 3(3) + 2$$Step 2 - exponent first:
$$5(9) - 3(3) + 2$$Step 3 - multiply:
$$45 - 9 + 2$$Step 4 - left to right:
$$= 38$$Expressions vs. Equations
These two look similar but serve completely different purposes.
An expression is like a formula - it computes a value, but it doesn’t make a claim:
$$2x + 5$$An equation is a statement that two things are equal - it makes a claim that something must be true:
$$2x + 5 = 13$$The equation is asking: for what value of $x$ is this statement true? (Answer: $x = 4$.)
An expression just says: here’s how to compute something. You evaluate it for different values of $x$ and get different results.
| Expression | Equation | |
|---|---|---|
| Has equals sign? | No | Yes |
| Purpose | Compute a value | Make a statement / solve |
| Example | $3x + 2$ | $3x + 2 = 11$ |
Think of an expression as a function definition. Think of an equation as a constraint - it pins down which specific value(s) of the variable make everything balance.
The Big Picture: Why This Matters
Variables and expressions are the grammar of algebra. Once you’re fluent in them, you can:
- Write one formula instead of hundreds of specific calculations
- Model real-world relationships (costs, distances, areas, growth rates)
- Communicate mathematical ideas precisely
- Build towards equations, functions, and calculus
In programming, you do this every day without thinking about it. You write functions that take parameters (variables) and compute results (expressions). The math version is the same concept with different notation.
Every time you write total = price * qty + shipping, you’re writing a mathematical expression. The only difference is syntax.
And here’s the beautiful part: once you learn to read and write expressions fluently, you can think with them. You start seeing relationships between quantities instead of just isolated numbers. That’s when math becomes genuinely useful.
Connecting to Functions
You’re now ready to understand functions, which are the next step.
A function is simply an expression with a name. When you write:
$$f(x) = 2x + 3$$You’re saying: “I’m naming this expression $f$, and its variable is $x$.” Now you can call it: $f(5) = 13$, $f(10) = 23$, and so on.
Functions let you package expressions so you can reuse them by name. It’s exactly like defining a named function in code.
If you want to dive deeper into functions - how they work, different types, how to graph them - my post on Functions in mathematics picks up right where this leaves off.
Quick Reference
Variable: A letter that represents a number. It’s a placeholder.
Expression: Numbers, variables, and operations combined - no equals sign.
Term: One piece of an expression ($3x^2$, $-5x$, $8$).
Coefficient: The number multiplying a variable in a term ($3$ in $3x^2$).
Constant term: A term with no variable ($8$ stands alone).
Like terms: Terms with identical variable parts - only these can be combined.
Evaluating: Replacing variables with specific numbers and calculating.
Simplifying: Rewriting an expression in a cleaner form (usually by combining like terms).
The next time you see an expression like $4x^2 - 3x + 7$, don’t panic. Break it down: three terms, coefficients $4$, $-3$, and $7$, variable $x$ raised to powers $2$ and $1$. Then it’s just a machine waiting for you to plug in a number.
That’s all algebra really is - a language for describing relationships between numbers that can change.