A variable is a symbol or name that represents a value which can change. The letter x in a math equation, the word “score” in a computer program, and the factor you test in a science experiment are all variables. They stand in for information that isn’t fixed, letting you work with values that might differ from one situation to the next.
Variables show up in three major areas: mathematics, scientific research, and computer programming. The core idea is the same across all three, but each field uses variables in slightly different ways.
Variables vs. Constants
The simplest way to understand a variable is to compare it to a constant. A constant has a fixed numerical value that never changes. The number 9, the number -42, and the fraction 3/8 are all constants. A variable, on the other hand, is a symbol (usually a letter like x, y, or z) that can take on different numerical values depending on the situation. In the expression x + 5 = 12, the number 5 is a constant and x is a variable whose value turns out to be 7. Change the equation to x + 5 = 20, and x becomes 15. The constant stayed the same; the variable shifted.
Variables in Mathematics
In math, variables typically fall into two categories: independent and dependent. The independent variable is the input, the value you choose or control. The dependent variable is the output, the value that changes based on whatever you picked for the independent variable. By convention, x usually represents the independent variable and y represents the dependent one.
When you write y = f(x), you’re saying “y is a function of x,” which simply means the value of y depends on whatever x happens to be. If y = 2x + 3, plugging in x = 4 gives you y = 11. Plug in x = 10 and y becomes 23. The relationship between the two variables is defined by the equation, and the dependent variable’s value is entirely determined by the independent one.
This framework extends well beyond algebra class. In economics, analysts use it to figure out which independent variables (like interest rates or consumer spending) explain changes in a dependent variable (like GDP growth). In any field that uses equations or graphs, independent and dependent variables are the basic building blocks.
Variables in Scientific Research
Scientists use variables to design experiments and measure results. The terminology overlaps with math, but the context is hands-on rather than abstract.
- Independent variable: The factor the researcher deliberately changes or manipulates. In a study testing whether a new fertilizer helps plants grow taller, the fertilizer is the independent variable. Sometimes the independent variable isn’t manipulated directly but is instead a grouping characteristic, like comparing outcomes between two age groups.
- Dependent variable: The outcome being measured. It’s what changes (or doesn’t) as a result of the independent variable. In the fertilizer example, plant height is the dependent variable.
- Controlled variable: A factor the researcher keeps the same across all groups so it doesn’t skew the results. Using the same soil, the same amount of sunlight, and the same watering schedule would all be controlled variables in the plant experiment.
- Extraneous variable: A factor that could influence the results but hasn’t been controlled. If some plants happen to sit closer to a window and get more light, that extra sunlight is an extraneous variable. Researchers try to identify and minimize these, but they can’t always eliminate every one.
The goal of any well-designed experiment is to isolate the independent variable so you can confidently say it caused the change in the dependent variable. The more extraneous variables you control for, the stronger your conclusions.
Variables in Computer Programming
In programming, a variable is a named container that stores a piece of data. You give it a name, assign it a value, and then use that name throughout your code whenever you need that value. If you write something like score = 0, you’ve created a variable called “score” and set its value to zero. Later, your code can update it to 10, 50, or any other number.
Variables in code hold different types of data, and the type matters because it determines what you can do with the value. The most common types include:
- Character (or string): Text, like a name or an address.
- Integer: A whole number without decimals, like 7 or -3.
- Decimal (sometimes called float): A number with a decimal point, like 3.14 or 99.95.
- Logical (or boolean): A true/false value, often used for yes-or-no conditions.
- Date: A calendar date value.
Many programmers follow naming conventions that make code easier to read. A common practice is to start a variable name with a lowercase letter that hints at the data type, so anyone reading the code can tell at a glance what kind of value the variable holds. For example, a variable storing text might start with “c” (for character), while one storing a whole number might start with “i” (for integer). Clear naming becomes increasingly important as programs grow larger and other people need to understand or maintain the code.
One key distinction in programming is between a variable that directly holds a value and one that acts as a reference, or handle, pointing to an object that contains the value. The difference is technical, but it matters: changing the object through one reference can affect every other reference pointing to the same object.
How the Concept Connects Across Fields
Whether you’re solving an equation, running an experiment, or writing software, a variable serves the same fundamental purpose: it’s a placeholder for something that can change. In math, variables let you write general rules that work for many numbers at once. In science, they let you isolate cause and effect. In programming, they let you store and manipulate data dynamically instead of hard-coding every value. Understanding what a variable is in one context makes it much easier to pick up the concept in another, because the underlying logic is the same.

