Visual Tools
Calculators
Tables
Mathematical Keyboard
Converters
Other Tools


Piecewise Functions






Different Rules for Different Regions

Not every function follows a single formula across its entire domain. Tax rates change at income thresholds. Shipping costs jump at weight limits. A ball's height follows one equation while rising and another while falling. These situations demand functions that switch rules depending on where the input lands.

A piecewise function divides its domain into intervals, assigning a different formula to each piece. The function is defined everywhere it needs to be, but no single expression covers all cases. Instead, a collection of expressions — each with its own territory — combines to form one coherent function.

Key Terms

Core

Piecewise Function— multiple formulas, each governing a different part of the domain
Domain— the union of all intervals covered by the pieces
Range— the union of each piece's outputs on its interval

Related Types

Absolute Value Function— the most familiar piecewise function, with two linear pieces meeting at a vertex
Constant Function— each piece of a step function is constant


See All Function Definitions →


What is a Piecewise Function

Most functions met so far come as one formula: f(x) = 2x + 5, g(x) = x², and so on.
So it is natural to expect that any rule turning inputs into outputs can be written as a single formula in xx.
Take the rule "add 1 to a negative number, square any other": no single formula from the rule matches it.
Try each of the two formulas the rule mentions across all inputs. Each one is right on some inputs and wrong on others.
xthe rule givestry x + 1try x²
−3−2−2 ✓9 ✗
−100 ✓1 ✗
001 ✗0 ✓
243 ✗4 ✓
The failure was visible in the wording: the rule says "if".
The rule changes at 00: one formula is in charge to the left, another from 00 on. A single formula has to fit every input at once, so it cannot switch partway. Postage and tax brackets work the same way — the charge is worked out one way up to a limit and another way beyond it.
The definition
A piecewise function is one whose rule is given by different formulas on different parts of its domain; which formula to use depends on where the input lies.
A simple example:
What is a Piecewise Function
f(x)={x+1if x<0x2if x≥0f(x) = \begin{cases} x + 1 & \text{if } x < 0 \\ x^2 & \text{if } x \geq 0 \end{cases}
So the rule above is a piecewise function with two pieces, split at x=0x = 0.
It is still a single function: one input, one output.
A piecewise function is defined by multiple formulas, each applying to a different part of the domain. Rather than one rule governing all inputs, separate rules govern separate intervals.
The function remains a function — each input still produces exactly one output. But which formula produces that output depends on where the input falls.
For negative inputs, use x+1x + 1. For non-negative inputs, use x2x^2. At x=−3x = -3, the output is −3+1=−2-3 + 1 = -2. At x=2x = 2, the output is 22=42^2 = 4. At x=0x = 0, the boundary, the condition x≥0x \geq 0 applies, giving 02=00^2 = 0.
f(x) = x + 1 for x < 0 and x^2 for x >= 0, evaluated at -3, 0 and 2xy−4−3−2−1123−3−2−1123456x + 1 for x < 0x² for x ≥ 0f(−3) = −2f(2) = 4f(0) = 0: x ≥ 0 owns 0(0, 1) open: not usedTwo formulas on two intervals, still one output per input
One function, two formulas

The section's example: x + 1 for x < 0 (blue) and x² for x ≥ 0 (navy). Each input falls in exactly one interval, so exactly one formula runs: f(−3) = −2 from the first, f(2) = 4 from the second. At the boundary x = 0 the condition x ≥ 0 applies, so f(0) = 0; the first piece’s end at (0, 1) is open and never used.

Which formula applies is decided by the input, never by choice.
Each piece can be any type of function — linear, quadratic, constant, radical, or otherwise. The pieces join together at boundary points, sometimes connecting smoothly, sometimes jumping abruptly.
Read backwards, the definition gives a test: every input must fall under exactly one condition.
If two conditions both claim an input, or none does, the rule is not a function at all — which is why x<0x < 0 and x≥0x \geq 0 hand the boundary 00 to exactly one piece. And a single symbol can still hide pieces: ∣x∣|x| is −x-x for negative xx and xx otherwise. The section on evaluating piecewise functions puts the test to work.
The rest of the page covers the notation, evaluating and graphing piecewise functions, their domain, range and continuity, absolute value and step functions, real-world uses, and writing piecewise functions.

Piecewise Notation

Notation

Piecewise Notation

One function, several formulas — held together by a single brace, split apart by a boundary handshake, and drawn with a two-dot code. The grammar rules (each input matches exactly one row) are what make the stack a function at all.
f(x)f(x) and evaluation come from function notation; the inequality signs and chains in the conditions from inequality notation; the intervals they encode from domain notation.
{2xx<05x≥0\begin{cases} 2x & x < 0 \\ 5 & x \geq 0 \end{cases}
f defined by cases
The single left brace stacks formula–condition rows and means "use the row whose condition holds". No right brace ever closes it — the layout itself, produced by the cases environment in LaTeX, is the notation.
CasesRows read "formula, if condition" — two rows or ten, the grammar is identical; the conditions must be mutually exclusive and cover the whole domain, or the stack stops defining a function.
Do not confuseSet braces. The same glyph collects members in {2,5,7}\{2, 5, 7\} — there a brace pair encloses a finite set; here one unpaired brace selects a row. Twins in shape, strangers in meaning.
x<1x < 1 · x≥1x \geq 1
x below one; x at least one
The boundary handshake: adjacent conditions split each cut point so it belongs to exactly one row — strict on one side, or-equal on the other. Which row owns the boundary is a decision the inequality symbols record.
CasesCompound conditions chain — 1≤x<41 \leq x < 4, the chained inequality doing interval work inline; at evaluation time the handshake picks the piece, the drill of Evaluating Piecewise Functions below.
Do not confuseSymmetric inclusion. Writing x≤1x \leq 1 and x≥1x \geq 1 on adjacent rows double-books the boundary — legal only when both formulas agree there, a silent contradiction when they do not.
∙\bullet · ∘\circ
solid dot in, open dot out
The graphical half of the handshake: a solid dot marks an included endpoint, an open circle an excluded one — the number-line code of domain notation, promoted to curve endpoints in Graphing Piecewise Functions below.
CasesAt each jump of a discontinuous graph, one solid and one open dot share a vertical line — the picture of exactly-one-row membership; two solid dots stacked vertically draw something that fails to be a function.
Do not confuseThe composition ring. The open dot on a graph is a hole, not the ∘\circ of composition — position separates them: one sits on a curve, the other between function names.
DownloadPNG2×PDF
Notation · Cheat sheet
Function Notation at a Glance
The marks from the notation cards across the function pages: how each is read and what it means. Every group links to the full card on its page.
Basics
f(x)f(x)
f of x
ff names the rule, f(x)f(x) its output; never f times x.
g(t),  P(n)g(t), \; P(n)
g of t; P of n
Any letter can name a function; tt hints at time, nn at counting.
f(x+1)f(x + 1)
f of x plus one
Whatever is in the brackets replaces xx everywhere.
Domain
[2,5)[2, 5)
two included, five excluded
Square bracket in, round bracket out.
{x∣x≥0}\{x \mid x \geq 0\}
all x such that
Set-builder: the variable, then the test it must pass.
(a,b)∪(c,d)(a, b) \cup (c, d)
a union of intervals
For domains in separate pieces, as (−∞,−1)∪(1,∞)(-\infty, -1) \cup (1, \infty).
Range
{y∣y≥0}\{y \mid y \geq 0\}
all y such that
The same grammar on the output side.
f:R→Rf: \mathbb{R} \to \mathbb{R}
f from R to R
Domain, then codomain; the range may be smaller.
{2,5,7}\{2, 5, 7\}
exactly these outputs
A finite range listed in braces.
Function arithmetic
(f+g)(x)(f + g)(x)
f plus g, of x
Equals f(x)+g(x)f(x) + g(x); the same for f−gf - g.
(fg)(x)(fg)(x)
f times g, of x
Equals f(x) g(x)f(x)\,g(x).
(fg)(x)\left(\frac{f}{g}\right)(x)
f over g, of x
Equals f(x)g(x)\frac{f(x)}{g(x)}, only where g(x)≠0g(x) \neq 0.
Composition
f∘gf \circ g
f after g
Feed the output of gg into ff; read right to left.
f(g(x))f(g(x))
f of g of x
The same thing, evaluated inside out.
fg(x)fg(x)
ambiguous
Could mean a product; avoid it for composition.
Inverse functions
f−1(x)f^{-1}(x)
f inverse of x
The function that undoes ff: f−1(f(x))=xf^{-1}(f(x)) = x.
1f(x),  (f(x))−1\frac{1}{f(x)}, \; (f(x))^{-1}
one over f of x
The reciprocal: a different thing.
Dom(f),  Ran(f)\text{Dom}(f), \; \text{Ran}(f)
domain and range of f
They swap: Dom(f−1)=Ran(f)\text{Dom}(f^{-1}) = \text{Ran}(f).
Piecewise functionsThis page
{2xx<05x≥0\begin{cases} 2x & x < 0 \\ 5 & x \geq 0 \end{cases}
defined by cases
Use the row whose condition holds.
x<1,  x≥1x < 1, \; x \geq 1
split at the boundary
Each cut point belongs to exactly one row.
∙,  ∘\bullet, \; \circ
solid dot, open dot
On a graph: endpoint included, endpoint excluded.
Transformations
af(b(x−h))+ka f(b(x - h)) + k
the four-knob form
Outside letters move it vertically, inside letters horizontally.
f(x−h)f(x - h)
f of x minus h
Shifts right by hh: the sign goes the opposite way.
−f(x)-f(x) vs f(−x)f(-x)
two mirrors
Flip across the xx-axis against flip across the yy-axis.
Same marks, different job
f−1f^{-1} vs 1f\frac{1}{f}The inverse function against the reciprocal.
f(x)f(x)The brackets apply ff; they never mean multiplication.
(2,5)(2, 5)An open interval in a domain; a point in the plane on a graph.
the bar ∣\midSuch that, inside set braces; given, inside P(⋅)P(\cdot); divides, between integers.
Function Notation at a Glance·/functions/basicsLearn Math Class

Evaluating Piecewise Functions

To evaluate a piecewise function at a specific input:

Step 1: Determine which condition the input satisfies.

Step 2: Use the corresponding formula to compute the output.

Only one piece applies to each input. The other formulas are irrelevant for that evaluation.

Example
Let f(x)={3x+2if x<1x2−1if x≥1f(x) = \begin{cases} 3x + 2 & \text{if } x < 1 \\ x^2 - 1 & \text{if } x \geq 1 \end{cases}
Find f(−2)f(-2): Since −2<1-2 < 1, use 3x+23x + 2. f(−2)=3(−2)+2=−4f(-2) = 3(-2) + 2 = -4.
Find f(1)f(1): Since 1≥11 \geq 1, use x2−1x^2 - 1. f(1)=1−1=0f(1) = 1 - 1 = 0.
Find f(4)f(4): Since 4≥14 \geq 1, use x2−1x^2 - 1. f(4)=16−1=15f(4) = 16 - 1 = 15.

Boundary points require attention. The condition that includes the boundary (with ≤\leq or ≥\geq) determines which formula to use. At x=1x = 1 above, the condition x≥1x \geq 1 applies, not x<1x < 1.

Errors often occur at boundaries when the wrong piece is selected. Always check the inequality symbols carefully.

Evaluating a piecewise function is a lookup first and a calculation second: the input picks the formula.

Graphing Piecewise Functions

To graph a piecewise function, graph each piece on its designated interval, then combine them.

Step 1: Identify each piece and its interval.

Step 2: Graph each piece as if it were defined everywhere, but only draw the portion within its interval.

Step 3: Mark endpoints appropriately — solid dot for included endpoints, open dot for excluded endpoints.

For f(x)={x+3if x<12x−1if x≥1f(x) = \begin{cases} x + 3 & \text{if } x < 1 \\ 2x - 1 & \text{if } x \geq 1 \end{cases}:

The first piece is a line with slope 11, drawn for x<1x < 1. At x=1x = 1, this piece gives 1+3=41 + 3 = 4, but x=1x = 1 is excluded, so place an open dot at (1,4)(1, 4).

The second piece is a line with slope 22, drawn for x≥1x \geq 1. At x=1x = 1, this piece gives 2(1)−1=12(1) - 1 = 1, and x=1x = 1 is included, so place a solid dot at (1,1)(1, 1).

Pitfall: Forgetting endpoint markers
Drawing both lines right up to x=1x = 1 with no dots puts two points above x=1x = 1, (1,4)(1, 4) and (1,1)(1, 1), so the graph seems to give two outputs. An open dot at (1,4)(1, 4) and a solid dot at (1,1)(1, 1) show that f(1)=1f(1) = 1.

The graph shows two line segments that do not connect — there is a jump at x=1x = 1 from height 11 to (approaching) height 44.

The visual reveals discontinuities. Pieces that connect smoothly indicate continuity at that boundary. Pieces that don't connect indicate a jump.
The three steps on the function of this section. Press Next to carry out one step at a time.
DownloadPNG2×PDF
x+3x + 3 if x<1x < 1, and 2x−12x - 1 if x≥1x \geq 1Step 1 of 3
Step
x+3x + 3 if x<1x < 1, and 2x−12x - 1 if x≥1x \geq 1
1
Identify each piece and its interval
x+3x + 3 on x<1x < 1; 2x−12x - 1 on x≥1x \geq 1
2
Draw each piece only within its interval
a line of slope 11 left of x=1x = 1; a line of slope 22 from x=1x = 1 on
3
Mark the endpointsSolid dot if included, open dot if excluded
open dot at (1,4)(1, 4), solid dot at (1,1)(1, 1)
Graphing a piecewise function, step by step·/functions/piecewiseLearn Math Class
Graphing x + 3 for x < 1 and 2x - 1 for x >= 1xy−3−2−11234−11234567x + 3 for x < 12x − 1 for x ≥ 1(1, 4) excluded: open dot(1, 1) included: solid dotEach line kept only on its interval; the dots show who owns x = 1
Graph each piece on its own interval

Each line is drawn as if it ran everywhere (faint dashes), then only its own interval is kept. At x = 1 the first piece would give 4, but x = 1 is excluded, so (1, 4) gets an open dot; the second piece gives 1 and includes x = 1, so (1, 1) gets a solid dot. The gap between the two dots is the jump.

Open and closed dots are part of the graph, not decoration: they say which piece owns each boundary.

Domain of Piecewise Functions

The domain of a piecewise function is the union of all intervals covered by its pieces.

If the pieces cover all real numbers without gaps, the domain is (−∞,∞)(-\infty, \infty).

If the pieces leave gaps, the domain excludes those intervals.

Example
For f(x)={x2if x≤−1xif x≥0f(x) = \begin{cases} x^2 & \text{if } x \leq -1 \\ \sqrt{x} & \text{if } x \geq 0 \end{cases}:
The first piece covers (−∞,−1](-\infty, -1]. The second covers [0,∞)[0, \infty). The interval (−1,0)(-1, 0) is not covered by either piece.
Domain: (−∞,−1]∪[0,∞)(-\infty, -1] \cup [0, \infty).

Additionally, each piece must be valid on its interval. A piece involving x−3\sqrt{x - 3} on [0,5][0, 5] would require x≥3x \geq 3 for the formula to work, potentially reducing the effective domain of that piece to [3,5][3, 5].

The domain is determined by both the stated conditions and the natural restrictions of each formula. Both must be satisfied.
Domain of x^2 for x <= -1 and sqrt x for x >= 0x² covers x ≤ −1(−∞, −1]√x covers x ≥ 0[0, ∞)−4−3−2−101234Dom f: no piece covers (−1, 0)(−∞, −1] ∪ [0, ∞)includedexcludedThe domain is the union of the pieces’ intervals — gaps stay out
Two intervals, one domain with a gap

x² is used only for x ≤ −1 and √x only for x ≥ 0. Laying the two intervals on one line and keeping everything either piece covers gives (−∞, −1] ∪ [0, ∞); the inputs between −1 and 0 belong to no piece, so they are not in the domain.

Remember to intersect each interval with what its own formula allows.

Range of Piecewise Functions

RULE
The range of a piecewise function is the union of the ranges of all pieces, restricted to their respective intervals.

Each piece contributes outputs from its portion of the domain. The combined range collects all these outputs.

Example
For f(x)={2if x<0x+1if x≥0f(x) = \begin{cases} 2 & \text{if } x < 0 \\ x + 1 & \text{if } x \geq 0 \end{cases}:
The first piece is constant at 22 for all x<0x < 0. It contributes {2}\{2\} to the range.
The second piece is linear starting at x=0x = 0. At x=0x = 0, output is 11. As x→∞x \to \infty, output →∞\to \infty. This piece contributes [1,∞)[1, \infty) to the range.
Combined range: {2}∪[1,∞)=[1,∞)\{2\} \cup [1, \infty) = [1, \infty) (since 22 is already in [1,∞)[1, \infty)).

Pitfall: Taking the range of the whole formula
Taking all outputs of x+1x + 1 gives the second piece, and the whole function, the range (−∞,∞)(-\infty, \infty). On its interval x≥0x \geq 0 the piece only reaches [1,∞)[1, \infty), so the range is [1,∞)[1, \infty).

Finding the range may require analyzing each piece separately — finding minima, maxima, and behavior on each interval — then combining results.

Discontinuities can create gaps in the range if no piece produces certain values, or they can be invisible in the range if different pieces cover those values.
Range of 2 for x < 0 and x + 1 for x >= 0 is [1, inf)xy−4−3−2−11234−1123456outputs [1, ∞)2 for x < 0x + 1 for x ≥ 0{2} is already inside [1, ∞)Range = {2} ∪ [1, ∞) = [1, ∞)
Collecting the outputs of each piece

The constant piece outputs only 2; the line x + 1, starting at (0, 1) with a solid dot, outputs every value from 1 upward. The amber bar on the y-axis is the union of the two: 2 already lies in [1, ∞), so the range is [1, ∞).

A piece's outputs can hide inside another piece's range, as the constant 2 does here.

Continuity of Piecewise Functions

A piecewise function is continuous at a boundary point if the two pieces meeting there produce the same value. The graph connects without a jump.

For continuity at x=cx = c where two pieces meet:

Continuity of Piecewise Functions
lim⁡x→c−f(x)=lim⁡x→c+f(x)=f(c)\lim_{x \to c^-} f(x) = \lim_{x \to c^+} f(x) = f(c)

The left piece's limit, the right piece's limit, and the actual value at cc must all agree.

Example
For f(x)={x2if x≤24x−4if x>2f(x) = \begin{cases} x^2 & \text{if } x \leq 2 \\ 4x - 4 & \text{if } x > 2 \end{cases}:
At x=2x = 2: Left piece gives 22=42^2 = 4. Right piece as x→2+x \to 2^+ gives 4(2)−4=44(2) - 4 = 4. Both equal 44.
The function is continuous at x=2x = 2. The pieces connect.

Example
For g(x)={x+1if x<32x−3if x≥3g(x) = \begin{cases} x + 1 & \text{if } x < 3 \\ 2x - 3 & \text{if } x \geq 3 \end{cases}:
At x=3x = 3: Left piece as x→3−x \to 3^- gives 3+1=43 + 1 = 4. Right piece gives 2(3)−3=32(3) - 3 = 3.
The limits differ (4≠34 \neq 3), so the function is discontinuous at x=3x = 3. There is a jump.

The table below collects both cases — the continuous example and the discontinuous example — with the three values that must agree for continuity and the verdict at each boundary.
DownloadPNG2×PDF
Layout
✓Yes✕No
Function and boundaryLeft limit (x → c⁻)Right limit (x → c⁺)f(c)Continuous at c?
x² (x ≤ 2), 4x − 4 (x > 2); at c = 2444✓
x + 1 (x < 3), 2x − 3 (x ≥ 3); at c = 3433✕
Continuity of Piecewise FunctionsLearn Math Class
-5-335-33a jump at x = 0
x + 1 for x < 0, x − 1 for x ≥ 0: a jump at 0

The two pieces meet the boundary x = 0 at different heights, 1 from the left and −1 from the right, so the graph jumps; the open dot marks the value the left piece approaches but does not take, the closed dot the value the function actually has. Continuity at the boundary would need the two dots to coincide. Move the pieces until they meet on the piecewise function explorer.

Checking continuity at a boundary is therefore a matter of comparing two limits with one value.

Absolute Value as Piecewise

The absolute value function is the most familiar piecewise function:

Absolute Value as Piecewise
∣x∣={xif x≥0−xif x<0|x| = \begin{cases} x & \text{if } x \geq 0 \\ -x & \text{if } x < 0 \end{cases}

Did you know: One formula for any broken line
A continuous graph made of finitely many straight pieces needs no cases: it equals a+bxa + bx plus one term c ∣x−k∣c\,|x - k| for each corner kk, with cc half the change of slope there. For example, x+∣x∣2\frac{x + |x|}{2} is 00 for x<0x < 0 and xx for x≥0x \geq 0.

For non-negative inputs, the output equals the input. For negative inputs, the output equals the negation of the input (making it positive).

The graph is V-shaped with vertex at the origin. The right arm has slope 11; the left arm has slope −1-1. The pieces meet at (0,0)(0, 0) and connect continuously — both pieces give 00 at x=0x = 0.

The corner at the origin is the only place where the slope changes, from −1-1 on the left to 11 on the right, a change of 22. Moving the corner to x=kx = k gives ∣x−k∣|x - k|, and a constant factor cc in front of it makes the change of slope 2c2c instead.

Transformed absolute value functions shift the V:

Absolute Value as Piecewise
f(x)=∣x−3∣+2={(x−3)+2if x≥3−(x−3)+2if x<3={x−1if x≥3−x+5if x<3f(x) = |x - 3| + 2 = \begin{cases} (x - 3) + 2 & \text{if } x \geq 3 \\ -(x - 3) + 2 & \text{if } x < 3 \end{cases} = \begin{cases} x - 1 & \text{if } x \geq 3 \\ -x + 5 & \text{if } x < 3 \end{cases}

The vertex moves to (3,2)(3, 2).

With more than one absolute value, each term adds its own split point. The absolute value page works through ∣x−2∣+∣x+1∣|x - 2| + |x + 1|, which becomes three pieces.

Equations involving absolute values often require piecewise analysis. Solving ∣x−2∣=5|x - 2| = 5 means considering both pieces: x−2=5x - 2 = 5 (giving x=7x = 7) and −(x−2)=5-(x - 2) = 5 (giving x=−3x = -3).

Pitfall: Solving only the positive case
Removing the bars from ∣x+4∣=6|x + 4| = 6 to get x+4=6x + 4 = 6 gives only x=2x = 2. The negative piece, −(x+4)=6-(x + 4) = 6, gives x=−10x = -10 as well, and ∣−10+4∣=6|-10 + 4| = 6.

Each piece turns the absolute value equation into an ordinary linear equation, valid on its own side of the vertex. The solution from the piece with x−2≥0x - 2 \geq 0 must satisfy x≥2x \geq 2, and the one from the piece with x−2<0x - 2 < 0 must satisfy x<2x < 2; here 7≥27 \geq 2 and −3<2-3 < 2, so both solutions stand. On the number line they are the two points at distance 55 from 22.
-5-335-33the absolute value, built from two pieces
|x| as two pieces: −x then x

The left ray is the line y = −x on x < 0 and the right ray is y = x on x ≥ 0; the two pieces meet at the origin at the same height, so the V is continuous even though its formula changes there. The closed dot at 0 belongs to the right piece. Rebuild the V from its two pieces on the piecewise function explorer.

Most functions with a corner are piecewise in this same quiet way.
The section's transformed V, from bars to pieces, one move at a time.
DownloadPNG2×PDF
Absolute value as piecewise

Removing the bars

A transformed absolute value is two linear formulas, one on each side of the vertex.
01
Absolute value formBefore
f(x)=∣x−3∣+2f(x) = |x - 3| + 2
↓Split at the vertex— |x − 3| is x − 3 for x ≥ 3 and −(x − 3) for x < 3
02
Two pieces, unsimplified
{(x−3)+2if x≥3−(x−3)+2if x<3\begin{cases} (x - 3) + 2 & \text{if } x \geq 3 \\ -(x - 3) + 2 & \text{if } x < 3 \end{cases}
↓Simplify each piece— each one is an ordinary linear formula
03
Piecewise formAfter
{x−1if x≥3−x+5if x<3\begin{cases} x - 1 & \text{if } x \geq 3 \\ -x + 5 & \text{if } x < 3 \end{cases}
Both pieces give 22 at x=3x = 3, so the graph has no jump: the vertex moves to (3,2)(3, 2).
Writing |x − 3| + 2 piecewise·/functions/piecewiseLearn Math Class
Each piece is valid only on its own side of x=3x = 3. The same split is what solves equations such as ∣x−2∣=5|x - 2| = 5: one linear equation per piece.

Step Functions

Step functions are piecewise functions where each piece is constant. The graph consists of horizontal segments with jumps between them — like a staircase.

The floor function ⌊x⌋\lfloor x \rfloor returns the greatest integer less than or equal to xx:

Step Functions
⌊2.7⌋=2,⌊−1.3⌋=−2,⌊5⌋=5\lfloor 2.7 \rfloor = 2, \quad \lfloor -1.3 \rfloor = -2, \quad \lfloor 5 \rfloor = 5

Pitfall: Rounding negative inputs toward zero
Dropping the decimal part of −2.5-2.5 gives ⌊−2.5⌋=−2\lfloor -2.5 \rfloor = -2, but −2-2 is greater than −2.5-2.5. The greatest integer less than or equal to −2.5-2.5 is −3-3.

Negative inputs follow the same definition as positive ones. The integers less than or equal to −1.3-1.3 are −2,−3,−4,…-2, -3, -4, \ldots, and the greatest of them is −2-2. On the number line, the floor always moves left to the nearest integer, or stays put when the input is already an integer.

The graph has horizontal segments at each integer height, jumping up at each integer input. The segment at height nn covers [n,n+1)[n, n+1) — closed on the left, open on the right. Subtracting this staircase from xx leaves the fractional part {x}=x−⌊x⌋\{x\} = x - \lfloor x \rfloor; both are covered on the integer and fractional part page.

The ceiling function ⌈x⌉\lceil x \rceil returns the least integer greater than or equal to xx:

Step Functions
⌈2.7⌉=3,⌈−1.3⌉=−1,⌈5⌉=5\lceil 2.7 \rceil = 3, \quad \lceil -1.3 \rceil = -1, \quad \lceil 5 \rceil = 5

The segments cover (n−1,n](n-1, n] — open on the left, closed on the right.

Did you know: Halves round to the even neighbour
Python's round function and the default rounding of the IEEE 754 floating-point standard send 2.52.5 to 22 and 3.53.5 to 44: each half goes to the even integer. Always rounding halves up would push long sums upward; this way about half of them go down.

Both functions have jump discontinuities at every integer. The domain is all real numbers; the range is all integers Z\mathbb{Z}.

Rounding to the nearest integer is a step function as well. Its jumps sit halfway between integers, at 0.5,1.5,2.5,…0.5, 1.5, 2.5, \ldots, and at each jump a rule has to decide which neighbour the half itself goes to. The rule taught in school sends every half up, so 2.52.5 becomes 33.

Step functions model situations with discrete jumps: postage rates by weight, tax brackets, rounding rules. The table below pairs the floor and ceiling functions side by side to highlight the small but important differences between them.
DownloadPNG2×PDF
Layout
FunctionDefinitionSegment shapeExamples
Floor ⌊x⌋greatest integer ≤ xhorizontal segment on [n, n+1) at height n — closed left, open right⌊2.7⌋ = 2, ⌊−1.3⌋ = −2, ⌊5⌋ = 5
Ceiling ⌈x⌉least integer ≥ xhorizontal segment on (n−1, n] at height n — open left, closed right⌈2.7⌉ = 3, ⌈−1.3⌉ = −1, ⌈5⌉ = 5
Step FunctionsLearn Math Class
-5-335-33a two-piece step: −1, then 1
A two-piece step: −1 then 1

Each piece is a constant, so the graph is two horizontal segments with a jump of 2 at x = 0; the open and closed dots record which piece owns the boundary. Every step function is built this way, one flat piece per interval. Try the three-piece sign function on the piecewise function explorer.

Step functions model anything that changes only at thresholds.

Real-World Applications

Piecewise functions naturally model situations where rules change at thresholds.

Tax brackets: Income tax rates increase at certain income levels. Income below 10,000 dollars might be taxed at 10%10\%, income from 10,000 dollars to 40,000 dollars at 20%20\%, and income above 40,000 dollars at 30%30\%.

Real-World Applications
T(x)={0.10xif x≤100001000+0.20(x−10000)if 10000<x≤400007000+0.30(x−40000)if x>40000T(x) = \begin{cases} 0.10x & \text{if } x \leq 10000 \\ 1000 + 0.20(x - 10000) & \text{if } 10000 < x \leq 40000 \\ 7000 + 0.30(x - 40000) & \text{if } x > 40000 \end{cases}

Pitfall: Taxing all income at the top rate
Applying 30%30\% to the whole income gives T(50000)=0.30⋅50000=15000T(50000) = 0.30 \cdot 50000 = 15000. Only the 1000010000 above 4000040000 is taxed at 30%30\%, so T(50000)=7000+0.30⋅10000=10000T(50000) = 7000 + 0.30 \cdot 10000 = 10000.

The constants in the second and third pieces are the tax already owed on the lower brackets. The 10001000 is 10%10\% of the first 10,00010{,}000 dollars, and 7000=1000+0.20⋅30,0007000 = 1000 + 0.20 \cdot 30{,}000 is the tax on the first 40,00040{,}000 dollars. Because of them, adjacent pieces agree at each threshold: both give 10001000 at x=10000x = 10000 and 70007000 at x=40000x = 40000.

Shipping costs: Packages under 11 pound cost 5 dollars. Packages from 11 to 55 pounds cost 5 dollars plus 2 dollars per additional pound. Packages over 55 pounds cost 13 dollars plus 1.50 dollars per additional pound.

Utility rates: Electricity might cost one rate for the first 500500 kWh and a higher rate beyond that threshold.

Parking fees: First hour free, next two hours at one rate, additional hours at another rate.

In each case, the rule changes at specific boundaries, and the piecewise function captures this structure mathematically. The table below collects four common application patterns with their threshold structure.
DownloadPNG2×PDF
Layout
SituationThreshold(s)Piecewise structure
Tax bracketsincome levels (e.g., 10,000,10,000, 40,000)tax rate increases at each bracket boundary; pieces are continuous (rates align at thresholds)
Shipping costsweight bands (under 1 lb, 1–5 lb, over 5 lb)flat fee for first band, then per-unit surcharge added above
Utility ratesusage tier (e.g., 500 kWh)one rate up to the tier, a higher rate beyond
Parking feestime periods (first hour, next two, beyond)different rate per time period; often a free or fixed first piece
Real-World ApplicationsLearn Math Class
Wherever a charge or a rate changes at a threshold, a piecewise function describes it exactly.

Writing Piecewise Functions

Constructing a piecewise function from a description or graph requires identifying the pieces and their intervals.

From a graph:

Step 1: Identify distinct segments or curves.

Step 2: Determine the formula for each segment (line, parabola, constant, etc.).

Step 3: Identify the interval each segment covers, noting open or closed endpoints.

Step 4: Write the piecewise notation with each formula and its condition.

From a verbal description:

Step 1: Identify the thresholds where rules change.

Step 2: Write the formula for each region between thresholds.

Step 3: Specify conditions using inequalities.

Example: "A plumber charges 50 dollars for the first hour and 30 dollars for each additional hour."

Let C(t)C(t) be the cost for tt hours of work (t>0t > 0):

Writing Piecewise Functions
C(t)={50if 0<t≤150+30(t−1)if t>1C(t) = \begin{cases} 50 & \text{if } 0 < t \leq 1 \\ 50 + 30(t - 1) & \text{if } t > 1 \end{cases}

Simplifying the second piece: 50+30t−30=30t+2050 + 30t - 30 = 30t + 20.

Writing Piecewise Functions
C(t)={50if 0<t≤130t+20if t>1C(t) = \begin{cases} 50 & \text{if } 0 < t \leq 1 \\ 30t + 20 & \text{if } t > 1 \end{cases}

Pitfall: Charging the first hour twice
Writing the second piece as 50+30t50 + 30t counts the first hour in both terms: it gives C(2)=50+60=110C(2) = 50 + 60 = 110. Only the hours after the first cost 3030 each, so C(2)=50+30(2−1)=80C(2) = 50 + 30(2 - 1) = 80.

The threshold t=1t = 1 is where the rule changes, and both pieces give 5050 there, so the charge does not jump. Past it, each extra hour adds 3030: at t=3t = 3 the second piece gives 30(3)+20=11030(3) + 20 = 110, the 5050 for the first hour plus 2⋅30=602 \cdot 30 = 60 for the other two.
The plumber example of this section, one step at a time. Press Next to carry out each step.
DownloadPNG2×PDF
50 dollars for the first hour, 30 for each additional hourStep 1 of 4
Step
50 dollars for the first hour, 30 for each additional hour
1
Identify the thresholds where the rule changes
t=1t = 1
2
Write the formula for each region
5050 and 50+30(t−1)50 + 30(t - 1)
3
Specify the conditions with inequalities
0<t≤10 < t \leq 1 and t>1t > 1
4
Simplify and write the function
C(t)=50C(t) = 50 if 0<t≤10 < t \leq 1, and 30t+2030t + 20 if t>1t > 1
From a description to a piecewise function·/functions/piecewiseLearn Math Class
Plumber cost C(t): 50 for the first hour, then 30t + 20tC123420406080100120threshold t = 1$50 flat30t + 20: +$30 per extra hourC(3) = 110The rule changes at t = 1 hour; the cost C does not jump
The plumber's charge as a graph

C(t) = 50 for 0 < t ≤ 1 and 30t + 20 for t > 1. The flat piece is the first-hour charge; after the threshold at one hour, the line climbs $30 per hour. Both pieces give $50 at t = 1, so the graph has no jump, and three hours cost C(3) = $110.

Drawing the function is a quick check that the written pieces match the description.

Common Mistakes

Several errors recur when working with piecewise functions.

Using the wrong piece at a boundary: At x=3x = 3 with conditions x<3x < 3 and x≥3x \geq 3, the second piece applies, not the first. The inequality symbols determine which piece owns the boundary.

Overlapping conditions: Writing x≤2x \leq 2 and x≥2x \geq 2 creates overlap at x=2x = 2. Both pieces claim this input, making the function ambiguous. Use x<2x < 2 and x≥2x \geq 2, or x≤2x \leq 2 and x>2x > 2.

Gaps in conditions: Writing x<1x < 1 and x>3x > 3 leaves [1,3][1, 3] undefined. Unless this gap is intentional (limiting the domain), conditions should cover all intended inputs.

Assuming continuity: Not all piecewise functions are continuous. Checking whether pieces connect at boundaries is essential — do not assume they do.

Forgetting endpoint markers when graphing: Open and closed dots distinguish included from excluded endpoints. Without them, the graph is incomplete and potentially misleading.

Evaluating all pieces instead of one: Only the piece whose condition the input satisfies should be used. The other formulas do not apply to that input.

The table below collects each mistake with the specific problem it causes and the rule of thumb that prevents it.
DownloadPNG2×PDF
Layout
MistakeWhat goes wrongHow to avoid it
Using the wrong piece at a boundarywrong output at boundary inputscheck inequality symbols — the piece with ≤ or ≥ owns the boundary
Overlapping conditionsfunction is ambiguous where conditions overlappair ≤ with >, or < with ≥, so each boundary lives in exactly one piece
Gaps in conditionsfunction undefined on some intervalsverify conditions cover the entire intended domain
Assuming continuitymisreading behavior at boundariesalways check that adjacent pieces produce the same value at the boundary
Forgetting endpoint markersgraph is incomplete or misleadingsolid dot for included endpoint, open dot for excluded — for every piece transition
Evaluating all pieces at one inputwrong answer or confusion about which output appliesonly the piece whose condition the input satisfies should be used
Common MistakesLearn Math Class
Five more mistakes are marked where they happen in the sections above. Each is worked through here in full, with the wrong and the right working side by side.
DownloadPNG2×PDF
1Taking the range of the whole formula
To find the range of a piecewise function, the range of each formula is found as if the formula ran over all real numbers. The condition beside it is ignored, so a piece seems to produce outputs it never reaches.
Start
For f(x)={2if x<0x+1if x≥0f(x) = \begin{cases} 2 & \text{if } x < 0 \\ x + 1 & \text{if } x \geq 0 \end{cases},
Wrong turn
Error here
The line x+1x + 1 takes every real value, so the range is given as (−∞,∞)(-\infty, \infty).
Right path
On x≥0x \geq 0 the line starts at 0+1=10 + 1 = 1 and rises, so the second piece gives [1,∞)[1, \infty). The first piece gives {2}\{2\}. The range is {2}∪[1,∞)=[1,∞)\{2\} \cup [1, \infty) = [1, \infty).
Why it happensThe range of a single formula is a familiar task, and the condition next to it reads like a note on when to use the formula rather than a limit on its outputs.
How to checkTest a value from the claimed range. Is there an input with f(x)=0f(x) = 0? The first piece gives only 22, and x+1=0x + 1 = 0 needs x=−1x = -1, which is not in x≥0x \geq 0. So 00 is not in the range.
2Solving only the positive case
An absolute value equation is solved by simply removing the bars, which uses only the piece for a non-negative inside. The solutions that come from the other piece are lost.
Wrong turn
Error here
∣x+4∣=6|x + 4| = 6 becomes x+4=6x + 4 = 6, so x=2x = 2 is given as the only solution.
Right path
Split into the two pieces. If x+4≥0x + 4 \geq 0: x+4=6x + 4 = 6, so x=2x = 2, and 2≥−42 \geq -4 holds. If x+4<0x + 4 < 0: −(x+4)=6-(x + 4) = 6, so x+4=−6x + 4 = -6 and x=−10x = -10, and −10<−4-10 < -4 holds. Both x=2x = 2 and x=−10x = -10 are solutions.
Why it happensThe bars look like brackets that can be dropped, and the positive case is the one that comes to mind first.
How to checkOn the number line, the inputs at distance 66 from −4-4 are −4+6=2-4 + 6 = 2 and −4−6=−10-4 - 6 = -10; there are two of them whenever the right side is positive. Substituting confirms both: ∣2+4∣=6|2 + 4| = 6 and ∣−10+4∣=∣−6∣=6|-10 + 4| = |-6| = 6.
3Rounding negative inputs toward zero
The floor of a negative number is found by dropping its decimal part. That moves the number toward zero, which for a negative number is upward, while the floor always moves downward.
Wrong turn
Error here
⌊−2.5⌋=−2\lfloor -2.5 \rfloor = -2, by cutting off the .5.5.
Right path
The integers less than or equal to −2.5-2.5 are −3,−4,−5,…-3, -4, -5, \ldots, and the greatest of them is −3-3. So ⌊−2.5⌋=−3\lfloor -2.5 \rfloor = -3. In the same way ⌊−1.3⌋=−2\lfloor -1.3 \rfloor = -2.
Why it happensFor positive numbers, dropping the decimal part does give the floor, ⌊2.7⌋=2\lfloor 2.7 \rfloor = 2, so the shortcut seems to work everywhere. Calculators and programming languages that truncate also return −2-2.
How to checkThe floor is never greater than the input, and ⌊x⌋≤x<⌊x⌋+1\lfloor x \rfloor \leq x < \lfloor x \rfloor + 1. Here −2>−2.5-2 > -2.5, so −2-2 fails; −3≤−2.5<−2-3 \leq -2.5 < -2 holds.
4Taxing all income at the top rate
An income is placed in its bracket, and that bracket's rate is applied to the whole income. In the piecewise formula, each rate applies only to the part of the income that lies inside its own bracket.
Wrong turn
Error here
An income of 50,00050{,}000 dollars lies in the bracket x>40000x > 40000, so T(50000)=0.30⋅50000=15000T(50000) = 0.30 \cdot 50000 = 15000.
Right path
Use the third piece. T(50000)=7000+0.30(50000−40000)=7000+3000=10000T(50000) = 7000 + 0.30(50000 - 40000) = 7000 + 3000 = 10000. The 70007000 is the tax on the first 40,00040{,}000 dollars: 0.10⋅10000+0.20⋅30000=1000+60000.10 \cdot 10000 + 0.20 \cdot 30000 = 1000 + 6000.
Why it happensThe phrase "the 30%30\% bracket" sounds like a rate for the whole income, and a single multiplication is simpler than the piecewise formula.
How to checkCompare two neighboring incomes. With the wrong method, an income of 40,00040{,}000 dollars pays 0.20⋅40000=80000.20 \cdot 40000 = 8000, but one dollar more pays 0.30⋅40001≈120000.30 \cdot 40001 \approx 12000, a jump of about 40004000 dollars. The piecewise TT has no jumps: both pieces give 70007000 at x=40000x = 40000.
5Charging the first hour twice
A description has a fixed charge for a first block and a rate for what comes after it. The rate is applied to the whole quantity instead of only to the part beyond the first block.
Wrong turn
Error here
"50 dollars for the first hour and 30 dollars for each additional hour" is written as C(t)=50+30tC(t) = 50 + 30t for t>1t > 1. Then C(2)=50+60=110C(2) = 50 + 60 = 110.
Right path
After the first hour, t−1t - 1 hours remain, so C(t)=50+30(t−1)=30t+20C(t) = 50 + 30(t - 1) = 30t + 20 for t>1t > 1. Then C(2)=50+30=80C(2) = 50 + 30 = 80: the first hour plus one additional hour.
Why it happens"30 per hour" is turned straight into 30t30t, and the word "additional" is lost on the way.
How to checkCompare the pieces at the threshold. The correct pieces both give 5050 at t=1t = 1. As tt approaches 11 from above, the wrong second piece approaches 50+30=8050 + 30 = 80, a jump of 3030 dollars that the description never mentions.
Common pitfalls with piecewise functions·/functions/piecewiseLearn Math Class
Each slip ignores the condition attached to a piece. A piece contributes only the outputs it takes on its own interval, an absolute value equation splits into two cases, the floor rounds −2.5-2.5 down to −3-3, a tax bracket taxes only the income inside it, and the hours after the first are t−1t - 1, not tt. Comparing the pieces at the boundary where they meet, or testing a value from the claimed answer, catches each slip.

Workflow Summary

Most of the tasks on this page — evaluating a piecewise function at an input, graphing it, finding its domain or range, checking continuity at a boundary — share the same general principle: handle each piece on its own interval, then combine. The table below collects the five core tasks with the procedure for each and the pitfall to watch for, useful as a checklist when working through a new piecewise function from scratch.
DownloadPNG2×PDF
Layout
TaskWhat to doWatch out for
Evaluate at a specific inputidentify which condition the input satisfies; apply that formula onlyboundary points — the inequality symbols decide which piece owns the boundary
Graph the functiongraph each piece on its interval and combineuse solid dots for included endpoints, open dots for excluded
Find the domaintake the union of the intervals stated by the conditionsalso check each formula's natural restrictions (denominators, square roots, logs)
Find the rangefind the outputs of each piece on its interval, then take the uniongaps in the range can appear if no piece covers some y-values
Check continuity at a boundary ccompute left limit, right limit, and f(c)all three must agree — any mismatch is a discontinuity
Workflow SummaryLearn Math Class

Skills You Should Learn

Each skill opens its step-by-step method page. Skills marked "On this page" are taught above.
Taught on this page
More functions methods

Piecewise Functions FAQ

When do you use an open circle and when a filled one?

+
A filled circle marks an endpoint the piece includes, matching a condition written with ≤\leq or ≥\geq. An open circle marks one it excludes, matching a strict << or >>. At a jump exactly one piece owns the boundary, so one dot is filled and the other open on the same vertical line, which is what keeps the rule single-valued.Read more →

Can a piecewise linear function be written without cases?

+
Yes, if its graph is continuous. A broken line made of finitely many straight pieces equals a+bxa + bx plus one term c ∣x−k∣c\,|x - k| for each corner kk, where cc is half the change of slope there, since ∣x−k∣|x - k| turns from slope −1-1 to slope 11. For example, x+∣x∣2\frac{x + |x|}{2} is 00 for x<0x < 0 and xx for x≥0x \geq 0: the slope changes by 11 at 00, so c=12c = \frac{1}{2}.Read more →

Can two pieces both include the same boundary point?

+
Only if their formulas agree there. Writing x≤2x \leq 2 and x≥2x \geq 2 hands x=2x = 2 to both pieces; with x2x^2 and 4x−44x - 4 both give 44, so the output is still a single value. If the formulas give different values, one input has two outputs and the rule is not a function. Pairing ≤\leq with >>, or << with ≥\geq, avoids the question entirely.Read more →

How do you write a first-hour fee plus an hourly rate as a piecewise function?

+
Give the first block its own piece and charge the rate only on what lies beyond it. For 50 dollars for the first hour and 30 dollars for each additional hour, C(t)=50C(t) = 50 for 0<t≤10 < t \leq 1 and C(t)=50+30(t−1)=30t+20C(t) = 50 + 30(t - 1) = 30t + 20 for t>1t > 1. Writing 50+30t50 + 30t charges the first hour twice: it gives C(2)=110C(2) = 110 instead of 8080, and jumps by 3030 at t=1t = 1.Read more →