Scatter a program's memory across fixed-size frames and translate every address through a page table — O(1) lookup, no external fragmentation.
Paging lets a program's memory be scattered all over physical RAM instead of sitting in one continuous block — and lets parts of it stay on disk until they're actually touched. The OS cuts a program's address space into fixed-size pages and cuts RAM into equal-size frames. A page can go in *any* free frame; a page table records which frame each page landed in.
Programs use virtual addresses that say nothing about where data physically sits. The hardware splits each one into a page number and an offset into that page. If the page size is a power of two, this split is just slicing the bits: the low bits are the offset, the high bits are the page number. Translation keeps the offset and swaps the page number for its frame.
// Page size = 1024 bytes (2^10), so the low 10 bits are the offset.
// Page table: pageTable[pageNumber] = frameNumber
const pageSize = 1024;
function translate(virtualAddr, pageTable) {
const page = Math.floor(virtualAddr / pageSize);
const offset = virtualAddr % pageSize;
const frame = pageTable[page]; // which frame holds this page
return frame * pageSize + offset; // physical address
}1024 bytes, and the program reads virtual address 1500.1500 / 1024 = 1; offset = 1500 % 1024 = 476.4 * 1024 + 476 = 4572 — same offset, new frame.