Usually: Detonation — the fuel igniting unevenly, often under load or up a hill.
But it can also be: Low octane fuel, carbon build-up, a timing issue, or on higher mileage engines, genuine internal wear.
Knocking or pinging when you accelerate
This one is worth stopping for, and worth getting looked at instead of hoping it goes away. A metallic knocking or pinging sound that shows up when you accelerate, especially climbing a hill or pulling a trailer, is usually detonation. That's the fuel-air mixture igniting unevenly in the cylinder instead of burning the way it should. It's sometimes called spark knock or pinging, and under load is exactly when it tends to show up, because that's when the engine is working hardest.
The most common cause, by a wide margin, is fuel that isn't the right octane for the engine. Some engines are tuned tight enough that a tank of regular instead of mid-grade or premium will bring this on. Carbon buildup on the pistons and combustion chamber can do the same thing, especially on an engine with some miles on it that hasn't had the intake cleaned in a while. A timing issue is possible too, though less common on newer cars where timing is computer controlled. On a higher mileage engine, it can also be a sign of actual internal wear, worn bearings or similar, which is a bigger job and not something to guess at.
A rough way to narrow it down yourself: if the knock only happens under hard acceleration or going uphill, and never at idle or steady cruising speed, that fits detonation and fuel or carbon buildup better than it fits a mechanical problem. If you've recently switched to a cheaper gas station or a lower octane, that's a real clue worth mentioning when you bring it in. If the knock is there all the time, including at idle, or gets worse the longer the engine runs, that points more toward something mechanical.
Is it safe to keep driving? For a day or two, probably, especially if you switch to a higher octane fuel and see if it clears up. But sustained detonation over weeks or months can damage pistons, and that turns a cheap fix into an expensive one. We wouldn't ignore it for long.
What fixing it involves depends on what it turns out to be. Sometimes it really is as simple as running the right fuel. Sometimes it's a carbon cleaning service, which is a few hours of shop time. Timing and internal wear are bigger diagnostic jobs, and we'd want to check codes and do a proper listen before quoting anything. We can take a look and tell you honestly which of these it looks like before any work starts.