Subscript and Superscript in LaTeX: _, ^, \textsubscript and Exponents

Quick answer

  • Subscript: _ in math mode, $x_i$. Superscript: ^ in math mode, $x^2$.
  • More than one character: use braces, $x_{i+1}$ and $x^{10}$; $x^10$ raises only the 1.
  • Both at once: $x_i^2$ (order does not matter).
  • In normal text: H\textsubscript{2}O and 1\textsuperscript{st}; _ and ^ outside math give Missing $ inserted.
  • Chemistry and units: \ce{H2O}, \ce{SO4^2-} with mhchem; $5\,\mathrm{m}^2$ or \qty{5}{\metre\squared} with siunitx.

A superscript in LaTeX is ^ and a subscript is _, both in math mode: $x^2$ is x squared and $x_i$ is x sub i. Anything longer than one character goes in braces, so $x^{10}$, not $x^10$. In running text use \textsuperscript{st} and \textsubscript{2}. This guide covers all of that plus exponents and powers, squared units, stacked and nested scripts, \limits on sums, prescripts for isotopes, chemical formulas with mhchem, ordinals, and the errors (“Double superscript”, “Missing { inserted”) you will meet.

You wantWriteWhere
x squared, x cubed$x^2$, $x^3$math mode
x to the power 10$x^{10}$math mode
x sub i, x sub i+1$x_i$, $x_{i+1}$math mode
both at once$x_i^2$math mode
1st, 2nd in a sentence1\textsuperscript{st}text mode
H₂O in a sentenceH\textsubscript{2}Otext mode
limits above and below Σ$\sum\limits_{i=1}^{n}$math mode
carbon-14 prescripts${}^{14}_{6}\mathrm{C}$math mode

Basic Superscripts

In LaTeX math mode, you create superscripts using the caret symbol (^). For a single character, you can place it directly after the caret. For multiple characters, wrap them in curly braces.

% Single character superscript
$x^2$

% Multiple characters require braces
$x^{2n}$
$e^{i\pi}$

% Without braces, only the first character is raised
$x^10$    % renders as x^1 followed by 0
$x^{10}$  % renders correctly as x to the power of 10

The braces tell LaTeX to treat everything inside them as a single group. This is one of the most common sources of errors for beginners — always use braces when your superscript contains more than one character.

Basic Subscripts

Subscripts work the same way as superscripts, but use the underscore character (_) instead of the caret. Again, single characters can be placed directly after the underscore, while multiple characters need curly braces.

% Single character subscript
$x_i$

% Multiple characters require braces
$x_{i+1}$
$a_{max}$

% Without braces, only the first character is lowered
$x_10$    % renders as x_1 followed by 0
$x_{10}$  % renders correctly as x sub 10

Subscripts are widely used for indexing variables, chemical formulas, and labeling quantities in scientific notation. A multi-letter subscript such as a_{max} is set in italic like a product of variables; if it is a word rather than a product, write a_{\max} (operator) or a_{\mathrm{max}} (upright text).

Multi-Character Scripts: x^{10} vs x^10

The rule behind every subscript and superscript in LaTeX is that ^ and _ take exactly one token. A single digit, a single letter, or a single command such as \alpha or \infty counts as one token; anything else needs braces to become one group. This is the classic mistake:

$x^10$      % x¹0  – only the 1 is raised, the 0 sits beside it
$x^{10}$    % x¹⁰  – correct

$a_max$     % a_m followed by "ax" at full size
$a_{max}$   % correct

$e^-x$      % e⁻x – only the minus sign is raised
$e^{-x}$    % correct

$x^\alpha$      % fine: \alpha is a single token
$x^\alpha\beta$ % x^α followed by β – braces needed: $x^{\alpha\beta}$
$2^n+1$          % 2ⁿ + 1, which is not 2^{n+1}

A good habit is to brace every script, even single characters: x^{2} costs two keystrokes and never surprises you later when you change 2 to 10. Most editors, including Octree, also highlight unbalanced braces so a missing } is caught before you compile.

