There are multiple reasons engine knock could occur. Here are a few potential causes:
Poor timing: The spark is not igniting at the correct time.
Improper air and fuel mixture: If the ratio of air to fuel is incorrect, this could create ignition problems.
Deposits inside the cylinder: Dirt, grime, and contaminants can enter cylinders and create all sorts of issues, including hot spots that may lead to autoignition.
Faulty, unhealthy, or incorrect spark plugs: The wrong type of spark plug, spark plugs with deposit build-up, or incorrect spark plug gaps could cause poor spark or incorrectly timed spark.
A knock sensor is essentially a small “listening” device in or on the engine that detects irregular vibrations and sounds that come from the engine block.
The knock sensor picks up vibration and sound coming from the engine block, turns it into an electronic signal and sends that signal to the engine control unit (ECU). The car’s computer then judges the information and determines whether or not ignition timing should be altered.
Generally if poor fuel is being used, a pre-ignition situation can be predicted by the ECU and it can thus alter the ignition timing.