arXiv:1206.3093v1; These are the notes prepared for the course "Metric spaces with dilations and sub-riemannian geometry from intrinsic point of view", CIMPA research school on sub-riemannian geometry (2012). Unitary exposition based on several previous papers of mine, especially arXiv:0810.5042, hopefully with many details, explanations and some proofs which I previously skipped