Heparin, a naturally occurring glycosaminoglycan, has been found to have antiviral activity against SARS-CoV-2, the causative virus of COVID-19. To elucidate the mechanistic basis for the antiviral activity of heparin, we investigated the binding of heparin to the SARS-CoV-2 spike glycoprotein by means of sliding window docking, molecular dynamics simulations, and biochemical assays. Our simulations show that heparin binds at long, positively-charged patches on the spike glycoprotein, thereby masking basic residues of both the receptor binding domain (RBD) and the multifunctional S1/S2 site. Biochemical experiments corroborated the simulation results, showing that heparin inhibits the furin-mediated cleavage of spike by binding to the S1/S2 site. Our simulations also showed that heparin can act on the hinge region responsible for motion of the RBD between the inactive closed and active open conformations of the spike glycoprotein. In simulations of the closed spike homotrimer, heparin binds the RBD and the N-terminal domain of two adjacent spike subunits and hinders opening. In simulations of open spike conformations, heparin induces stabilization of the hinge region and a change in RBD motion. Taken together, our results indicate that heparin can inhibit SARS-CoV-2 infection by three mechanisms: by allosterically hindering binding to the host cell receptor, by directly competing with binding to host heparan sulfate proteoglycan co-receptors, and by preventing spike cleavage by furin. Furthermore, these simulations provide insights into how host heparan sulfate proteoglycans can facilitate viral infection. Our results will aid the rational optimization of heparin derivatives for SARS-CoV-2 antiviral therapy.