A local variable is defined within a specific function or block of code and can only be accessed within that scope. A global variable, on the other hand, is defined outside of any function or block and can be accessed from anywhere in the code.