Computer memory refers to any medium that stores digital data to be accessed and used by a computer. The term often refers to a computer's primary system memory, or RAM, that temporarily stores active programs and files. However, it may also refer to a computer's storage devices like hard drives, solid-state drives, and removable USB flash drives.
Random access memory, or RAM, is a computer's primary system memory. When a computer boots up, it loads the operating system into RAM, allowing it to run programs and accept user input. Opening a program or a file also loads it into RAM, letting the CPU run the program and read and modify the file. RAM is faster than storage disks, allowing the CPU to read its contents with less delay. However, RAM is a type of volatile memory that does not preserve its contents while powered off. Turning off a computer (or restarting it) clears the RAM entirely, so anything not saved to a disk is lost.
A computer's CPU accesses the RAM over a dedicated series of wires on the motherboard, called a bus. Since the memory bus provides a direct connection between the RAM and CPU, the CPU can read data from RAM with little latency. The CPU also includes a small amount of memory, called a cache, built directly into the CPU chip. This cache is even faster than the system RAM but is limited in size, so it only stores the instructions telling the CPU what to do and other frequently-used data.
Read-only memory, or ROM, is a non-volatile memory chip built into every computer and component. ROM chips keep their contents in a read-only state that can only be rewritten under certain conditions (depending on the type of ROM chip). ROM is not meant for temporary storage but instead stores data like a device's firmware, bootloader, and BIOS / UEFI — all of which contain instructions that are necessary for a computer to boot up.
Storage devices like hard drives, solid-state drives, and USB flash drives are also known as secondary memory. These devices provide longer-term data storage for files, applications, and the computer's operating system. Secondary memory is slower than system RAM but is available in much larger sizes. The CPU does not have direct access to the contents of secondary memory, so files and applications are copied into RAM when opened.