How computer works Internally ?

Do you know when you press a key of Keyboard then what happens ? how the things working internally that you are getting on the monitor ? If not this article will give you a full idea that how things actually works in computer . It took me 4 months to know all these things and you will Know it just by reading this article .
So Let’s Start -
1. Computer System Architecture
Computers come with different processor architectures: 8-bit, 16-bit, 32-bit, 64-bit.
These define data bus width, register size, instruction size, and addressable memory range.
A broad overview of how actually things work when you write some code -
High Level Language
↓
Assembly Language
↓
Machine Code
↓
Instruction Format (8-bit / 16-bit / 32-bit)
↓
Stored in Memory (RAM)
↓
CPU reads from Memory and Executes
———————————————————————————
┌────────────────────┐
│ ROM │
│ (Permanent programs │
│ like BIOS, firmware) │
└────────────────────┘
↓
[ Only at computer startup / boot time used ]
↓
┌────────────────────┐
│ SSD / Hard Disk │
│ (Your source code, │
│ compiled programs │
│ and data stored here) │
└────────────────────┘
↓
[ When you Run Program ]
↓
┌────────────────────┐
│ RAM (Memory) │
│ (Machine code / │
│ Instructions loaded │
│ here temporarily) │
└────────────────────┘
↓
[ CPU reads Instructions from RAM ]
↓
┌────────────────────┐
│ CPU │
│ (Executes Instructions) │
└────────────────────┘
2. You Press the Key 'A' on the Keyboard
When you press 'a', it's a mechanical switch being triggered on the keyboard matrix.
Keyboard Matrix + Controller
Keyboards are arranged in a row × column matrix.
3. When a key is pressed, the intersection of a specific row and column is detected.
This event is captured by the keyboard's internal microcontroller.
4. Key Scan Code Generation
The microcontroller converts the row-column press into a scan code.
For example, pressing 'a' on a QWERTY keyboard generates a scan code like 0x1C.
5. Scan Code to ASCII Conversion (by OS/Driver)
The scan code is sent over USB or PS/2 interface to the computer.
6. The keyboard driver inside the OS (like Windows/Linux) receives it.
The driver translates it to an ASCII character 'a' (which is 0x61 in ASCII).
7.Interrupt is Triggered to CPU
The keypress triggers an interrupt request (IRQ).
CPU stops its current task and handles the interrupt using an Interrupt Service Routine (ISR).
Character Handling in the OS
The operating system processes this input, usually pushing it into a keyboard buffer.
8. This buffer stores keys temporarily for use by applications like editors, shells, etc.
9.Application-Level Input Handling
Say you’re typing in a program like Notepad or a C/C++ program.
The application reads the character 'a' from the buffer using input handling functions (cin, scanf, etc.).
10 .Storing the Value of a Variable
Suppose in C code: a = 9;
Compiler will:
Allocate memory for a (maybe in stack or data section).
Generate an instruction like MOV EAX, 9 → MOV [a], EAX.
11. Assembly to Machine Code Translation
MOV EAX, 9 is written in assembly.
During compilation, this gets converted into machine code:
Example: B8 09 00 00 00 → where B8 is opcode for MOV EAX, imm32
12. Instruction Execution in CPU
CPU fetches the instruction:
Instruction Register (IR) stores the opcode.
Control Unit (CU) decodes it.
ALU executes it if arithmetic/logical.
The number 9 is placed in the register EAX.
It can then be moved into memory using an address from the stack or data segment.
13. Memory Operations
If a is stored in memory:
Address Bus is used to specify the memory address.
Data Bus carries the actual value (9).
On a 32-bit system:
Addresses are 4 bytes wide.
Data is processed in 32-bit registers like EAX, EBX, etc.
Output on Screen
If you later print the value of a:
CPU executes display-related system calls.
These system calls go to the OS kernel.
14. The OS communicates with the GPU (Graphics Card) using drivers and framebuffer/memory-mapped I/O.
15. Graphics Rendering
GPU takes characters like '9', draws the glyph using a font rasterizer.
Converts into pixels on the screen using the frame buffer.
Your display controller refreshes the screen 60/75/144 times per second to show updated pixels.
Subscribe to my newsletter
Read articles from Divyansh pratap singh directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Divyansh pratap singh
Divyansh pratap singh
Blogging my tech Journey | Love to Explain Horrible topics into simpler way