Subtract
The math node for when the sampler needs a number, not a guess
- value
The FairLab Subtract node does A − B. That's the entire job. If that reads like the least exciting node in existence, you haven't yet hit the workflow where a resolution, a denoise strength, or a padding amount has to be computed rather than typed. ComfyUI's graph isn't just a pipeline - it's a program, and programs need arithmetic.
The classic case: you know your output width, your border, or your target aspect, and the value the sampler needs is that minus something. Subtract is how you express "1024 minus the 64px of context I'm cropping" as a wire instead of a hard-coded guess. Change the upstream number once, and every downstream number follows.
How it works
Straightforward: it takes two floating-point inputs, subtracts the second from the first, and outputs the result as a FLOAT.
- a - the minuend (what you subtract from).
- b - the subtrahend (what gets subtracted).
- value - the output,
a - b.
Both inputs are FLOAT sockets. That's the one thing to plan around: there's no auto-casting. Feed it an INT from a primitive and the wire won't connect; run the number through the pack's Int To Float first (or use an Int node and cast).
What it's actually for
- Geometry math. Output size minus padding, batch count minus one, latent size minus a crop margin.
- Adjusting strengths. CFG or denoise values that need to be slightly less than another value on the graph, tied to one editable source.
- Offsets. Frame ranges, indices, and counters that need a
-1or-Napplied uniformly.
It's part of the pack's logic family - Add, Multiply, Divide, Min, Max, If, plus the Float To Int / Int To Float casts that make the type dance work. Together they cover the "compute a number on the graph" use case that core ComfyUI leaves you to hack with primitives and converter nodes.
Gotchas worth the half-second
- It's
FLOATin,FLOATout. Integer math needs the cast dance mentioned above. - Order matters and it's
a - b, notb - a- which direction you wire decides the sign. Sounds obvious; it's the #1 mistake. - There's no clamping, so negative results are legal. If downstream expects a positive width, you own that.
- Division-by-zero isn't a thing here (it's subtraction), so the only real failure mode is type mismatch or a disconnected input.
Installing it
One pack, all nodes:
cd ComfyUI/custom_nodes
git clone https://github.com/yanhuifair/ComfyUI-FairLab.git
cd ComfyUI-FairLab
pip install -r requirements.txt
Restart, or search "ComfyUI-FairLab" in ComfyUI Manager. No dependencies of its own - pure Python arithmetic, so if the pack imported, this node is ready. It's the kind of node you'd never google and never miss, until the day a graph needs a computed number and this is the wire that provides it.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| a | FLOAT | — | |
| b | FLOAT | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| value | FLOAT | — |