# Piecewise Functions: Graphs, Limits, Continuity and Derivatives

> Piecewise functions explained: how to read and graph them, find one-sided limits, check continuity and differentiability, and integrate across pieces.

Source: https://practicecalculus.com/functions/piecewise-functions
Updated: 2026-11-03

$$ f(x) = \begin{cases} f_1(x) & x < a \\ f_2(x) & x \ge a \end{cases} $$

## At a glance

- **Domain:** The union of the intervals the pieces cover
- **Continuous at x = a:** When $\lim_{x\to a^-}f_1(x) = \lim_{x\to a^+}f_2(x) = f(a)$
- **Derivative:** $f'(x) = \begin{cases} f_1'(x) & x < a \\ f_2'(x) & x > a \end{cases}$
- **Integral:** $\int_b^c f(x)\,dx = \int_b^a f_1(x)\,dx + \int_a^c f_2(x)\,dx$
- **Examples:** Absolute value, floor function, tax brackets, shipping rates

## Key takeaways

- A piecewise function uses different formulas on different intervals of its domain.
- At a break point, compare the left-hand limit, the right-hand limit and the function value to test continuity.
- Differentiate each piece on its open interval, then check break points separately with one-sided derivatives.
- To integrate across a break point, split the integral there.

A **piecewise function** is a function defined by different formulas on different parts of its domain. The rule tells you which formula to use based on where $x$ is. Piecewise functions are the standard test cases for [limits](/blog/what-is-a-limit), [continuity](/blog/continuity) and differentiability, because the interesting behavior happens where the pieces meet.

## How to read a piecewise function

$$f(x) = \begin{cases} x^2 & x < 1 \\ 3 - x & x \ge 1 \end{cases}$$

To evaluate, first find which condition $x$ satisfies, then use that piece only. Here $f(0) = 0^2 = 0$, $f(1) = 3 - 1 = 2$ (because $x \ge 1$ includes $1$), and $f(2) = 3 - 2 = 1$.

## Graph of a piecewise function

```graph
title: 'Graph of a piecewise function with a jump at x = 1'
caption: 'The left piece $x^2$ approaches the open dot at $(1, 1)$. The right piece $3 - x$ starts at the closed dot $(1, 2)$, which is the actual value $f(1)$.'
x: [-2, 4]
y: [-1.5, 4.5]
functions:
  - expr: x^2
    label: y = x², x < 1
    domain: [-2, 1]
  - expr: 3 - x
    label: y = 3 − x, x ≥ 1
    domain: [1, 4]
points:
  - [1, 1, '(1, 1)', open]
  - [1, 2, '(1, 2)']
```

Each piece is drawn only on its own interval. An **open dot** marks an endpoint that is not included; a **closed dot** marks one that is.

## Limits of piecewise functions

At a break point $a$, compute the two [one-sided limits](/blog/how-to-evaluate-limits) separately, each with its own piece. For the function above at $a = 1$:

$$\lim_{x\to 1^-}f(x) = \lim_{x\to 1^-}x^2 = 1, \qquad \lim_{x\to 1^+}f(x) = \lim_{x\to 1^+}(3 - x) = 2$$

The one-sided limits differ, so $\lim_{x\to 1}f(x)$ does not exist, and the graph has a jump. Away from the break point, a limit is just [direct substitution](/rules/direct-substitution) into the active piece.

## Continuity at a break point

$f$ is continuous at $a$ when all three of these agree:

1. the left-hand limit $\lim_{x\to a^-}f(x)$,
2. the right-hand limit $\lim_{x\to a^+}f(x)$,
3. the value $f(a)$.

**Example: choosing a constant.** For which $k$ is

$$g(x) = \begin{cases} kx + 1 & x < 2 \\ x^2 & x \ge 2 \end{cases}$$

continuous? The left limit at $2$ is $2k + 1$ and the right limit and value are $2^2 = 4$. Setting $2k + 1 = 4$ gives $k = \frac{3}{2}$.

## Derivatives of piecewise functions

Inside each open interval, differentiate the active piece as usual. At a break point you need two checks:

- $f$ must be continuous there (a jump means no derivative).
- The left and right derivatives must match: $\lim_{h\to 0^-}\frac{f(a+h) - f(a)}{h} = \lim_{h\to 0^+}\frac{f(a+h) - f(a)}{h}$.

When both pieces are differentiable polynomials and $f$ is continuous at $a$, the second check reduces to comparing $f_1'(a)$ with $f_2'(a)$.

**Example: a corner.** The [absolute value function](/functions/absolute-value-function) $|x|$ is $-x$ for $x < 0$ and $x$ for $x \ge 0$. It is continuous at $0$, but the left slope is $-1$ and the right slope is $1$, so $|x|$ is not differentiable at $0$.

**Example: continuous but not smooth.** For $g$ above with $k = \frac{3}{2}$, the left slope at $2$ is $\frac{3}{2}$ and the right slope is $2x = 4$. They differ, so $g$ is continuous but not differentiable at $x = 2$.

## Integrating a piecewise function

Split the integral at every break point inside the interval. For the first function on $[0, 3]$:

$$\int_0^3 f(x)\,dx = \int_0^1 x^2\,dx + \int_1^3 (3 - x)\,dx = \frac{1}{3} + 2 = \frac{7}{3}$$

The second integral is $\left[3x - \frac{x^2}{2}\right]_1^3 = \frac{9}{2} - \frac{5}{2} = 2$. A single jump does not change the value of the integral, so it does not matter which piece owns the point $x = 1$.

## Common mistakes

1. **Using the wrong piece at the boundary.** Check whether the condition says $<$ or $\le$ before evaluating $f(a)$.
2. **Concluding continuity from one side.** Both one-sided limits and the value must agree.
3. **Assuming continuous means differentiable.** Corners like $|x|$ at $0$ are continuous but have no derivative.
4. **Differentiating the pieces and comparing them at a jump.** If $f$ is not continuous at $a$, it is not differentiable there, even if the piece slopes happen to match.
5. **Integrating one formula across the whole interval.** Always split at the break points.

## Related functions

The [floor and ceiling functions](/functions/floor-and-ceiling-functions) are piecewise constant step functions with a jump at every integer, and [absolute value](/functions/absolute-value-function) is the simplest piecewise function with a corner. For the full treatment of limits and continuity, see the guide to [continuity](/blog/continuity).

## Frequently asked questions

### How do you find the limit of a piecewise function?

Away from a break point, use the formula for that piece. At a break point, compute the left-hand limit with the left piece and the right-hand limit with the right piece. The limit exists only if they agree.

### How do you make a piecewise function continuous?

At each break point $a$, set the two pieces equal at $x = a$ and solve for the unknown constant. This forces the left and right limits to match $f(a)$.

### Is a continuous piecewise function always differentiable?

No. The pieces can meet with different slopes, creating a corner. The absolute value function $|x|$ is continuous at $0$ but not differentiable there.

### How do you graph a piecewise function?

Graph each formula only on its own interval. At each endpoint draw a closed dot if the endpoint is included and an open dot if it is not.
