Context-aware computing is a lethal paradigm for making technology inconspicuous in people's lives. It is a disruptive technology capable of transforming and enriching human experience. Traditionally, applications collected context data directly from sensors and utilized them to target a narrow set of use cases. However, this is not a scalable approach. With the advent of Internet of Things (IoT), which envisions billions and trillions of sensors and devices generating context data, a common infrastructure or middleware for managing context is paramount for development, deployment and widespread use of context-aware applications. However, managing context in IoT is fraught with challenges. To this end, we propose Machine-to-Machine (M2M) as a podium for managing context life cycle in an IoT environment. We systematically discuss challenges in each phase of context life cycle and provide solutions and based on these solutions, propose a gateway-based reference architecture, entailing hierarchical hybrid context modelling and reasoning, for context management in IoT. We demonstrate the proof of concept by implementing a prototype for the reference architecture. The proposed reference architecture also derives importance from the fact that it does not radically alter the existing end-to-end M2M system architecture and aids in standardization activities.