How to Write Mod in LaTeX

Use \bmod between two numbers: a \bmod b. After a congruence use \pmod{n}, which adds space and parentheses: a \equiv b \pmod{n}. Never type the letters m-o-d directly in math; they come out as an italic product.

The four mod commands

  • a \bmod b
    a mod b

    Binary operator: "a mod b" with operator spacing.

  • a \equiv b \pmod{n}
    a ≡ b ( mod n )

    Parenthesised: "(mod n)" with extra space before it.

  • a \equiv b \mod{n}
    a ≡ b mod n

    amsmath: "mod n" without parentheses.

  • a \equiv b \pod{n}
    a ≡ b ( n )

    amsmath: "(n)", parentheses without the word.

  • \operatorname{mod}
    mod

    Upright "mod" with operator spacing you control.

Try it live

Change the formula and the preview redraws as you type. Copy the LaTeX, download a PNG or SVG, copy it for Word, or use Edit here on any example below to load it.

Templates

Modulo (mod) examples

Each result below is drawn from the LaTeX under it. Copy the code, edit it on this page, or open it in the full editor.

Which one to use

\bmod is for the operation that returns a remainder, as in programming. \pmod is for the relation "congruent modulo n" and is what most number theory texts use. \mod and \pod come from amsmath for authors who prefer "mod n" without parentheses or parentheses without "mod".

Too much space before (mod n)?

\pmod adds a quad of space in display math and less inline. If it looks too wide in running text, write \;(\operatorname{mod} n) yourself, as in the last example.

Common mistakes

  • Typed letters become italic variables m·o·d.

    Instead of
    a \equiv b (mod n)
    Write
    a \equiv b \pmod{n}
  • \pmod puts parentheses around b; for "a mod b" use \bmod.

    Instead of
    a \pmod b
    Write
    a \bmod b
  • % starts a comment in LaTeX; the rest of the line disappears.

    Instead of
    a % b
    Write
    a \bmod b

In Overleaf, MathJax and Word

  • Overleaf and pdfLaTeX

    \bmod and \pmod work without packages; \mod and \pod need amsmath.

  • MathJax and KaTeX

    MathJax and KaTeX support \bmod, \pmod, \mod and \pod.

  • Microsoft Word

    In a Word equation type "mod" and Word sets it upright as a function name, or use \pmod-style text: (mod n).

Have this math on paper, in a PDF or a photo?

Retyping formulas is slow. These converters read whole pages and handwriting and give you LaTeX or Word with every equation editable.

Single printed formulas are free: 3 a day without an account, 6 with a free account. New accounts get 30 credits to try handwriting, pages and documents; failed conversions return their credits. See plans and credit prices.

Modulo (mod) in LaTeX: questions

How do I write mod in LaTeX?
a \bmod b for the operation, a \equiv b \pmod{n} for a congruence.
What is the difference between \bmod and \pmod?
\bmod is a binary operator; \pmod{n} writes "(mod n)" after a congruence.
Why is my mod italic?
You typed the letters. Use one of the mod commands or \operatorname{mod}.

Have the formula as a picture?

Paste a screenshot or photo of the equation and get its LaTeX, ready to copy or open in the editor.

Convert an image to LaTeX