Modulo in LaTeX (\bmod)

 mod \bmod
LaTeX command
\bmod
Package
No package needed: built into LaTeX
Mode
Math mode only

Where it is used

Binary modulo operator: typesets 'mod' between two operands, as in a mod n, with operator spacing.

Use \bmod for the remainder operation inside an expression, such as 17 \bmod 5 = 2 or the hash function h(k) = k \bmod m. It produces upright mod with medium spacing on both sides, just like a binary operator. For congruences, use \pmod instead: a \equiv b \pmod{n} prints the parenthesized form with extra space before it. amsmath also defines \mod{n}, which gives a wider unparenthesized gap, and \pod{n}, which keeps the parentheses but drops the word. Typing the bare letters mod would italicize them as a product of variables, so always use one of these commands.

Minimal compilable example

Paste this into an empty .tex file and compile it with pdfLaTeX, XeLaTeX or LuaLaTeX.

h(k)=k mod m,17 mod 5=2h(k) = k \bmod m, \quad 17 \bmod 5 = 2
\documentclass{article}
\begin{document}
Modulo: $\bmod$

\[ h(k) = k \bmod m, \quad 17 \bmod 5 = 2 \]
\end{document}

Related symbols

All Computer Science →

Frequently asked questions

How do I write Modulo in LaTeX?
Type \bmod in math mode, for example $h(k) = k \bmod m, \quad 17 \bmod 5 = 2$. It works in plain LaTeX without loading any package.
Which package do I need for \bmod?
None. \bmod is part of standard LaTeX, so it compiles with nothing in the preamble but the document class.
Can I use \bmod in text mode, or only in math mode?
Only in math mode. Outside $...$ LaTeX stops with "Missing $ inserted", so write $\bmod$ in running text.
Math poweredSumulat ng LaTeX gamit ang AI

Pinakamahusay na AI LaTeX Editor, Alternatibo sa Overleaf

Tinutulungan ng Octree ang mga researcher mula sa 15+ na unibersidad na sumulat ng research papers nang mas mabilis gamit ang AI

  • Gumawa ng magagandang TikZ diagrams gamit ang AI
  • Mag-upload ng larawan at i-convert ito sa LaTeX nang walang problema
  • Makakuha ng instant na tulong sa pagsulat at pag-format ng research papers