Exponents and Powers

Exponents are just superscripts, so everything above applies. Here are the forms that come up most often, from squared and cubed through negative and fractional powers, scientific notation and towers of exponents:

$x^2$                 % x squared
$x^3$                 % x cubed
$x^{n}$               % x to the n
$x^{-1}$              % reciprocal
$x^{-2} = \frac{1}{x^2}$
$x^{1/2} = \sqrt{x}$  % fractional exponent
$y = x^{\frac{3}{2}}$ % or x^{3/2} to keep the exponent compact
$(x+1)^2$             % power of a bracketed expression
$\left(\frac{a}{b}\right)^2$

% Exponent rules
$a^{m+n} = a^m a^n$
$(a^m)^n = a^{mn}$
$\frac{x^{n}}{x^{m}} = x^{n-m}$

% Exponential function and powers of ten
$e^{i\pi} + 1 = 0$
$e^{x} = \sum_{n=0}^{\infty} \frac{x^n}{n!}$
$2^{10} = 1024$
$6.022 \times 10^{23}$
$10^{-3}$

% Towers: braces nest from the top down
$a^{b^{c}}$      % a^(b^c)
$2^{2^{2^{2}}}$

Two style points. A fractional exponent is usually better as x^{3/2} than x^{\frac{3}{2}}, because a stacked fraction inside a superscript is tiny and hard to read. And the base of the natural exponential is set italic by default (e^x); some journals ask for an upright \mathrm{e}^{x}, and for a long exponent \exp(...) is clearer than a superscript. For the full story on fractions and roots, see Mathematical Expressions in LaTeX.

Squared, Cubed and Units

For areas and volumes the exponent belongs to the unit, and the unit should be upright: $5\,\mathrm{m}^2$ gives 5 m² with a thin space between the number and the unit. The siunitx package does this consistently and understands \squared and \cubed:

% Plain LaTeX
$5\,\mathrm{m}^2$
$9.81\,\mathrm{m/s^2}$
$25\,\mathrm{cm}^{3}$

% siunitx (version 3 syntax)
\usepackage{siunitx}
\qty{5}{\metre\squared}              % 5 m²
\qty{9.81}{\metre\per\second\squared} % 9.81 m/s²
\qty{25}{\centi\metre\cubed}         % 25 cm³
\unit{\kilo\gram\per\metre\cubed}   % unit alone: kg/m³

% siunitx version 2 names still work
\si{\metre\squared}

% In a sentence without math mode
an area of 5 m\textsuperscript{2}

Outside LaTeX, the squared symbol is Unicode U+00B2 (²) and cubed is U+00B3 (³); our blog post on typing the squared symbol and superscript numbers covers the keyboard shortcuts for Windows, Mac, Word and Google Docs. In a LaTeX source file, prefer ^2: pasting the ² character into running text works under XeLaTeX and LuaLaTeX and with utf8 input in pdfLaTeX, but it is typeset as a text character, not a math superscript, and will not align with ^ exponents next to it.

Combining Subscripts and Superscripts

LaTeX allows you to apply both a subscript and a superscript to the same base element. The order in which you write them does not matter — LaTeX will position them correctly.

% Subscript and superscript on the same element
$x_i^2$
$x^2_i$    % same result as above

% More complex examples
$a_{n}^{2}$
$T_{\mu\nu}^{\alpha\beta}$   % tensor notation

% Simultaneous notation in physics
${}^{14}_{6}\mathrm{C}$    % carbon-14 isotope notation
${}^{A}_{Z}X$             % general isotope notation

When combining subscripts and superscripts, LaTeX automatically handles the vertical positioning. Both are attached to the same base, so they appear neatly aligned.

x_i^2 versus {x_i}^2

There is a subtle difference between stacking the scripts on the base and applying a superscript to an already-subscripted group:

