We represent the functioning of the housing market and the processes that shape residential income segregation by introducing a spatial Agent-Based Model (ABM). Differently from traditional models in urban economics, we explicitly specify the behavior of buyers and sellers and the price formation mechanism. Buyers who differ by income select among heterogeneous neighborhoods using a probabilistic model of residential choice; sellers employ an aspiration level heuristic to set their reservation offer price; prices are determined through a continuous double auction. We first provide an approximate analytical solution of the ABM, shedding light on the structure of the model and on the effect of the parameters. We then simulate the ABM and find that: (i) a more unequal income distribution lowers the prices globally, but implies stronger segregation; (ii) a spike of the demand in one part of the city increases the prices all over the city; (iii) subsidies are more efficient than taxes in fostering social mixing.J.E.L. codes: C63, D31, O18, R23, R31 Keywords: Agent-Based Model, Housing Market, Residential Income Segregation, Aspiration Level Heuristic, Urban Economics * Corresponding author: marco.pangallo@maths.ox.ac.uk. We thank seminar participants at WE-HIA 2016, EAEPE 2016, ISCPIF, SCCS 2015, IRES Piemonte and INET Oxford, in particular Henri Berestycki, Allan Davids, J. Doyne Farmer, Michele Loberto, Mauro Napoletano, David Pugh and Matteo Richiardi, for helpful comments. We also thank Florian Artinger and Gerd Gigerenzer for pointing us to their work on aspiration level heuristics, and Marco Ranaldi and R. Maria del Rio Chanona for carefully reading the manuscript. A previous version of this manuscript circulated under the title "Price formation on a housing market and spatial income segregation". This paper reuses material from the master thesis of MP at the University of Torino. MP especially thanks Pietro Terna, who was the main advisor of his thesis, for insightful and frequent discussions.