Skip to main content
Mathovia

Algebra / Common Graphs

Constant Functions: y = k and Horizontal Lines

A constant function returns the same output no matter what you feed it, and its graph is a flat horizontal line. That simplicity hides the two questions this topic is really testing: why the slope is zero rather than undefined, and why y = k is a function while the vertical line x = k is not. This lesson settles both, with the domain and range, the real-world models that produce flat graphs, and where constant functions turn up later.

Written by
Zohaib
Founder & Mathematics Content Creator
Published

Mathematics verification: Mathematical formulas, calculations, worked examples and solutions are reviewed for accuracy before publication.

Some functions do a lot of work. This one does none: whatever you put in, the same number comes out. That makes the constant function the simplest in all of algebra, and a useful test case for definitions — because a rule this plain exposes exactly what “function”, “slope”, and “range” really mean.

Definition of a constant function
A constant function returns the same output for every input

The Definition

A constant function has the form

where is a fixed real number. There is no on the right-hand side, which is the whole point: the output does not depend on the input.

The horizontal line f of x equals 3 drawn across a coordinate grid with five points plotted on it at different x-values
Every input lands on the same output height.

Because every point has the same -coordinate, the graph is a horizontal line at height . Written in function notation it is ; written as an equation it is . Same line either way.

Why the Slope Is Zero

This is where the marks are lost, so it is worth doing properly. Take any two points on , say and , and apply the slope formula:

Two points on the horizontal line y equals 4 with a run of 4 marked between them and a rise of 0, giving slope zero
Rise 0 over a run of 4 gives a slope of 0 — a real number.

Zero divided by something is zero. That is an ordinary number, and it is a complete answer.

Compare the vertical line , where two points such as and give

which is undefined, because dividing by zero is not defined. The two cases are opposites and they are constantly swapped:

LineEquationRiseRunSlope
Horizontal0non-zero
Verticalnon-zero0undefined

A memory hook that survives exam pressure: a flat road has no gradient, so zero. A cliff has no horizontal distance to divide by, so the question breaks.

Why y = k Is a Function but x = k Is Not

Apply the vertical line test. A relation is a function when every vertical line crosses its graph at most once.

A horizontal line y equals 2 shown passing the vertical line test, beside a vertical line x equals negative 3 which fails it
A vertical test line meets y = 2 exactly once, and x = −3 infinitely often.
  • — any vertical line meets it exactly once. One input, one output. It is a function.
  • — the vertical line at lies on top of it, meeting it at every height. The single input would be paired with every possible output. Not a function.

Notice that a constant function is allowed to repeat outputs — that is all it does. What a function may never do is give one input two different outputs. Repeating outputs costs it nothing as a function; it only costs it the property of being one-to-one.

Domain and Range

The line f of x equals 2 with the entire x-axis highlighted as the domain and the single output value 2 highlighted as the range
Everything goes in; only one value ever comes out.
  • Domain: all real numbers, . Nothing can break — there is no denominator, no root, no logarithm.
  • Range: the single value .

The range is the detail people get wrong, usually by writing out of habit or by giving . The output set has exactly one element, so set notation is the natural way to write it.

Is It Linear?

Yes. Compare with slope-intercept form and read off , . A constant function is a linear function whose slope happens to be zero, so it belongs to the family of lines — it just sits flat.

Some textbooks call it a polynomial of degree zero, for the same reason: can be written .

One thing it is not is a proportional relationship, unless . Proportional graphs pass through the origin, and never does.

Where Flat Graphs Come From

Constant functions model any quantity that does not respond to the input:

  • Flat-rate pricing. A £15 delivery charge however many items you order.
  • A fixed monthly fee on a bill, before usage charges are added.
  • A thermostat holding a set temperature while the outside temperature changes.
  • Base salary independent of hours worked.
  • The zero function , whose graph is the -axis itself.
A cost against items graph showing a flat line at fifteen pounds regardless of how many items are ordered
A flat rate graphs as a horizontal line — the cost ignores the input.

In each case the flatness is the information: it says the output is insensitive to the input. A constant piece often appears as one branch of a piecewise function — a flat rate up to a threshold, then a rising charge beyond it.

Worked Example A: Evaluate

For , find , and .

All three are . The input is never used, so no substitution is needed.

Worked Example B: Slope and Intercepts

Give the slope and intercepts of .

Slope 0. The -intercept is . There is no -intercept — the line runs parallel to the -axis at height 6 and never reaches it.

