No more IF/SWITCH spaghetti – build clean workflows with bitmasking

Endless IF/SWITCH nodes tangled together. Change one thing, break three others. Add a new condition? Good luck finding where it fits without destroying the rest.

There’s a way to replace almost any condition maze with a single number.

It’s called bitmasking, and once you see it, you can’t unsee it.

Let’s say you’re building a customer order system.

Customers can order:

  • Coffee or Tea (drinks)
  • Croissant (food)
  • Any combination of the above

Your brain immediately goes to this:

IF drink = "coffee" AND food = "croissant" → Action A
IF drink = "tea" AND food = "empty" → Action B  
IF drink = "empty" AND food = "croissant" → Action C
IF drink = "coffee" AND food = "empty" → Action D

This is a nightmare.

The workflow tends to look like this:

Add one more drink option? You just doubled your conditions. Add a sandwich option? You’ve now got 12 different combinations to track.

What if I told you there’s a way to represent every possible combination with just one number?

All serious engineers know about bitmasking. Now is the time flowgrammers adopt this idea!

Here’s the secret sauce:

Step 1: Give each choice a “power of 2” value

  • Coffee = 1
  • Tea = 2
  • Croissant = 4

Why these specific numbers? Because they’re magical. You literally cannot create the same sum with different combinations.

Every combination gets its own unique “fingerprint” number.

Step 3: Replace your spaghetti logic with a simple switch

Instead of 8 complex IF/THEN branches, you get:

  • Number = 1 → Coffee path
  • Number = 2 → Tea path
  • Number = 4 → Croissant path
  • Number = 5 → Coffee + Croissant path
  • Number = 6 → Tea + Croissant path
  • Number = 7 → Everything path

One number. One switch. Done.

Here’s how it looks in action

Watch how each combination automatically generates its unique number, and the workflow instantly knows which path to take. No complex logic, no nested conditions.

This isn’t just for order systems. Bitmasking works anywhere you have multiple independent choices:

  • User permissions (read, write, delete, admin)
  • Feature flags (dark mode, notifications, beta features)
  • Survey responses (multiple selections)
  • Game states (inventory items, character abilities)
  • Email preferences (newsletter, promotions, updates)

Once you see this pattern, you’ll spot it everywhere.

The craziest part? This technique is older than the internet, but most flowgrammers today have never heard of it.

Try It Yourself

Next time you catch yourself building complex conditional logic, stop.

Ask yourself: “Could I assign each choice a power-of-2 value and just add them up?”

Too lazy to figure out the math? Just ask ChatGPT or Claude: “I have these 5 choices [list them]. Can you create a bitmask system for me?” They’ll spit out the power-of-2 values and all possible combinations in seconds.

I share more n8n engineering techniques like this on LinkedIn – practical stuff that actually makes your workflows cleaner, faster, and more maintainable. Follow me there.

My other posts:

2 Likes