What is a bitmask — and why permissions=8 makes your bot an admin

You're building a Discord bot. The tutorial says: "here's the invite link, paste in your id". The link ends with permissions=8. You click, add the bot to your server. And it gets administrator rights. All of them. Instantly.
Why eight? Why not "admin=true"? Because that number isn't a count or a level. It's a bitmask: eight switches packed into one number. Let's learn to read it — and you'll stop handing bots more than they need.
What is a bitmask
A bitmask is a way to store many yes/no flags in a single number. Each flag takes its own bit — its own position in the binary form.
Picture a panel of switches. The first is "can invite". The second, "can kick". The third, "can ban". The fourth, "administrator". A switch that's up is 1, down is 0.
Binary positions have different weights: 1, 2, 4, 8, 16, and so on, doubling. So:
- only the first switch — the number 1;
- only the second — 2;
- only the third — 4;
- only the fourth — 8.
That's the answer: permissions=8 means the fourth switch is up. In Discord, the fourth bit is ADMINISTRATOR. Nothing else is in the mask, but nothing else is needed: an admin can do everything.
How to combine permissions
Want the bot to only read and write messages? Find the weights you need and add them up. In Discord:
- view channel —
1024; - send messages —
2048; - read message history —
65536.
1024 + 2048 + 65536 = 68608. Put that number in the link. Each permission sits in its own position, so the sum never gets ambiguous: from 68608 you can always recover which switches are up.
In code, flags are combined not with plus but with the | operator ("bitwise OR") and checked with & ("bitwise AND"):
const VIEW = 1 << 10 // 1024
const SEND = 1 << 11 // 2048
const perms = VIEW | SEND // 3072
if (perms & SEND) {
console.log('can write')
}
1 << 10 reads as "one, shifted 10 places left" — the tenth bit. That's how flags are declared: you see the switch number, not a mysterious value.
Where else you'll see it
chmod 755. In the terminal you've probably seen chmod 755 script.sh. Each digit is a tiny three-bit mask: read (4), write (2), execute (1).
7= 4 + 2 + 1 — the owner can do everything;5= 4 + 1 — the group can read and execute;5— everyone else can read and execute too.
And chmod 777 — everyone can do everything, writing included. That's why people warn you not to use it "just to make it work".
Settings in a database. Sometimes a database has one flags field instead of ten boolean columns. Compact, but hard for a human to read. When you meet one — it's a mask.
Keys and events. "Shift held, Ctrl not" is often stored as a mask too — in games and low-level libraries.
The trap: JavaScript and big masks
Here's where beginners trip. Bitwise operators in JavaScript only work with 32 bits. Past that, things get weird:
1 << 31 // -2147483648 (turned negative)
1 << 32 // 1 (the shift wrapped around)
Discord already has around fifty permissions. The newest ones live past position 40. That's why Discord sends permissions as a string, and libraries like discord.js store flags as BigInt — numbers with no ceiling, with an n at the end: 1n << 40n.
If AI wrote you a permission check with plain numbers — test it on a newer permission. It will likely just say "no" without complaining.
What to take away
- Granting permissions to a bot or an app — don't use
8"just in case". Add up only what you need. If the bot gets hacked, the damage stays limited to those rights. - See a strange number in settings — split it into powers of two. 68608 = 65536 + 2048 + 1024. Instantly clear what's inside.
- Masks over 32 flags —
BigIntor strings only.
Why masks, when you could store an array of names?
A mask is more compact and faster to check: one number instead of a list of strings. That matters for APIs and network protocols. In your own app an array of names is often more readable — pick for the situation.
How do I decode a mask without a calculator?
Discord and many services offer a permissions calculator in the developer panel. In the browser console one line is enough: (68608).toString(2) shows which bits are up.
Is a bitmask the same as an enum?
No. An enum picks one value from a list. A mask holds several switched-on flags at once.
The AI Architect 2027 course: step by step from computer basics to your own app and first customers. 543 short lessons on your phone.





