Hardware-in-the-loop (HIL) testing methods by means of HIL units or real-time simulators (RTS), are becoming broadly accepted for validating of control systems in many technical areas. This new approach brings advantages such as the acceleration of the industrial and the research development cycle and offers a risk-free and flexible environment for the testing and the evaluation stages before the control deployment in the physical system. Nevertheless, the realization of such methodology can be very challenging in some large or complex plants. In this scenario, a proper simulation of the physical system, that is, the development of its accurate digital twin, demands a suitable and reliable sectioning of the different components into different parts running in parallel into different HIL units. This is the case of a nanogrid (nG) involving some prosumers with renewable energy resources (RES), and their corresponding multiple power electronic converters. These power electronic converters operate at high switching frequencies, which require a very low simulation time step, as well as a high number of input and output signals in closedloop operation. This work analyzes in detail how to realize a digital twin of a two-prosumer residential nG including a photovoltaic (PV)-battery assisted three-level T-type (3L T-Type) inverter and managed by a hierarchical grid-forming (GFM) control structure by means of RTS based on the RT Box 1 by Plexim. The analysis allows to test the proposed GFM controls and the control hardware in steady and transient conditions, validating their accurate performance.INDEX TERMS Digital twin, grid-forming power converters, hardware-in-the-loop, microgrids, real-time simulation, residential nanogrids. MARÍA ISABEL MILANÉS-MONTERO (Member, IEEE) received the M.Sc. degree in industrial engineering and the Ph.D. degree in electrical and electronic engineering from the University of Extremadura, Spain, in 1997 and 2005, respectively. In November 1998, she joined the School of Industrial Engineering, University of Extremadura, as an Assistant Professor and a Researcher with the Power Electrical and Electronic Systems Research and Development Group. Her research interests include power quality, renewable energy sources control, energy storage management systems, smart grids, and electric vehicles. OLEKSANDR HUSEV (Senior Member, IEEE) received the B.Sc. and M.Sc. degrees in industrial electronics from