Localization has many important applications in wireless sensor networks (WSNs). A variety of technologies, such as acoustic, infrared and UWB (ultra-wide band) media have been utilized for localization purposes. In this paper, we propose a holistic, bottom-up design of a UWB-based communication architecture and related protocols for localization in WSNs. A new UWB coding method, called U-BOTH (UWB based on orthogonal variable spreading factor and time hopping), is utilized for minimum interference communication, and an ALOHA-type channel access method and a message exchange protocol are used to collect distance information in WSNs. We derive the corresponding UWB path loss model in order to apply the maximum likelihood estimation (MLE) method to compute the distances between neighbor nodes using the RSSI information. Then, we propose NMDS-MLE (non-metric multidimensional scaling and maximum likelihood estimation) localization algorithms based on the two types of distance information: estimated distance and Euclidean distance. The performance of the system is validated using theoretic analysis and simulations.