$x_i^2$      % i and 2 stacked, both attached to x
${x_i}^2$    % 2 is a superscript of the group (x_i): it sits further right
$(x_i)^2$    % the explicit, unambiguous form
$x_{i}{}^{2}$ % an empty group staggers the scripts (used for tensors)

The staggered form matters in tensor notation, where T^{\mu}{}_{\nu} keeps the index order visible; for ordinary variables, x_i^2 is what you want.

Nested Subscripts and Superscripts

You can nest subscripts and superscripts inside each other for more complex expressions. Each level of nesting requires its own set of braces.

% Nested superscript (e to the x squared)
$e^{x^2}$

% Nested subscript
$a_{i_{j}}$

% Deeply nested expressions
$e^{e^{e^x}}$    % tower of exponentials
$x_{a_{b_{c}}}$  % triple-nested subscript

% Practical example: Gaussian function
$e^{-\frac{x^2}{2\sigma^2}}$

Each nesting level is set one size smaller, down to a minimum: first-level scripts use scriptstyle, second-level and deeper use scriptscriptstyle, and nothing gets smaller than that. While LaTeX supports arbitrary nesting depth, keep readability in mind. For very complex expressions, consider breaking them into smaller parts using \newcommand, or write \exp(...) instead of a tall tower.

Limits on Big Operators: \limits and \nolimits

Large operators like \sum, \prod, \lim, and\int have a special behavior: in display mode, their subscripts and superscripts appear directly below and above the operator (“limits” position). In inline mode, they appear to the side so the line does not grow taller.

% Display style: limits appear above and below
\[
  \sum_{i=1}^{n} x_i \qquad
  \prod_{k=1}^{n} k \qquad
  \lim_{x \to \infty} f(x)
\]

% Inline style: limits appear to the side
The sum $\sum_{i=1}^{n} x_i$ is computed inline.

% Force display-style limits in inline mode
The sum $\sum\limits_{i=1}^{n} x_i$ stacks its bounds.
The sum $\displaystyle\sum_{i=1}^{n} x_i$ is full size.

% Force inline-style limits in display mode
\[
  \sum\nolimits_{i=1}^{n} x_i
  \qquad
  \textstyle\sum_{i=1}^{n} x_i
\]

% Integrals put their bounds beside the sign even in display mode
\[
  \int_0^1 f(x)\,dx \qquad \int\limits_0^1 f(x)\,dx
\]

% \max, \min, \lim and \sup take limits too
\[
  \max_{x \in S} f(x) \qquad \operatorname*{argmax}_{x} f(x)
\]

\limits and \nolimits go immediately after the operator and before the scripts. Use \limits sparingly inline, because it increases the line height; \displaystyle is usually the better tool when you want a full-size operator in a paragraph. To define your own operator that takes limits, use \DeclareMathOperator*{\argmin}{arg\,min} (note the star) in the preamble. The integrals, sums and limits guide goes deeper.

Prescripts: Scripts on the Left

Isotope notation, some tensor conventions, and the transpose written as tA all put a script before the base. Attach the scripts to an empty group {} so they have something to hang on:

% Empty-group trick (no package needed)
${}^{14}_{6}\mathrm{C}$     % carbon-14
${}_{92}^{235}\mathrm{U}$   % uranium-235
${}^{t}A$                   % transpose, French style

% mathtools \prescript{sup}{sub}{base} aligns the prescripts properly
\usepackage{mathtools}
$\prescript{14}{6}{\mathrm{C}}$
$\prescript{}{i}{x}$          % subscript only
$\prescript{t}{}{A}$          % superscript only

