Learn the Logical and Physical Address Description in operating systems with simple examples, differences, and how memory mapping works.
When you hear the terms logical address and physical address in operating systems, it can sound confusing at first. But don’t worry — by the end of this guide, you’ll understand both clearly with simple examples and how they work together in memory management.
Introduction of Difference Between Logical and Physical Address
In computer systems, memory plays a vital role in how data and programs are stored and accessed. The CPU doesn’t directly deal with the actual (hardware) memory locations. Instead, it uses something called a logical address.
The operating system and the Memory Management Unit (MMU) then convert that logical address into a physical address, which points to the actual location in RAM.
So, understanding the difference between logical vs physical address is key to learning how memory management works in an operating system.
What is a Logical Address?
A logical address (also called virtual address) is the address generated by the CPU when a program is running.
It is not the real location in the memory; instead, it’s used by programs to access memory in an abstract way.
Example:
When a process wants to access a variable, it uses a logical address like 0x0032.
But this doesn’t tell where that variable is physically located in RAM.
Key Points about Logical Address:
- Generated by the CPU during program execution.
- Used by programs and processes.
- Exists in the user space (visible to programmers).
- Converted to physical address by the Memory Management Unit (MMU).
What is a Physical Address?
A physical address refers to the actual location in RAM (main memory) where data or instructions are stored.
After the logical address is generated, the MMU translates it into a physical address, which the hardware can use to access memory directly.
Example:
If the logical address is 0x0032, the MMU might convert it into the physical address 0xA032 depending on the mapping.
Key Points about Physical Address:
- Represents the actual location in main memory (RAM).
- Used by hardware to fetch or store data.
- Not visible to the user or programmer.
- Exists in the hardware memory space.
Difference Between Logical and Physical Address
Here’s a simple comparison table to understand the difference:
| Parameter | Logical Address | Physical Address |
|---|---|---|
| Definition | Address generated by the CPU during program execution | Actual location of data in main memory (RAM) |
| Visible To | Programmer | Hardware only |
| Generated By | CPU | Memory Management Unit (MMU) |
| Usage | Used by programs to access memory | Used by hardware to access actual memory |
| Accessibility | User can see logical addresses | User cannot see physical addresses |
| Space | Exists in user space | Exists in hardware memory space |
| Example | 0x0032 | 0xA032 |
How Address Translation Works
The conversion from logical address to physical address is handled by the Memory Management Unit (MMU).
Here’s the process in simple steps:
- The CPU generates a logical address.
- The MMU adds the base address (relocation register) to the logical address.
- The resulting address is the physical address used to access RAM.
Formula:
Physical Address = Base Address + Logical AddressThis process ensures that every program thinks it has its own memory space, even though all programs share the same physical memory.
Example for Better Understanding
Let’s say:
- Base address = 1000
- Logical address = 200
Then,
Physical Address = 1000 + 200 = 1200sSo, the data that appears at logical address 200 is actually stored at physical memory location 1200.
Why This Difference Matters
Understanding the difference between logical and physical address helps in:
- Memory protection: Prevents one program from accessing another’s memory space.
- Efficient multitasking: Enables multiple processes to run smoothly without overlapping memory.
- Virtual memory systems: Helps implement paging and segmentation effectively.
C Code: Logical and Physical Address Concept Demo
/*
* Logical and Physical Address Demonstration in C
* -----------------------------------------------
* This program explains how logical (virtual) and physical
* addresses are related conceptually.
*
* Note:
* In user space, we can only see logical (virtual) addresses.
* Physical addresses are managed by the OS and MMU (Memory Management Unit).
*
* Author: Raj
*/
#include
#include
int global_var = 50; // Stored in data segment (global memory)
void show_addresses()
{
int local_var = 20; // Stored in stack
int *heap_var = malloc(sizeof(int)); // Stored in heap
*heap_var = 100;
printf("\n=== Logical Address Demonstration ===\n");
printf("Address of function (code/text segment): %p\n", (void*)show_addresses);
printf("Address of global_var (data segment): %p\n", (void*)&global_var);
printf("Address of local_var (stack): %p\n", (void*)&local_var);
printf("Address of heap_var (heap): %p\n", (void*)heap_var);
printf("\nNote: All above are logical addresses assigned by CPU.\n");
printf(" The OS and MMU translate them into actual physical addresses internally.\n");
free(heap_var);
}
int main()
{
printf("Logical and Physical Address Description Example\n");
show_addresses();
return 0;
}
Explanation
- Code/Text Segment – Where compiled instructions of your program are stored.
- Data Segment – Holds global and static variables.
- Heap Segment – Used for dynamically allocated memory (
malloc,calloc). - Stack Segment – Stores local variables and function calls.
Each printed address represents a logical (virtual) address generated by the CPU.
The Memory Management Unit (MMU) inside your computer translates these into physical addresses — the real hardware locations in RAM.
How to Run
gcc -o address_demo address_demo.c
./address_demoKind of interviewer might ask this, why they ask it, and sample questions you might face
When an interviewer asks about logical and physical addresses, they’re usually trying to check your understanding of memory management — one of the core topics in operating systems and embedded systems interviews.
1. Type of Interviewer Who Asks This
| Interviewer Role | Where You’ll See This Question | Purpose of Asking |
|---|---|---|
| Embedded Software Engineer / System Engineer | KPIT, Bosch, Continental, Qualcomm, etc. | To test if you understand how hardware interacts with memory. |
| Operating System Developer / Linux Driver Engineer | OS or kernel-level interviews | To verify your grasp on address mapping, MMU, and virtual memory. |
| Computer Science Fundamentals Round | General software engineer interviews | To check your theoretical understanding of OS memory. |
| Firmware Developer / RTOS Engineer | QNX, FreeRTOS, or bare-metal projects | To ensure you can manage memory manually and know the difference between CPU-generated and real memory addresses. |
2. Why They Ask This Question
Interviewers want to see if you can explain:
- What happens when a program runs in memory.
- How CPU-generated addresses differ from hardware memory addresses.
- How MMU, paging, segmentation, and virtual memory come into play.
- Whether you can connect theory to real-world embedded systems.
3. Common Interview Questions on Logical & Physical Address
Here’s a list of typical questions — from easy to advanced — so you can prepare:
| Level | Question | Expected from You |
|---|---|---|
| Basic | What is the difference between logical and physical address? | Simple definition and difference table. |
| Basic | Who converts logical address to physical address? | Mention MMU (Memory Management Unit). |
| Basic | Can the user see the physical address? | No — only logical (virtual) addresses are visible to user programs. |
| Intermediate | Why does the OS use logical addresses instead of physical ones? | Explain memory protection, abstraction, and process isolation. |
| Intermediate | How does MMU perform address translation? | Explain base address + offset or page table mapping. |
| Intermediate | What are paging and segmentation in memory management? | Relate them to logical and physical addressing. |
| Advanced | How are logical and physical addresses handled in QNX/Linux? | Discuss virtual memory, page tables, and mapping done by kernel. |
| Advanced | How does address translation happen in embedded systems without MMU (bare-metal)? | Explain that logical = physical address (1:1 mapping) since no MMU. |
4. Example Answer (Short & Effective)
Q: What is the difference between logical and physical address?
A: A logical address is generated by the CPU when a program runs, while a physical address represents the actual location in RAM. The MMU translates the logical address into a physical one for hardware access. This translation ensures process isolation and efficient memory use.
5. Pro Tip (For Embedded Interviews)
If you’re facing embedded system or QNX/Linux driver interviews:
- Mention that in microcontrollers (without MMU), logical and physical addresses are the same.
- In OS-based systems (Linux/QNX), address translation happens through page tables and MMU.
Related Article regrading Logical and Physical Address
If you’re learning about memory management, you should also read:
What is Demand Paging?
It explains how pages are loaded into memory only when needed — a smart way of using logical and physical addresses efficiently.
FAQs on Difference Between Logical and Physical Address
Q1. What is the main difference between logical and physical address?
A logical address is generated by the CPU, while a physical address represents the real location in RAM.
Q2. Who converts the logical address to physical address?
The Memory Management Unit (MMU) performs the translation automatically.
Q3. Can a programmer access a physical address?
No, the programmer only deals with logical addresses for safety and abstraction.
Q4. Why do we need both logical and physical addresses?
They provide security, flexibility, and efficient use of memory by separating user and hardware memory spaces.
Conclusion of Difference Between Logical and Physical Address
In summary,
- The logical address is what the CPU generates.
- The physical address is where the data actually lives in memory.
- The MMU is the bridge between them.
This separation ensures better memory management, protection, and multitasking in operating systems.
So next time you run a program, remember — the address you see is logical, but the real magic happens behind the scenes in physical memory!
Mr. Raj Kumar is a highly experienced Technical Content Engineer with 7 years of dedicated expertise in the intricate field of embedded systems. At Embedded Prep, Raj is at the forefront of creating and curating high-quality technical content designed to educate and empower aspiring and seasoned professionals in the embedded domain.
Throughout his career, Raj has honed a unique skill set that bridges the gap between deep technical understanding and effective communication. His work encompasses a wide range of educational materials, including in-depth tutorials, practical guides, course modules, and insightful articles focused on embedded hardware and software solutions. He possesses a strong grasp of embedded architectures, microcontrollers, real-time operating systems (RTOS), firmware development, and various communication protocols relevant to the embedded industry.
Raj is adept at collaborating closely with subject matter experts, engineers, and instructional designers to ensure the accuracy, completeness, and pedagogical effectiveness of the content. His meticulous attention to detail and commitment to clarity are instrumental in transforming complex embedded concepts into easily digestible and engaging learning experiences. At Embedded Prep, he plays a crucial role in building a robust knowledge base that helps learners master the complexities of embedded technologies.












