{
  "id": "latch",
  "title": "Latch",
  "lang": "en",
  "source_lang": "en",
  "summary": "A latch is a bistable digital circuit that stores one bit, retaining its state until its inputs cause it to change.",
  "category": "computer-science",
  "subcategory": "hardware",
  "type": "concept",
  "aliases": [
    "Electronic latch",
    "Bistable latch"
  ],
  "generated_at": "2026-11-04",
  "model": "pro/gpt-6.1-sol",
  "url": "https://aiwiki.page/en/latch/",
  "translations": {
    "zh-Hans": {
      "url": "https://aiwiki.page/zh/latch/",
      "json": "https://aiwiki.page/zh/latch.json"
    }
  },
  "sections": [
    {
      "heading": "",
      "text": "A latch is a digital circuit that stores one bit of information by maintaining either of two stable states. Its output depends on both its inputs and its previously stored state, making it a basic element of sequential logic. Some latches respond directly to set and reset inputs; others accept data only while an enable signal is active. In the latter case, the latch is level-sensitive: it can respond throughout an interval, rather than only at a signal transition.\n\nLatches are used in control circuits, temporary data storage, interfaces, and processor timing structures. Modern terminology generally distinguishes them from flip-flops, which are usually edge-triggered storage elements, although historical usage and some component documentation use the terms less strictly."
    },
    {
      "heading": "Operating principle",
      "text": "A latch typically uses feedback to preserve its state. In a simple implementation, two logic gates are cross-coupled: each gate’s output feeds an input of the other. This arrangement can sustain one of two complementary states.\n\nThe main output is conventionally labeled \\(Q\\). Many implementations also provide an output labeled \\(\\overline{Q}\\), which is the logical complement of \\(Q\\) during valid, stable operation. Input signals can force the circuit into either state; when those signals are removed or disabled, feedback maintains the selected state.\n\nThis behavior differs from combinational logic, whose outputs depend only on the current inputs after propagation delays have elapsed. A latch contains memory: identical current inputs can produce different outputs depending on the circuit’s history.\n\nDigital states are abstractions of electrical behavior. Actual latch outputs are voltages that take finite time to change, and internal nodes need not remain at valid logic levels during a transition."
    },
    {
      "heading": "Main types",
      "text": "Set–reset latch\n\nA set–reset latch, or SR latch, has inputs that request one of two actions:\n\n- Set: make \\(Q=1\\).\n- Reset: make \\(Q=0\\).\n\nA common implementation uses two cross-coupled NOR gates with active-high inputs. Its idealized state table is:\n\nSet \\(S\\) | Reset \\(R\\) | Result\n0 | 0 | Retain the previous state\n0 | 1 | Reset: \\(Q=0\\)\n1 | 0 | Set: \\(Q=1\\)\n1 | 1 | Forbidden condition\n\nFor the permitted input combinations, its characteristic equation is\n\n\\[Q_{\\text{next}}=S\\lor(\\neg R\\land Q).\\]\n\nHere, \\(Q\\) denotes the previous state and \\(Q_{\\text{next}}\\) the state reached after the circuit settles.\n\nWith both inputs high, a NOR-based SR latch drives both outputs low, so they are no longer complementary. If both inputs are then deasserted nearly simultaneously, the resulting stored state may be unpredictable, and the circuit may temporarily become metastable. The forbidden condition is therefore not merely an unspecified entry in an otherwise ideal truth table; it reflects a physical limitation.\n\nAn SR latch can also use cross-coupled NAND gates. In that form, the inputs are normally active-low: both inputs high retain the state, while both low produce the forbidden condition. Input polarity must therefore be considered when interpreting a latch symbol or data sheet.\n\nGated SR latch\n\nA gated SR latch adds an enable input. When enabled, set and reset control the stored state. When disabled, changes at those inputs do not affect it.\n\nGating provides control over when the latch can change, but it does not inherently eliminate an invalid combination of set and reset. Depending on the design, simultaneous requests may remain forbidden or may have a specified priority.\n\nD latch\n\nA D latch, or data latch, has a data input \\(D\\) and an enable input \\(E\\). For an active-high enable, its ideal behavior is\n\n\\[Q_{\\text{next}}= \\begin{cases} D, & E=1,\\\\ Q, & E=0. \\end{cases}\\]\n\nWhile enabled, the output follows the input after a propagation delay. The latch is then described as transparent. When the enable becomes inactive, the latch closes and retains the last valid data value.\n\nA basic D latch can be derived from a gated SR latch by generating complementary set and reset requests from \\(D\\). This removes the forbidden input combination from the ideal external interface, but it does not remove the physical timing requirements of the circuit.\n\nActive-low D latches operate similarly, except that transparency occurs while the enable is low. Devices may also include asynchronous set or reset inputs that override ordinary data operation."
    },
    {
      "heading": "Latches and flip-flops",
      "text": "The central distinction is level sensitivity versus edge triggering.\n\nA transparent D latch can pass multiple data changes to its output during an enabled interval. An edge-triggered D flip-flop captures data around a specified transition, such as the rising edge of a clock, and otherwise holds its output.\n\nTwo latches with complementary transparency phases can form a master–slave storage structure with edge-triggered behavior. Other flip-flop implementations use different internal circuits, so a flip-flop is not universally equivalent to a particular two-latch arrangement.\n\nProperty | Level-sensitive D latch | Edge-triggered D flip-flop\nData acceptance | Throughout an enabled interval | Around a specified clock edge\nOutput behavior | Can follow data while transparent | Normally changes in response to the active edge\nTiming boundary | Closing transition of enable | Active clock transition\nTiming flexibility | Can support time borrowing | Conventionally analyzed between clock edges\n\nThese differences affect the organization of processors and other synchronous systems. Latches can provide useful timing flexibility, while edge-triggered storage often makes cycle boundaries easier to reason about."
    },
    {
      "heading": "Timing and physical limitations",
      "text": "Propagation delay, setup time, and hold time\n\nA latch does not respond instantaneously. Its specifications may distinguish data-to-output delay while transparent from enable-to-output delay when enabling allows stored or applied data to appear.\n\nTo capture a defined value reliably, the data must satisfy timing requirements around the latch’s closing transition:\n\n- Setup time: the required interval for which data must be stable before the latch closes.\n- Hold time: the required interval for which data must remain stable afterward.\n\nMinimum enable-pulse widths and timing requirements for asynchronous controls may also apply. The precise requirements depend on the implementation and operating conditions.\n\nMetastability\n\nIf data changes too close to the closing transition, the latch may enter metastability: a temporary condition in which its internal voltages have not resolved into a valid stable state. The output may settle later than expected, making its value or timing unsuitable for downstream logic.\n\nMetastability is a consequence of the analog behavior underlying digital storage. Synchronization circuits can reduce the probability that an unresolved state propagates into a system, but no finite settling interval guarantees resolution in every possible case.\n\nRace-through\n\nIf successive latches are transparent at the same time, data may pass through multiple intended storage boundaries in one interval. This is known as race-through. Whether it occurs depends on enable overlap, clock distribution, circuit delays, and minimum path delays.\n\nLatch-based systems often use complementary or non-overlapping clock phases to control transparency. Clock skew, short data paths, and hold-time constraints remain important even when the nominal phases are distinct.\n\nTime borrowing\n\nIn a latch-based pipeline, data can arrive after a receiving latch has opened and still be accepted before it closes. A slower logic stage can therefore use part of the timing interval that would otherwise be available to a subsequent stage. This is called time borrowing.\n\nTime borrowing can accommodate unequal logic delays, but it does not create additional time overall. Time used by one stage reduces the timing budget available elsewhere, and setup and hold constraints still apply."
    },
    {
      "heading": "Circuit implementation",
      "text": "Latches can be built from discrete components or incorporated into an integrated circuit. In CMOS technology, implementations may use cross-coupled inverters, transmission gates, or other transistor arrangements that combine input selection with state retention.\n\nA static latch uses regenerative feedback to retain its state while adequate power is supplied. It does not require periodic refreshing merely to maintain that state.\n\nA dynamic latch stores information as electrical charge on a circuit node during part of its operation. Leakage and disturbances limit retention, so its operation depends on timing and implementation-specific constraints. Dynamic circuits can offer area or speed advantages, but require careful treatment of charge loss and noise.\n\nThe storage core of static random-access memory also uses bistability, commonly through cross-coupled inverters. An SRAM cell, however, includes access circuitry designed for a memory array and is not interchangeable with a standard logic latch.\n\nOrdinary latches are volatile: their contents are not guaranteed to survive loss of power. Their initial state after power-up may also be unspecified unless initialization circuitry establishes it."
    },
    {
      "heading": "Applications and design practice",
      "text": "Latches serve several distinct roles:\n\n- Temporary data storage: holding data while another part of a circuit processes or transfers it.\n- Interface control: retaining a signal or data word independently of later input changes.\n- Event retention: recording an event until a separate input clears it.\n- Pipelining: separating logic stages while permitting controlled time borrowing.\n- Clock gating: holding a clock-enable value stable during the relevant clock phase to help prevent unwanted clock pulses.\n- Switch debouncing: using an SR latch with a suitable switch arrangement to suppress repeated transitions caused by contact bounce.\n\nIn electronic design automation, synthesis software may infer a latch from a hardware description language when a purportedly combinational process leaves an output unassigned for some input conditions. The missing assignment implies that the previous value must be retained.\n\nSuch inference can be intentional, but an unintended latch changes the circuit’s storage and timing behavior. Design checks therefore commonly distinguish deliberate latch descriptions from incomplete combinational logic. Timing analysis must likewise account for transparency and closing edges rather than treating every storage boundary as an edge-triggered flip-flop."
    },
    {
      "heading": "Other computing usage",
      "text": "In software, especially database management systems, latch can denote a short-duration synchronization mechanism that protects an internal data structure. Such a latch may be implemented using a mutex, spinlock, or another coordination primitive.\n\nThis software meaning is separate from the electronic storage element. The distinction between software latches and transaction locks is system-specific, although latches commonly protect brief internal operations rather than user-visible transaction isolation."
    }
  ],
  "links": [
    "bit",
    "flip-flop",
    "logic-gate",
    "combinational-logic",
    "central-processing-unit",
    "integrated-circuit",
    "cmos",
    "transistor",
    "static-random-access-memory",
    "electronic-design-automation",
    "database-management-system",
    "mutex",
    "spinlock"
  ],
  "sources": [],
  "license": "https://creativecommons.org/licenses/by/4.0/"
}