The 8051 microcontroller has 40 pins, 32 of which are used for input/output across 4 ports (P0, P1, P2, P3). Ports P0, P2, and P3 have pins that are multiplexed for address/data functions when accessing external memory, but otherwise function as I/O pins. The remaining pins are used for power (VCC, GND), oscillators (XTAL1, XTAL2), resets (RST), and enabling access to external devices (ALE, PSEN, EA).