2011 wrx Subaru really bad idle

A loud bang like that can be caused by the engine misfiring which sends raw gasoline into the exhaust system, which explodes inside the exhaust pipe/cat/muffler, wherever and you hear a loud bang. This can also damage the exhaust system, which might be the cause of your poor idling. Another idea, some sort of problem with the ignition or valve timing, and the bang was cause b/c an intake valve opened at he time the spark happened. That bang would have come from the intake manifold, which could also have damaged something. Is this engine turbo-charged?

Where I’d start – besides checking for diagnostic codes — is to examine the exhaust system for broken joints, and the intake manifold area for something that has come loose, especially any rubber boots between the air filter and the throttle body. My wild guess, and just a guess, is the valve timing has changed for some reason, some problem with the timing chain system. EGR , fuel pressure, intake manifold vacuum, and cylinder compression tests might be needed too.