If you're seeing this message, it means we're having trouble loading external resources on our website.

If you're behind a web filter, please make sure that the domains *.kastatic.org and *.kasandbox.org are unblocked.

### Course: Computers and the Internet>Unit 2

Lesson 3: Logic gates and circuits

# Logic circuits

Computers often chain logic gates together, by taking the output from one gate and using it as the input to another gate. We call that a logic circuit.
Circuits enables computers to do more complex operations than they could accomplish with just a single gate.
The smallest circuit is a chain of 2 logic gates. Consider this circuit:
Inputs A and B first go through an AND gate. Then the output of that gate goes through an OR gate, combined with another input, C.
Now interesting things happen based on which inputs are $0$ or $1$.
Let's set everything to on at first - all inputs are $1$ or "true":
The output is also $1$ or "true", since $1$ AND $1$ is $1$, and $1$ OR $1$ is also $1$.
What if we set inputs A and B to off, and keep C on?
In this case, the output is still $1$! That's because the final step is an OR gate, so it only needs one of the inputs to be on for it to output a $1$.
Now you try it. What do you think this chain will output if we set inputs A and B to $1$ and set input C to $0$?

Try one more combination. What if we set input A to $1$, input B to $0$, and input C to $0$?

If you're struggling to figure out what a circuit outputs, try tracing it one gate at a time. Get out a pencil and paper, start on the first gate, write its output over the wire, then look at the next gate. Theoretically, you could figure out the output for a chain of gates that's hundreds of gates long! You probably have more exciting things to do though, so it's a good thing that we typically have computers to do that for us.

## Want to join the conversation?

• What would happen with more complex chains with changing variables? Like an "if" statement changes A variable into what B variable is at that moment. Wouldn't that change an entire logic chain?
• OoOooOooOOooooOOOOooOooooOooooOOOOOO
• How come when A is 1 and B is 0 when it goes through the "and" gate it is 0 and not 1
• The AND gate only outputs 1 when both of its inputs equal 1.
• I understood all of this, but can you make a video or article about doing computation with these logic gates? Like multiplication or division with these?
• what is AND?
• AND is a logic operator that outputs a true if both of the values that it inputs are true, and false if both of the values are false. If one input is true and the other is false, the output of the AND (&&) operator is false.
• How can I understand logic gates better?
• In what ways are these chips used? How do programmers recognize and remember all of them?
• Programmers don't actually have to remember what all of the logic circuits and chips do, just that they work reliably to do what they need them to do.
Put more simply, they don't need to know how exactly it works, just that it does work.
Hope this helps! (: