Most mobile robots do this using a technique called SLAM (simultaneous localisation and mapping), whereby they build up a map of their unknown environment, using various sensors, whilst keeping track of their current position at the same time.
BBC: NEWS | Technology | 'Guessing' robots find their way