Two gates, one loop
Start with two NOR gates. A NOR gate outputs 1 only when both of its inputs are 0; any 1 going in makes its output 0. Gate 1 will make an output called Q, gate 2 one called Q̄ (say Q-bar).
Now wire each output back into the other gate. Feeding an output back in as an input is called feedback. Q goes into gate 2 and Q̄ goes into gate 1, so the two gates keep each other steady.
Set, hold, reset
Turn on S, the set input. Gate 2 now has a 1 going in, so Q̄ drops to 0. That 0 travels round to gate 1, which now sees 0 and 0, so Q rises to 1.
Turn S off again. Nothing changes: Q stays 1, because Q feeds a 1 into gate 2, which keeps Q̄ at 0. The loop remembers the last value. That is one bit of memory.
Turn on R, the reset input. Gate 1 now has a 1 going in, so Q drops to 0. That 0 travels round to gate 2, which now sees 0 and 0, so Q̄ rises to 1.
Turn R off. Q stays 0: Q̄ feeds a 1 into gate 1, which holds Q at 0. With S and R both 0, the latch keeps whatever it was last told, set or reset.
Rules and variants
Turning on S and R together is not allowed. Both gates get a 1, so Q and Q̄ are both 0, which breaks the rule that they are opposites. Release both at once and the result is unpredictable.
Here are the rules in one table. S = 1 sets Q to 1. R = 1 resets Q to 0. Both 0 holds the last value. Both 1 is not allowed. This circuit is called an SR latch.
Two NAND gates make a latch too. Its inputs are active-low: they rest at 1 and act when pulled to 0, so they are written S̄ and R̄. A 0 on S̄ sets Q to 1, and Q stays 1.
Gate by gate
;; step 1/9 · two-nor ;; about: Gate 1, Gate 2 NOR = NOT OR A B → out 0 0 → 1 0 1 → 0 1 0 → 0 1 1 → 0 Only 0 and 0 give a 1.
In the figure the gates change one after another so you can follow the loop. In a real chip each gate takes a tiny delay (nanoseconds or less), so the whole loop settles almost at once. In Python, | on the numbers 0 and 1 is OR, so NOR of two bits is 1 - (a | b). The loop runs a few times so the two gates can settle.