Autopsy of Vulnerabilities

Periodically, security releases are published to patch vulnerabilities and make our websites secure again, but do we know exactly how these vulnerabilities (and their exploits) work behind the scenes? How does the patch change our code, so the vulnerabilities are fixed and the risk mitigated?