% amsmath \sideset for big operators: scripts on both sides
$\sideset{_a^b}{_c^d}\sum$
$\sideset{}{'}\sum_{i} a_i$   % primed sum

The empty-group version works everywhere but can leave the left scripts slightly misaligned with the right ones; \prescript from mathtools fixes that. \sideset only works on big operators such as \sum and \prod.

Chemical Formulas: mhchem

You can write chemistry with plain scripts, $\mathrm{H_2O}$, and keep the element symbols upright with \mathrm. For anything beyond a formula or two, the mhchem package's \ce command is easier to type, sets charges and isotopes correctly, and handles whole reactions:

\usepackage[version=4]{mhchem}

\ce{H2O}                 % H₂O
\ce{CO2}                 % CO₂
\ce{SO4^2-}              % sulfate ion with charge
\ce{Fe^{3+}}             % ferric ion
\ce{^{14}_{6}C}          % carbon-14 with prescripts
\ce{2H2 + O2 -> 2H2O}    % reaction with arrow
\ce{CaCO3 ->[\Delta] CaO + CO2}  % condition above the arrow

% The same with plain math
$\mathrm{H_2O}$, $\mathrm{SO_4^{2-}}$, $\mathrm{CO_2}$

% In running text
Water is H\textsubscript{2}O.

\ce works in both text and math mode. Numbers that follow an element symbol become subscripts automatically, a leading number is a stoichiometric coefficient, and ^ gives a charge or mass number.

Subscripts and Superscripts in Text Mode

The caret and underscore operators only work in math mode; in text they stop compilation with Missing $ inserted. To add superscripts and subscripts in regular text, use the \textsuperscript{} and \textsubscript{} commands.

% Superscript in text mode
This is the 1\textsuperscript{st} edition.
The 2\textsuperscript{nd} floor.
March 3\textsuperscript{rd}, 2026.
E = mc\textsuperscript{2}       % but $E = mc^2$ is better for math
See the note\textsuperscript{*}  % footnote-style marker

% Subscript in text mode
H\textsubscript{2}O is water.
CO\textsubscript{2} is carbon dioxide.

% \textsubscript has been part of the LaTeX kernel since 2015.
% Only for a very old installation add: \usepackage{fixltx2e}

Both commands use the current text font, so they inherit bold or italic from their surroundings, and they can be used inside headings, captions and tables. Use them for ordinal numbers, trademarks (\textsuperscript{TM}), chemical formulas written outside of math mode, and marker symbols. For actual mathematics, switch to math mode instead: $x^2$ uses the math font and spacing, while x\textsuperscript{2} is just small text.

Ordinals: 1st, 2nd, 3rd

Many style guides (including Chicago and APA) prefer ordinals on the baseline, so plain 1st is often the right answer. If you want them raised, write the suffix with \textsuperscript or let the nth package work out the suffix for you:

1\textsuperscript{st}, 2\textsuperscript{nd}, 3\textsuperscript{rd}, 4\textsuperscript{th}

\usepackage[super]{nth}
\nth{1}, \nth{2}, \nth{23}   % 1st, 2nd, 23rd, raised; drop [super] for baseline

Common Use Cases

Subscripts and superscripts appear across many disciplines. Here are the most common scenarios:

Use CaseLaTeX CodeDescription
Chemistry$\mathrm{H_2O}$ or \ce{H2O}Chemical formulas with subscript atom counts
Exponents$x^n$Powers and polynomial terms
Units$5\,\mathrm{m}^2$Squared and cubed units, upright
Derivatives$f'(x)$Prime notation for derivatives
Tensors$T_{\mu\nu}$Tensor indices in physics
Isotopes${}^{14}_{6}\mathrm{C}$Nuclear isotope notation
Sequences$a_{n+1}$Indexed sequences and series
Limits$\lim_{x \to 0}$Limit notation in calculus
Ordinals1\textsuperscript{st}Raised suffix in text

Prime Notation

In LaTeX, the apostrophe character (') is a shorthand for a superscript prime symbol. This is commonly used for derivatives and transformed variables.

% Single prime (first derivative)
$f'(x)$

% Double prime (second derivative)
$f''(x)$

% Triple prime (third derivative)
$f'''(x)$

% Combining primes with subscripts
$f'_n(x)$

% Equivalent explicit notation
$f^{\prime}(x)$
$f^{\prime\prime}(x)$

% Using primes with other superscripts
$f'^2(x)$          % prime squared
$f^{\prime 2}(x)$  % same thing, explicit

The apostrophe shorthand is generally preferred because it's easier to type and produces identical output to the explicit \prime command. It is also the one case where two superscripts in a row (f'^2) do not trigger the double superscript error, because LaTeX merges the prime into the following script.

Transpose, Inverse, Complement and Other Common Superscripts

A handful of superscripts come up in almost every maths or physics document. They are ordinary ^ scripts, but there is usually a preferred form:

% Matrix transpose: \top is a cleaner T than the letter
$A^T$  or  $A^{\top}$  or  $A^{\mathsf{T}}$

% Inverse matrix and inverse function: braces around the minus sign
$A^{-1}$
$f^{-1}(x)$

% Conjugate transpose (Hermitian adjoint)
$A^{*}$  or  $A^{\dagger}$  or  $A^{\mathsf{H}}$

% Set complement
$A^c$  or  $A^{\complement}$  (amssymb)  or  $\overline{A}$

% nth derivative, in brackets so it is not read as a power
$f^{(n)}(x)$

% Mixed tensor indices: contravariant up, covariant down
$T^{\mu\nu}$, $T_{\mu\nu}$, $T^{\mu}{}_{\nu}$

% Quantum notation
$\psi_{nlm}$, $|n, l, m\rangle$

Pick one transpose notation and use it throughout; A^{\top} avoids confusion when T is also a variable in the same document.

Superscript vs superset, subscript vs subset

The set symbols ⊂ and ⊃ are not scripts at all. They are relation symbols with their own commands:

$A \subset B$     % A is a subset of B
$A \subseteq B$   % subset or equal
$A \supset B$     % A is a superset of B
$A \supseteq B$   % superset or equal
$A \not\subset B$ % not a proper subset
$A \nsubseteq B$  % not a subset or equal (amssymb)

The amsmath Package

The amsmath package from the American Mathematical Society provides advanced commands for positioning subscripts and superscripts in specialized contexts.

\usepackage{amsmath}

% \overset: place a symbol above another
$\overset{!}{=}$        % "!" above "="
$\overset{\sim}{x}$     % tilde above x

% \underset: place a symbol below another
$\underset{n \to \infty}{\lim}$

% \sideset: add subscripts/superscripts to large operators
$\sideset{_a^b}{_c^d}{\sum}$

% \substack: stacked subscripts (multi-line conditions)
$\sum_{\substack{i=1 \\ i \neq j}}^{n} a_i$

% \stackrel: older kernel command; \overset does the same and more
% $\stackrel{\text{def}}{=}$

The \substack command is particularly useful for sums and products with multiple conditions in the subscript position.

Quick Reference Table

CommandExampleOutput Description
^$x^2$x squared
_$x_i$x sub i
^{}$x^{2n}$x to the 2n
_{}$x_{i+1}$x sub i+1
_i^j$x_i^j$x sub i, superscript j
{}^{}_{}${}^{14}_{6}\mathrm{C}$Prescripts (isotope)
\prescript$\prescript{14}{6}{\mathrm{C}}$Aligned prescripts (mathtools)
\limits$\sum\limits_{i=1}^{n}$Bounds above and below, even inline
\nolimits$\sum\nolimits_{i=1}^{n}$Bounds beside the operator
\textsuperscript1\textsuperscript{st}1st (in text mode)
\textsubscriptH\textsubscript{2}OH2O (in text mode)
\ce\ce{SO4^2-}Chemical formula (mhchem)
\qty\qty{5}{\metre\squared}5 m² (siunitx)
'$f'(x)$f prime of x
\overset$\overset{!}{=}$= with ! above
\underset$\underset{x}{\min}$min with x below
\substack$\sum_{\substack{i\\j}}$Sum with stacked subscripts

Common Errors and Fixes

Message or symptomCauseFix
Double superscriptTwo ^ on one base: $x^a^b$$x^{ab}$ or ${x^a}^b$, depending on what you mean
Double subscriptTwo _ on one base: $x_i_j$$x_{ij}$ or $x_{i_j}$
Missing { insertedNothing usable after ^ or _: $x^$, $x_$, $x^\left($Put a token or a braced group after the operator
Missing } inserted / Extra }Unbalanced braces in a nested scriptCount braces; most editors highlight the matching pair
Missing $ inserted^ or _ used in text, or a literal underscore in a file name or URLUse $...$, \textsuperscript, or \_ for a literal underscore
Only the first character is raised$x^10$, $a_max$Braces: $x^{10}$, $a_{max}$
Undefined control sequence \textsubscriptLaTeX older than 2015Update TeX Live, or \usepackage{fixltx2e}
Undefined control sequence \prescript / \ce / \qtyPackage not loadedAdd mathtools, mhchem or siunitx to the preamble
Limits beside Σ instead of above itInline math uses text style\limits or \displaystyle, or move to display math
Superscript looks like text, not mathx\textsuperscript{2} used for an exponentWrite $x^2$
% WRONG: multi-character without braces
$x^10$         % renders as x^1 then 0
$a_max$        % renders as a_m then ax

% CORRECT: use braces
$x^{10}$
$a_{max}$

% WRONG: ^ outside math mode
This is x^2    % Missing $ inserted

% CORRECT: use math mode or text commands
This is $x^2$
This is x\textsuperscript{2}

% WRONG: double superscript
$x^a^b$        % error: Double superscript

% CORRECT: group appropriately
$x^{ab}$       % a and b together as superscript
${x^a}^b$      % b is superscript of (x^a)

% WRONG: nothing after the operator
$x^$           % Missing { inserted

% CORRECT
$x^{}$         % empty group is allowed (rarely useful)

Frequently Asked Questions

How do you write subscript and superscript in LaTeX?

In math mode, _ makes a subscript and ^ makes a superscript: $x_i$ is x sub i and $x^2$ is x squared. Wrap anything longer than one character in braces, as in $x_{i+1}$ and $x^{10}$. In normal text use \textsubscript{...} and \textsuperscript{...}, so water is H\textsubscript{2}O and first is 1\textsuperscript{st}. None of these needs a package.

Why do I get “Missing $ inserted” when I use _ or ^?

The _ and ^ operators only work in math mode. Typed in a normal sentence, or as a literal underscore in a file name or URL, they make LaTeX insert a $ and stop. Put the expression in $...$, use \textsubscript or \textsuperscript for text, or write \_ for a literal underscore.

How do I write squared in LaTeX?

Type $x^2$ for x squared and $x^3$ for x cubed. For units write $5\,\mathrm{m}^2$, or load siunitx and write \qty{5}{\metre\squared}. In plain text, m\textsuperscript{2} also works.

Why does $x^10$ only raise the 1?

The ^ and _ operators take exactly one token. In $x^10$ that token is the digit 1, so the 0 is typeset at normal size next to it. Write $x^{10}$ with braces so the whole number is the exponent.

What does “Double superscript” mean?

You attached two superscripts to the same base, as in $x^a^b$. LaTeX cannot tell whether you mean xab or (xa)b, so you have to group one of them: $x^{ab}$ or ${x^a}^b$. “Double subscript” is the same problem with underscores.

How do I put a subscript and a superscript on the same symbol?

Write both after the base in either order: $x_i^2$ and $x^2_i$ give the same result, with the two scripts stacked. For a prescript on the left, as in isotope notation, use ${}^{14}_{6}\mathrm{C}$ or $\prescript{14}{6}{\mathrm{C}}$ from mathtools.

Next Steps

Now that you've mastered subscripts and superscripts, explore these related topics:

Free LaTeX Tools

Ready to start writing?

Try Octree — the AI-powered LaTeX editor that catches a missing brace before you compile and explains errors like “Double superscript” in plain English.

Try Octree Free →