We introduce an endogenous network model of the interbank overnight lending market. Banks are motivated to meet the minimum reserve requirements set by the Central Bank, but their reserves are subject to random shocks. To adjust their expected end-of-the-day reserves, banks enter the interbank market, where borrowers decrease their expected cost of borrowing with the Central Bank, and lenders decrease their deposits with the Central bank in attempt to gain a higher interest rate from the interbank market, but face a counter-party default risk. In this setting, we show that a nancial network arises endogenously, exhibiting a unique giant component which is at the same time connected but bipartite in lenders and borrowers. The model reproduces features of trading decisions observed empirically in the Italian e-MID market for overnight interbank deposits.