In this article we introduce all the ingredients to develop adaptive isogeometric methods based on hierarchical B-splines. In particular, we give precise definitions of local refinement and coarsening that, unlike previously existing methods, can be understood as the inverse of each other. We also define simple and intuitive data structures for the implementation of hierarchical B-splines, and algorithms for refinement and coarsening that take advantage of local information. We complete the paper with some simple numerical tests to show the performance of the data structures and algorithms, that have been implemented in the open-source Octave/Matlab code GeoPDEs.