Representing a Chess Board Using Bitboards
- Sam Lench
- Dec 21, 2025
- 2 min read
Updated: 6 days ago
What is a bitboard?
A bitboard is way of representing a chess board using unsigned 64 bit binary numbers, it's that simple. A chess board has 64 squares, meaning that each bit (a 1 or 0) in the binary number represents a single square on the board. Obviously we can't tell all the data of a chess board with just a 1 or a 0, so to get around this we create 12 different bitboards, one for each piece. 6 pieces x 2 colours. Additional bitboards are often used as well such as:
All white pieces
All black pieces
All occupied squares
ulong whitePawnsBitboard = 0x000000000000FF00;p.s. all code examples are in C#.
These bitboards can represent multiple things, but usually represents which squares are occupied or which squares can be attacked.
Occupancy Bitboard
This is an example of a bitboard for the white pawns

Attacking Bitboard
This is an example of a knights attacking bitboard if it is on D4

Why are they beneifital?
Modern computer systems are optimised for working with 64 bit numbers. This means bitboards take advantage of fast bitwise operators such as AND, OR, XOR, NOT, and bit shifts.
Bitwise operations can also be ran in parallel whilst only using a small number of CPU instructions. This means that they are extremely efficient and a lot faster than the common way of looping over individual squares.
Because of this, bitboards are common in chess programming when creating a high performance chess engine.
What are the different bitwise operations used for?
AND (&) - Used to find overlaps from comparing two bitboards
- Checking if a square is occupied
- Detecting collisions between pieces
- Finding overlapping squares between two bitboards
if (whitePiecesBitboard & squareMask){
//A white piece is on this square
}OR (|) - Used to combine bitboards
- Combining multiple piece boards into one
- Adding a piece to a bitboard
allPiecesBitboard = whitePiecesBitboard | blackPiecesBitboard;XOR (^) - Used to toggle bits
- moving a piece from one square to another
bitboard ^= (fromBit | toBit);NOT (~) - Used to invert bits
- Clearing a square
- Creating a mask to exclude certain squares
bitboard &= ~squareMask;



