I can write a program that handles 64-bit data on a 32-bit OS like XP, but actual RAM access is limited to 2GB on any 32-bit operating system. But a 32-bit operating system is still capable of working with 64-bit data (like large numbers) if the program was made accordingly. But to use 4GB of RAM, I think is dependent on the OS.
Not really true. Photoshop can use way more than 2 gigs of RAM in Mac OS X and that's a 32-bit app running on a 32-bit OS.
As timthetortoise noted, the 2 gig limit is only true in Windows because it by default does a "2/2 split" with two gigs of address space for user space and gigs of address space for the kernel. The purpose of this is for faster data transfer between user space and the kernel, but the net effect is that you have a more limited address space in both places. User-space apps are limited to 2 gigs, and graphics cards start biting you in the ass with modern hardware because you have to be able to map their entire aperture into the kernel and... oops, two one gig graphics cards and you have to drop the 2/2 mapping or you won't boot.
I -think- Linux typically uses a 3/1 mapping, which means that the kernel has a gig and user space gets three. This is more workable in Linux because the graphics card aperture gets mapped into the X11 binary itself under normal circumstances, and the kernel drivers only map a fraction of the graphics RAM for a text console.
Mac OS X uses a 4/4 mapping, which means that user space and the kernel both have a full 4 GB address space that does not overlap. This means you can't just treat kernel and user-space addresses as being equivalent and you have to explicitly map data when going back and forth. There's a slight performance hit, but the functionality advantages are significant if you have the RAM to take advantage of them.
As a caveat, though, the memory available to applications is reduced by shared library code, the stack, etc. (We normally don't consider the stack as application memory because it can't be freely allocated and deallocated and is context sensitive.) Thus, in Mac OS X, the space typically available to an application is more on the order of 3 gigs, with only about 2.5 contiguous, if memory serves. Of course, this also means that in Windows, it is far less than two gigs. Also, don't forget that your application's actual executable code comes out of that.
Even better, though, Photoshop does its own virtual memory scheme in which it memory maps chunks of large files on disk into RAM. Although it can only see a 2.5-ish gig combined window into those files, the operating system is still keeping track of recently-accessed blocks on disk in its buffer cache. The net effect is that the total portion of those files in RAM can be arbitrarily large---in theory, up to the limits of memory.
While it is slightly slower to map those chunks of RAM into the application's address space than it would be if you actually had 16 GB of usable application memory, the application can still access that extra RAM in your computer at a speed orders of magnitude faster than actually paging from disk. Thus, in effect, Photoshop is able to use way more than even 4 GB of memory even as a 32-bit application on a 32-bit OS.
To some degree, even audio apps take advantage of this when the OS buffers file reads from raw audio files, but not nearly to the degree that apps like Photoshop do....