NAND Calculator
Calculate the bitwise NAND (NOT AND) of two numbers.
Result: A NAND B
Enter both values to see the result in decimal, hex, binary, and octal.
NAND truth table
| A | B | A NAND B |
|---|---|---|
| 0 | 0 | 1 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
NAND Calculator – Bitwise NOT AND
Compute the bitwise NAND of two numbers. NAND is AND followed by NOT: every bit of the result is 0 only when both input bits are 1, and 1 otherwise. Enter the two values in decimal, hex, binary, or octal and pick a bit width; the calculator shows the aligned bits and the result in every base. For 8-bit values, 12 NAND 10 = 247 (1111 0111).
Why bit width matters for NAND
Because NAND inverts the result, all the leading zeros of the AND result turn into ones. The answer therefore depends on how many bits you work with: 12 NAND 10 is 247 in 8 bits, 65,527 in 16 bits, and 4,294,967,287 in 32 bits. As a signed (two's complement) number it is −9 in every width. Choose Auto to use the smallest multiple of 8 bits that fits both operands, or fix the width to match the integer type in your code.
In most programming languages NAND is written as ~(a & b). Remember to mask the result (& 0xFF, & 0xFFFF, …) if you want the unsigned value, because ~ in JavaScript, C, and Python produces a negative signed number.
NAND is a universal gate
NAND is famous in digital electronics because every other logic function can be built from NAND gates alone:
- NOT A = A NAND A
- A AND B = (A NAND B) NAND (A NAND B)
- A OR B = (A NAND A) NAND (B NAND B)
Flash memory (NAND flash), CMOS logic, and courses such as "From NAND to Tetris" rely on this property. The truth table beside the calculator shows the single-bit rule: 0 0 → 1, 0 1 → 1, 1 0 → 1, 1 1 → 0.
Use cases
Check homework on logic gates, verify a hardware design, simulate a NAND-based circuit bit by bit, or compute complement masks. See also the AND Calculator, NOR Calculator, and the full Bitwise Calculator.
Frequently Asked Questions
What is NAND in simple terms?
NAND means 'not both'. The output bit is 1 unless both input bits are 1. It is the inverse of AND.
Why does NAND give such large numbers?
Inverting turns every leading 0 into a 1, so the result fills the whole bit width. Choose the width that matches your data type; the signed value (e.g. -9) stays the same across widths.
How do I write NAND in code?
Use ~(a & b) and, for an unsigned result, mask it with the width: (~(a & b)) & 0xFF for 8 bits.