Chip Select / Address Decoder
Design a memory address decoder. Given base address, size, and total address space, compute the enable logic and address bit masks.
How to Use
- Choose the address bus width: 16 bits for 8-bit CPUs such as the Z80 or 6502, 24 for the 68000, 32 for most microcontrollers.
- Enter the base address in hex.
- Enter the block size in bytes (K and M are accepted); it must be a power of two.
- Read the end address, which lines go to the chip, the compare bits and the chip-select equation; Show Work warns if the base is not aligned.
Worked Example
A 256-byte peripheral at 0xE000 on a 16-bit address bus. 256 = 2⁸, so A0–A7 go to the device and the block ends at 0xE000 + 255 = 0xE0FF. The other 8 lines, A8–A15, must match the base's upper byte, 0xE0 = 1110 0000.
Chip select: CS = A15·A14·A13·!A12·!A11·!A10·!A9·!A8: one 8-input AND with inverters, or a 74HC138 handling A15–A13 with a few gates for the rest.
The common mistake: an unaligned base. Put the same 256 bytes at 0xE010 and the equation above still selects 0xE000–0xE0FF, so the device would answer 16 bytes early and miss its last 16. Bases must be multiples of the block size for simple decoding.
Show Work: Decoding Logic
Formulas
History of Memory Address Decoding
Address decoding has been part of computer design since machines first had more than one memory bank. With TTL logic, decoder chips such as the 74138 3-to-8 decoder became the standard way to do it in small systems — combining three address lines plus three enable lines into one of eight active-low chip-select outputs.
As address bus widths grew from 16 bits (8080, Z80, 6502) to 20 bits (8086), 24 bits (68000), and beyond, dedicated decoder logic became impractical. Programmable logic devices (PALs and GALs in the 1980s, CPLDs and FPGAs in the 1990s) replaced discrete decoders with configurable chip-select equations. Modern SoC designs embed address decoding directly into memory controllers and bus matrices (AXI interconnects, AMBA fabric), but the underlying math — high-order address bits must match the device base, low-order bits index within the device — is unchanged since the TTL era.
Alignment to power-of-2 boundaries minimizes decoder complexity: a 256-byte device at address 0xE000 needs only 8 bits of comparison, but at address 0xE010 it would require a full 16-bit comparator. This is why operating systems and linker scripts align memory-mapped peripherals to natural boundaries — the hardware cost drops precipitously.
About This Calculator
Enter a base address in hex, device size (bytes, with K/M suffixes), and the system's address bus width. The tool computes the end address, number of offset bits (low-order pass-through), number of compare bits (high-order that must match base), and the compare mask.
The resulting values let you implement the chip-select equation in discrete logic (74LS138 + AND gates), in a PLD/GAL, or in an FPGA. Sizes must be powers of two; for an odd-sized device, decode the next power of two up and leave the extra addresses unused. All math runs client-side; no values leave your browser.
Frequently Asked Questions
What is a chip select?
An enable signal that switches on one memory or I/O device when the processor addresses its block. Decode logic watches the upper address lines and asserts the chip select only when they match the block.
How does address decoding work?
The lowest log₂(size) address lines go straight to the device to pick a location inside it. All the lines above must match the block's base address, and an AND of those lines (inverted where the base has a 0) produces the chip select.
Why must the base be a multiple of the size?
Then the low bits of the base are all zero and the block is defined by the upper bits alone. A 256-byte block at 0xE010 would straddle two aligned blocks and need a magnitude comparator instead of simple gates.
How does a 74HC138 fit in?
It decodes three address lines into eight active-low outputs, each one block of the address space. With A15 on an enable input and A14–A12 on the select inputs, it splits 0x8000–0xFFFF into eight 4 KB blocks.
What is partial decoding?
Leaving some upper address lines out of the comparison to save logic. The device then also answers at mirror addresses; that is fine if nothing else lives there, and a classic source of bugs if something does.
How do I use the Chip Select / Address Decoder?
Just type your numbers. The answer shows up right away — there is no button to press. Change anything and it updates by itself.
Does it cost anything or need an account?
No. The tool is completely free, there is no account to create, and it keeps working offline after the page first loads.
Is anything I type uploaded?
No. The tool works entirely on your device, so the values you enter never leave your browser.
Common Use Cases
Two 32 KB SRAMs
In a 64 KB space, A15 alone picks the chip: CS = !A15 for 0x0000–0x7FFF and CS = A15 for 0x8000–0xFFFF.
Memory-Mapped UART
A 16-byte UART at 0xE000–0xE00F uses A0–A3 for its registers and compares the 12 lines A4–A15.
68000 Flash
A 1 MB flash at 0x100000 on the 24-bit bus needs only four compare bits: CS = !A23·!A22·!A21·A20.
74HC138 Block Decoder
Eight 4 KB peripheral blocks from one chip, so each device then only needs its own low address lines.
Last updated: