Density functional theory (DFT) is often used for simulating extended materials such as infinite crystals or surfaces, under periodic boundary conditions (PBCs). In such calculations, when the simulation cell has non-zero charge, electrical neutrality has to be imposed and this is often done via a uniform background charge of opposite sign (`jellium'). This artificial neutralization does not occur in reality, where a different mechanism is followed as in the example of a charged electrode in electrolyte solution, where surrounding electrolyte screens the local charge at the interface. The neutralizing effect of surrounding electrolyte can be incorporated within a hybrid quantum-continuum model based on a modified Poisson-Boltzmann equation, where the concentrations of electrolyte ions are modified to achieve electroneutrality. Among the infinite possible ways of modifying the electrolyte charge, we propose here a physically optimal solution which minimizes the deviation of concentrations of electrolyte ions from those in open boundary conditions (OBCs). This principle of correspondence of PBCs with OBCs leads to the correct concentration profiles of electrolyte ions and electroneutrality within the simulation cell and in the bulk electrolyte is maintained simultaneously, as observed in experiments. This approach, which we call the Neutralization by Electrolyte Concentration Shift (NECS), is implemented in our electrolyte model in the ONETEP linear-scaling DFT code which makes use of a bespoke highly parallel Poisson-Boltzmann solver, DL_MG. We further propose another neutralization scheme (`accessible jellium') which is a simplification of NECS. We demonstrate and compare the different neutralization schemes on several examples.