In 1975, Malcolm McLaren (defacto manager of the Sex Pistols) took a lease on the outbuilding of No. 6 from the pop/rock group Badfinger ('Come and Get It', 'Without You', 'Baby Blue'). He asked architect Ben Kelly to refurbish the basement room to be used as a studio. The Sex Pistols had it all in one place at No. 6: they lived upstairs, rehearsed in the basement room and recorded their early demos such as 'No Feelings', Pretty Vacant' and 'Anarchy in the UK' there.
In a way, The Pistols stayed there forever since Johnny Rotten created graffiti cartoons of the members across the walls which was later revealed in an archaeological survey of the site.
Sources: Wikipedia,
https://www.classicrocktourlondon.com/post/secrets-of-no-6-denmark-street