Both circuits start by turning $|\psi\rangle = a |0\rangle + b|1\rangle$ into $|\psi\rangle = a |000\rangle + b|111\rangle$, copying the 0/1 information onto two additional qubits.
Note that, for any pair of qubits in this state, either both are in state $|0\rangle$, or both are in state $|1\rangle$. Any superposition must be expressed only in terms of states that satisfy this condition.
This gives us a way to check up on whether everything is okay. We make a measurement that checks whether the 0/1 states of two neighbouring qubits are the same or different. We want it to give us only this information and no more, to ensure that preserves superpositions.
Each ancilla in the second circuit is there to perform this exact measurement. The two cnots that act on the ancilla, as well as the measurement gate itself, are all part of the measurement. Th measurement outputs 0
when two qubits can be expressed as a superposition or mixture of $|00\rangle$ and $|11\rangle$. It outputs 1
if they must be expressed with $|01\rangle$ and $|10\rangle$.
Given this information, we can see if errors happened, and try to guess what they were. A corresponding correction operator can then be performed.
The first circuit seems like it could probably correct a bit flip on the first qubit. I'm not really sure what it is designed for, though.