ComfyUI Node

modulus

The remainder node — what's left after you divide

By StableLlama·Created about a year ago·Updated 4 days ago· 48
modulus
    • INT
    int10
    int21

    Modulus is the workhorse of "every Nth thing" logic, and modulus from the Basic data handling pack is that operator in node form: divide one integer by another and keep only the remainder. 10 % 3 is 1. 100 % 10 is 0. If you've ever wanted "do something every 5th frame" or "toggle when the count is even," this is the node that gets you there.

    What it does

    It computes int1 % int2 - Python's remainder operator. That's the whole job, with two details worth knowing:

    • It returns 0 exactly when int1 divides evenly by int2. That makes == 0 the classic "every Nth" test: frame % 5 == 0 fires on frames 0, 5, 10…
    • The sign follows Python's rule: the result takes the sign of the divisor. -10 % 3 is 2, not -1. If you're porting expectations from C or JavaScript, this will surprise you exactly once, so it's worth deciding consciously whether that matters in your logic.

    Like the pack's divide node, it draws the line at zero: int2 == 0 raises a ValueError. There's no "safe" remainder variant, so if your divisor can be zero, guard it upstream.

    Inputs and outputs

    • int1 - INT, default 0. The value being divided.
    • int2 - INT, default 1. The divisor.
    • Output INT - the remainder.

    Install

    From the Basic data handling pack. ComfyUI Manager → search "Basic data handling" → install → restart. Or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/StableLlama/ComfyUI-basic_data_handling
    

    then restart ComfyUI. No dependencies, no model downloads.

    How it fits a workflow

    The pair to know is divide + modulus side by side: one gives the quotient, the other the remainder, and together they let you decompose any value into "how many whole groups" and "what's left over." The classic ComfyUI pattern is modulus feeding a comparison node (result == 0) to build a frame-based or batch-based condition - every N iterations, do the heavy pass. Keep the divisor positive unless you enjoy debugging sign weirdness.

    CategoryBasic/INT

    Inputs (2)

    NameTypeDefaultDescription
    int1INT0
    int2INT1

    Outputs (1)

    NameTypeDescription
    INTINT