IRAS 16293-2422 is a well studied low-mass protostar characterized by a strong level of deuterium fractionation. In the line of sight of the protostellar envelope, an additional absorption layer, rich in singly and doubly deuterated water has been discovered by a detailed multiline analysis of HDO. To model the chemistry in this source, the gas-grain chemical code Nautilus has been used with an extended deuterium network. For the protostellar envelope, we solve the chemical reaction network in infalling fluid parcels in a protostellar core model. For the foreground cloud, we explored several physical conditions (density, cosmic ionization rate, C/O ratio). The main results of the paper are that gas-phase abundances of H2O, HDO and D2O observed in the inner regions of IRAS16293-2422 are lower than those predicted by a 1D dynamical/chemical (hot corino) model in which the ices are fully evaporated. The abundance in the outer part of the envelope present chaotic profiles due to adsorption/evaporation competition, very different from the constant abundance assumed for the analysis of the observations. We also found that the large abundances of gas-phase H2O, HDO and D2O observed in the absorption layer are more likely explained by exothermic surface reactions rather than photodesorption processes.