Contributed by
Lapo Fanciullo
The main plot is not mathrelated: the Night Watch has to solve a series of mysterious murders, all while dealing with the internal tensions due to the Patricianmandated hiring of "ethnic minorities"  namely, a dwarf, a troll and a woman (there's more to it, but I can't add anything without risking a spoiler). However, mathematics plays an important role in the subplot where Cuddy the dwarf and Detritus the troll overcome their mutual dislike (on Discworld, dwarfs and trolls cannot stand each other).
In this book Pratchett introduces one of the most successful ideas of the Discworld series: trolls  which in this universe are big humanoids made of stone  have brains that are mostly silicon, and therefore they are essentially living computers. This has two main consequences:
 Trolls naturally count in base two (which unfortunately is never explored in subsequent books), and
 Trolls become smarter when it's cold, because their brain conductivity increases (this would come up a few more times in the series).
When Cuddy and Detritus are sent on patrol and begrudgingly get to know each other better, Cuddy discovers that the expressions Detritus uses  such as "two and one" for "three"  don't mean that he cannot count. As a matter of fact, despite being quite dumb, Detritus is really good at counting (I just realized this is a pretty apt description of computers); he's just most used to powers of two.
(quoted from Men at Arms)
"A twothirtytwo, and eight, and a one!"
"See? How many bricks in that pile?"
Pause.
"A sixteen, an eight, a four, a one!"
"Remember what I said about dividing by eightandtwo?"
Longer pause.
"Twoentynine...?"
"Right! [...] If you can count to two, you can count to anything!"

The 'smarter when it's cold cold' angle comes into play later, when the two are trapped in (the magical equivalent of) a walkin freezer. Detritus manages to throw Cuddy out a window to look for help, and while waiting for rescue he takes the counting game he just discovered a few notches further.
(quoted from Men at Arms)
He calculated the number of bricks in the wall, first in twos and then in tens and finally in sixteens. The numbers formed up and marched past his brain in terrified obedience. Division and multiplication were discovered. Algebra was invented and provided an interesting diversion for a minute of two. And then he felt the fog of numbers drift and away, and looked up and saw the sparkling, distant mountains of calculus.

While there is no explicit discussion of maths, this section is nothing less than a love letter to higher mathematics. When Cuddy gets someone to open the freezer door  just in time to save Detritus, frozen still and icecovered  the troll may have reinvented all of known mathematics.
(quoted from Men at Arms)
The inner walls of the warehouse were covered with numbers. Equations as complex as a neural network had been scraped in the frost. At some point in the calculation the mathematician had changed from using numbers to using letters, and then letters themselves hadn't been sufficient; brackets like cages enclosed expressions which were to normal mathematics what a city is to a map.
They got simpler as the goal neared  simpler, yet containing in the flowing lines of their simplicity a spartan and wonderful complexity. [...] This was maths without numbers, pure as lightning.
They narrowed to a point, and at the point was just the very simple symbol: "=".
"Equals what?" said Cuddy. "Equals what?"

There's a debate in the fandom on whether Detritus was stopped just short of solving the ultimate equation that would make sense of all mathematics, of whether the equal sign itself is supposed to be the final result, expressed in some symbolic system above human comprehension.
Whatever your interpretation, this remains a powerful section in the book: Cuddy and Detritus get so excited in their discovery of base two that they bond over the experience, and the subplot culminates in one of the best written praises of the beauty of maths. This is one of my favorite scenes in all of Discworld, and I love to go back and reread it.