The exception is , which is the -axis and so meets it everywhere.

Worked Example C: Domain and Range

State the domain and range of .

Domain ; range .

Worked Example D: From Two Points

A line passes through and . Find its equation.

Both -values are 9, so the rise is 0 and the slope is 0. The line is .

Whenever two given points share a -coordinate, the answer is a constant function — no formula needed beyond noticing it.

Worked Example E: Is It One-to-One?

Does have an inverse?

No. and , so two different inputs share an output and the function fails the horizontal line test. A horizontal line drawn at meets the graph infinitely often.

Since only one-to-one functions have inverses, no constant function has one.

Common Mistakes to Avoid

  • Calling the slope undefined. Zero slope is horizontal; undefined slope is vertical.
  • Thinking is a constant function. It is not a function at all.
  • Writing the range as all real numbers. It is the single value .
  • Claiming a constant function is not linear. It is — a line of slope 0.
  • Expecting an -intercept. Only has one.
  • Assuming it has an inverse. It is never one-to-one.
  • Substituting the input anyway. There is no to substitute into.

Where Constant Functions Lead Next

  • Piecewise definitions. Flat segments are the simplest branches of a piecewise function.
  • Horizontal asymptotes. Curves that level off approach a constant function far from the origin.
  • Calculus. The derivative of a constant is zero — the formal version of “slope zero” — and constants are what an indefinite integral leaves ambiguous.
  • Average value. The mean of a data set is the constant function that best summarises it.
  • Transformations. Adding a constant to any function shifts its whole graph vertically.

Practice Problems

Work each one before opening the answer.

Problem 1. What is the slope of ?

Show answer

Zero. It is a horizontal line.

Problem 2. For , what is ?

Show answer

. The input is never used.

Problem 3. State the domain and range of .

Show answer

Domain ; range .

Problem 4. Is a function?

Show answer

No. It is a vertical line and fails the vertical line test.

Problem 5. Is a function?

Show answer

Yes. Every vertical line meets it exactly once.

Problem 6. A line passes through and . Find its equation.

Show answer

Equal -values, so .

Problem 7. Does have an -intercept?

Show answer

No. It sits three units above the -axis and never crosses it.

Problem 8. Write in the form .

Show answer

, so and .

Problem 9. Is one-to-one?

Show answer

No. Every input gives 9, so different inputs share an output.

Problem 10. What is the slope of ?

Show answer

Undefined. The run is zero, so the division is not defined.

Problem 11. A courier charges £12 regardless of parcel weight. Write the cost as a function of weight , and give its range.

Show answer

, with range .

Problem 12. What is unusual about the constant function ?

Show answer

Its graph is the -axis, so it is the only constant function with -intercepts — infinitely many of them.

Quick Reference

PropertyConstant function
Graphhorizontal line at height
Slope
Domain
Range
-intercept
-interceptnone, unless
Is it a function?yes
Is it linear?yes, with
One-to-one?no
Has an inverse?no
insteadvertical line, undefined slope, not a function

A constant function is the flattest member of the lines family, and it is the cleanest illustration of the slope rules and the vertical line test from functions. Its single-value range is what stops it being one-to-one. To drill the underlying ideas, try the domain and range practice problems. More Algebra lessons are available.

Frequently Asked Questions

What is a constant function?+

It is a function of the form , where is a fixed number. Every input produces the same output, so the graph is a horizontal line at height .

What is the slope of a constant function?+

Zero. Between any two points on the line the rise is 0 and the run is non-zero, so . It is zero, not undefined — undefined slope belongs to vertical lines.

Is a horizontal line a function?+

Yes. Every vertical line crosses it exactly once, so it passes the vertical line test: each input has exactly one output. A vertical line is not a function, because one input would map to infinitely many outputs.

What is the domain and range of a constant function?+

The domain is all real numbers, since any input is allowed. The range is the single value , because that is the only output the function ever produces.

Is y = 3 a linear function?+

Yes. It fits with and , so it is a linear function of degree zero. Every constant function is linear, but not every linear function is constant.

What is the difference between y = k and x = k?+

is a horizontal line and a genuine function. is a vertical line and is not a function at all, because the single input would be paired with every possible output.

Is a constant function one-to-one?+

No. Every input maps to the same output, so different inputs share an output — that is the definition of failing to be one-to-one. It follows that a constant function has no inverse.

Related lessons