In this dissertation, we consider the problem of assigning spectrum to wireless local-area networks (WLANs). In line with recent IEEE 802.11 amendments and newer hardware capabilities, we consider situations where wireless nodes have the ability to adapt not only their channel center-frequency but also their channel width. This capability brings an important additional degree of freedom, which adds more granularity and potentially enables more efficient spectrum assignments. However, it also comes with new challenges; when consuming a varying amount of spectrum, the nodes should not only seek to reduce interference, but they should also seek to efficiently fill the available spectrum. Furthermore, the performances obtained in practice are especially difficult to predict when nodes employ variable bandwidths. We first propose an algorithm that acts in a decentralized way, with no communication among the neighboring access points (APs). Despite being decentralized, this algorithm is self-organizing and solves an explicit tradeoff between interference mitigation and efficient spectrum usage. In order for the APs to continuously adapt their spectrum to neighboring conditions while using only one network interface, this algorithm relies on a new kind of measurement, during which the APs monitor their surrounding networks for short durations. We implement this algorithm on a testbed and observe drastic performance gains compared to default spectrum assignments, or compared to efficient assignments using a fixed channel width. Next, we propose a procedure to explicitly predict the performance achievable in practice, when nodes operate with arbitrary spectrum configurations, traffic intensities, transmit powers, etc. This problem is notoriously difficult, as it requires capturing several complex interactions that take place at the MAC and PHY layers. Rather than trying to find an explicit model acting at this level of generality, we explore a different point in the design space. Using a limited number of real-world measurements, we use supervised machine-learning techniques to learn implicit performance models. We observe that these models largely outperform other measurement-based models based on SINR, and that they perform well, even when they are used to predict performance in contexts very different from the context prevailing during the initial set of measurements used for learning. We then build a second algorithm that uses the above-mentioned learned models to assign the spectrum. This algorithm is distributed and collaborative, meaning that neighboring APs have to exchange a limited amount of control traffic. It is also utility-optimal -- a feature enabled both by the presence of a model for predicting performance and the ability of APs to collaboratively take decisions. We implement this algorithm on a testbed, and we design a simple scheme that enables neighboring APs to discover themselves and to implement collaboration using their wired backbone network. We observe that it is possible to effectively gear the performance obtained in practice towards different objectives (in terms of efficiency and/or fairness), depending on the utility functions optimized by the nodes. Finally, we study the problem of scheduling packets both in time and frequency domains. Such ways of scheduling packets have been made possible by recent progress in system design, which make it possible to dynamically tune and negotiate the spectrum band [...]