Both numbers matter because RAM and storage do completely different jobs, even though they're both measured in gigabytes.
Storage (your 512GB) is where files live permanently: your operating system, installed apps, documents, photos, videos, games. It keeps everything saved even when the computer is off. Modern laptops use SSDs (solid-state drives), which are fast, or older/cheaper machines may still use HDDs (spinning hard drives), which are slower. Either way, storage capacity determines how much stuff you can keep on the machine long-term, how many apps you can install, how many files you can save before running out of room.
RAM (your 16GB) is temporary, working memory the computer uses while it's actually running things. When you open an app, the computer loads the relevant data from storage into RAM so the processor can access it instantly. RAM is dramatically faster than storage, but it's volatile, meaning everything in it is wiped the moment you lose power or restart. That's why an unsaved document disappears if your laptop crashes: it only existed in RAM, not yet written to storage.
Think of storage like a filing cabinet and RAM like your desk. The filing cabinet (storage) holds everything you own, but it's slower to dig through. Your desk (RAM) only holds what you're actively working on right now, but you can grab anything on it instantly. A bigger desk (more RAM) lets you have more things open and accessible at once, juggling more browser tabs, more apps, bigger files, without the computer slowing down or needing to constantly swap things in and out. A bigger filing cabinet (more storage) just means more total stuff fits, but it doesn't make any single task run faster.
This is why a computer with tons of storage but very little RAM can still feel sluggish: storage capacity doesn't help if the computer doesn't have enough temporary workspace to actually run your programs smoothly. And a computer with huge RAM but a small drive can run fast but fill up quickly and run out of room to install things. They solve different problems, which is why both specs get listed separately and both matter for different reasons.