Transcranial electrical brain stimulation techniques like transcranial direct current (tDCS) and transcranial alternating current (tACS) have emerged as potential tools for treating neurological diseases by modulating cortical excitability. These techniques deliver small electric currents to the brain non-invasively through electrodes on the scalp. tDCS uses constant direct current which weakly alters the membrane voltage of cortical neurons, while tACS utilizes alternating current to target and enhance cortical oscillations, though the underlying mechanisms are not fully understood more specifically. To elucidate how tACS perturbs endogenous network dynamics, we simulated spiking neuron network models. We identified distinct roles of the depolarizing and hyperpolarizing phases in driving network activity towards and away from the strong nonlinearity provided by pyramidal neurons. Exploring resonance effects, we found matching tACS frequency to the network's endogenous resonance frequency creates greater entrainment. Based on this, we developed an algorithm to determine the network's endogenous frequency, phase, and amplitude, then deliver optimized tACS to entrain network oscillations. Together, these computational results provide mechanistic insight into the effects of tACS on network dynamics and could inform future closed-loop tACS systems that dynamically tune stimulation parameters to ongoing brain activity.