{
  "id": "flip-flop",
  "title": "Flip-Flop",
  "lang": "en",
  "source_lang": "en",
  "summary": "A flip-flop is a bistable electronic circuit that stores one bit, usually updating its state on a specified clock edge.",
  "category": "computer-science",
  "subcategory": "hardware",
  "type": "concept",
  "aliases": [
    "Bistable storage element",
    "Bistable multivibrator"
  ],
  "generated_at": "2026-11-03",
  "model": "pro/gpt-6.1-sol",
  "url": "https://aiwiki.page/en/flip-flop/",
  "translations": {
    "zh-Hans": {
      "url": "https://aiwiki.page/zh/flip-flop/",
      "json": "https://aiwiki.page/zh/flip-flop.json"
    }
  },
  "sections": [
    {
      "heading": "",
      "text": "A flip-flop is an electronic circuit with two stable states, used to store one bit of information. Its output represents a binary value, conventionally 0 or 1, and remains in that state until an input causes a permitted transition. Flip-flops provide the elementary state storage in processor registers, counters, control circuits, communication interfaces, and many other digital systems. Their ability to preserve information between events distinguishes sequential circuits from purely combinational circuits, whose outputs depend only on their current inputs.\n\nTerminology varies historically and between engineering contexts. In contemporary digital design, flip-flop usually means an edge-triggered storage element, which samples data around a rising or falling clock transition. A latch is normally level-sensitive: while its enable signal is active, changes at its input can propagate to its output. Older literature sometimes uses flip-flop for either kind of bistable circuit. This distinction matters because edge-triggered and level-sensitive storage impose different timing requirements.\n\nThe behavior of a flip-flop can be described by simple binary equations, but its operation depends on continuous electrical processes. Feedback, transistor gain, propagation delay, noise, and the precise timing of input transitions determine whether a physical device behaves as the ideal model predicts."
    },
    {
      "heading": "Bistability, feedback, and stored state",
      "text": "The basic storage mechanism is regenerative feedback. Two inverting stages can be connected in a loop so that the output of each drives the input of the other. If one internal node is high, it drives the other low; that low voltage reinforces the first node’s high state. Reversing the two voltages produces another self-consistent state. The circuit therefore has two stable operating points rather than a single predetermined output.\n\nThese two states encode a binary value. The principal output is usually labeled \\(Q\\), and a complementary output, when provided, is labeled \\(\\overline{Q}\\). In stable, valid operation, the two are logical opposites. This relation is not an unconditional electrical guarantee: during transitions, forbidden input combinations, or metastability, both outputs can temporarily fail to behave as ideal complements. Some devices expose only \\(Q\\), while others provide both outputs for use in surrounding logic.\n\nA physical implementation uses active devices such as a transistor to amplify small differences between its internal nodes. In complementary metal–oxide–semiconductor technology, cross-coupled inverters are a common storage core. Around either valid state, small disturbances tend to be corrected by the feedback. Near the intermediate equilibrium between the two states, however, a small imbalance tends to grow until one state wins. That intermediate, unstable equilibrium is central to the phenomenon of metastability.\n\nThe state is maintained by electrical feedback, not by a permanent alteration of the device material. Ordinary flip-flops are therefore volatile: removing their power supply normally destroys the stored information. A power-up value is not generally guaranteed unless the circuit includes an initialization mechanism. Manufacturing mismatch may make one value more likely, but such a preference is not equivalent to a specified reset state.\n\nA flip-flop belongs to the broader category of sequential logic, in which outputs and future behavior depend on stored history. By comparison, a network of logic gates without state implements a combinational function. For an ideal sequential element, the next state can be written\n\n\\[Q^{+}=F(Q,X),\\]\n\nwhere \\(Q\\) is the current state and \\(X\\) denotes the relevant inputs. For an edge-triggered device, this update applies at the designated clock event. Between events, the state is retained, except when a separately specified asynchronous control overrides normal operation."
    },
    {
      "heading": "Set–reset storage and forbidden input combinations",
      "text": "The simplest widely taught bistable storage circuit is the set–reset, or SR, latch. It can be constructed from two cross-coupled NOR gates. With active-high inputs \\(S\\) and \\(R\\), asserting \\(S\\) sets \\(Q\\) to 1, while asserting \\(R\\) resets \\(Q\\) to 0. When both inputs are 0, the feedback preserves the previous state. Its ideal behavior is:\n\n\\(S\\) | \\(R\\) | Result\n0 | 0 | Retain the previous state\n0 | 1 | Reset: \\(Q=0\\)\n1 | 0 | Set: \\(Q=1\\)\n1 | 1 | Forbidden for ordinary complementary-state operation\n\nFor the NOR implementation, asserting both inputs forces both gate outputs low. The problem is not simply that the circuit lacks an output while the inputs remain asserted: both output voltages are determined. Rather, the outputs cease to be complementary, and releasing both inputs together can leave the eventual stored state dependent on small timing differences and electrical asymmetries. A release sufficiently close to simultaneous can also cause metastability.\n\nA NAND implementation uses active-low inputs, commonly written \\(\\overline{S}\\) and \\(\\overline{R}\\). Both inputs high produce the hold condition; a low set input sets the state, and a low reset input clears it. Driving both inputs low forces both outputs high and creates the analogous forbidden condition. Thus, a truth table for an SR element is incomplete unless the active polarities and gate implementation are clear.\n\nFor the active-high SR element, excluding the forbidden combination, the characteristic equation is\n\n\\[Q^{+}=S+\\overline{R}Q,\\]\n\nwhere \\(+\\) denotes Boolean OR and juxtaposition denotes AND. This equation describes the valid state transitions; it does not make the simultaneous assertion of \\(S\\) and \\(R\\) acceptable. Practical circuits sometimes define set-dominant or reset-dominant behavior, but that priority must be explicitly implemented and specified.\n\nAn enable input can be added by gating the set and reset controls. This produces a level-sensitive storage element that accepts changes only while enabled. A D latch goes further by deriving complementary set and reset commands from one data input, thereby removing the independent forbidden input combination during intended operation.\n\nSR storage remains useful for recording events and constructing control circuits. For example, a suitably wired changeover switch and an SR latch can suppress repeated output transitions caused by mechanical contact bounce. Such applications rely on the permitted sequence of set and reset signals; they do not eliminate the need to examine overlapping inputs, minimum pulse widths, or power-up behavior."
    },
    {
      "heading": "D flip-flops and clocked sampling",
      "text": "The D flip-flop is the most common storage element in synchronous digital design. Its name is associated with data or delay: at the active clock edge, the next stored value becomes the value presented at input \\(D\\). Its ideal characteristic equation is\n\n\\[Q^{+}=D.\\]\n\nA positive-edge-triggered device responds to the clock’s low-to-high transition; a negative-edge-triggered device responds to its high-to-low transition. Data changes outside the sampling interval do not alter the stored output, provided that asynchronous controls are inactive.\n\nOne conventional implementation connects two level-sensitive latches in sequence. In a positive-edge-triggered arrangement, the first, or master, latch is transparent while the clock is low, and the second, or slave, latch is transparent while it is high. Before the rising edge, the master follows the data while the slave retains the old output. At the edge, the master closes and the slave opens, transferring the captured value to the external output. During the high phase, further data changes cannot pass through the closed master.\n\nThis explanation describes the intended behavior, not a guarantee that arbitrary pairs of latches form a reliable flip-flop. Internal clock overlap, propagation delays, and transistor sizing must prevent unintended transparency through both stages. Other implementations use transmission gates, clocked inverters, differential structures, or internally generated short pulses. A pulse-triggered element may appear edge-triggered at its interface while internally allowing data capture during a narrow interval. Its timing characteristics therefore depend on that pulse window.\n\nMany D flip-flops include an enable input. With enable \\(E\\), their state equation becomes\n\n\\[Q^{+}=ED+\\overline{E}Q.\\]\n\nThis can be implemented by selecting between new data and the existing output before the storage element. An integrated clock-enable implementation may instead control internal circuitry. These alternatives can have the same logical function but different power consumption and timing behavior. Simply placing an arbitrary logic gate in a clock path is not equivalent to using a properly designed clock-control circuit.\n\nReset and preset inputs establish known states. A synchronous reset is acted on only at the active clock edge; an asynchronous reset can force the output independently of a clock edge. Reset priority, polarity, and interactions with enable or preset are part of the device specification. For example, simultaneous asynchronous preset and clear may be prohibited even though each control is individually valid.\n\nThe ideal description says that a D flip-flop samples at an instant. The physical device instead has a finite sampling aperture. Data must satisfy setup and hold requirements around the active edge, and the output changes only after a nonzero clock-to-output delay."
    },
    {
      "heading": "JK and T flip-flops",
      "text": "The JK flip-flop extends the set–reset behavior so that asserting both data controls requests a defined state change rather than a forbidden condition. With inputs \\(J\\) and \\(K\\), the four operations are hold, reset, set, and toggle:\n\n\\(J\\) | \\(K\\) | State after the active event\n0 | 0 | \\(Q\\)\n0 | 1 | 0\n1 | 0 | 1\n1 | 1 | \\(\\overline{Q}\\)\n\nIts characteristic equation is\n\n\\[Q^{+}=J\\overline{Q}+\\overline{K}Q.\\]\n\nThe equation shows how the old state participates in selecting the new one. When \\(J=K=1\\), the next state is the complement of the current state. When both inputs are 0, the old value is preserved.\n\nAn important historical implementation issue is race-around. In a level-enabled JK circuit with both inputs asserted, the output can toggle, feed back, and toggle again while the enable remains active. If the active pulse lasts long enough, the final value can depend on how many internal transitions occur. A correctly designed edge-triggered or master–slave structure restricts the externally visible state update and avoids this repeated toggling during a single intended event. The distinction between a JK latch and a JK flip-flop is therefore functionally significant.\n\nA T flip-flop, or toggle flip-flop, has one control input. When \\(T=0\\), it holds its state; when \\(T=1\\), it changes state at each active clock edge:\n\n\\[Q^{+}=Q\\oplus T,\\]\n\nwhere \\(\\oplus\\) denotes exclusive OR. It can be realized by connecting both JK inputs to \\(T\\), or by driving a D flip-flop with \\(D=Q\\oplus T\\). A D flip-flop with \\(D=\\overline{Q}\\) toggles unconditionally.\n\nA continuously toggling flip-flop completes one output cycle for every two input clock cycles. After propagation delays are taken into account, it therefore acts as a divide-by-two frequency divider. Cascading toggle stages can produce successive powers-of-two divisions. However, using one stage’s output to clock the next creates a ripple structure, in which changes propagate through the stages at different times rather than occurring together.\n\nJK and T forms remain useful for explaining counters, deriving state transitions, and understanding discrete logic devices. In modern application-specific integrated circuit design, the available storage library may consist primarily of D-type elements. A synthesis tool then implements the JK or T next-state equation with combinational logic feeding a D flip-flop. The chosen behavioral description does not necessarily imply a dedicated physical JK or T cell."
    },
    {
      "heading": "Timing requirements and synchronous operation",
      "text": "A flip-flop’s principal timing quantities are setup time, hold time, and clock-to-Q delay. Setup time is the interval before the active clock edge during which the data must meet the specified stability requirement. Hold time is the corresponding interval after that edge. Clock-to-Q delay is the time from the active clock transition to a valid output transition. These values depend on the cell design, supply voltage, temperature, input transition rate, output load, and manufacturing variation.\n\nIn a conventional synchronous path, one flip-flop launches data, combinational logic transforms it, and another flip-flop captures the result at the following active edge. For a simple same-frequency, same-edge path, a useful maximum-delay condition is\n\n\\[T_{\\mathrm{clk}} \\geq t_{\\mathrm{cq,max}} +t_{\\mathrm{logic,max}} +t_{\\mathrm{setup}} +t_{\\mathrm{uncertainty}} -t_{\\mathrm{skew}}.\\]\n\nHere, clock skew is defined as the capture-clock arrival time minus the launch-clock arrival time. With that convention, positive skew provides more time for setup. Clock uncertainty accounts for effects such as jitter and analysis margins. Actual timing analysis also includes interconnect delay and more detailed variation models.\n\nHold timing places a separate constraint on the fastest possible data path:\n\n\\[t_{\\mathrm{cq,min}}+t_{\\mathrm{logic,min}} \\geq t_{\\mathrm{hold}}+t_{\\mathrm{skew}},\\]\n\nbefore additional margins are included. Positive capture skew makes this hold requirement harder to satisfy. A hold violation means that new data can reach the receiving element too soon after its sampling edge, disturbing the value intended to be captured. Reducing clock frequency generally does not fix such a violation because the relevant events occur around the same edge.\n\nFor illustration, suppose a path has a maximum clock-to-Q delay of 80 ps, a maximum logic delay of 600 ps, a setup requirement of 70 ps, and 50 ps of uncertainty, with zero skew. The simplified minimum period is 800 ps, corresponding to 1.25 GHz. This is a hypothetical calculation, not a general performance rating for flip-flops; a complete implementation must satisfy all paths and operating conditions.\n\nOther checks include minimum high and low clock pulse widths, reset pulse width, and recovery and removal constraints on asynchronous controls. Recovery and removal govern the release of an asynchronous control relative to clock activity. Timing requirements can also interact: setup and hold limits are often characterized as a boundary rather than two entirely independent constants.\n\nElectronic design automation tools perform static timing analysis using characterized cell models and interconnect estimates. Closing timing therefore involves the storage cells, combinational network, clock distribution, and physical layout together—not merely choosing a nominal clock frequency."
    },
    {
      "heading": "Metastability and communication between clock domains",
      "text": "A flip-flop can enter metastability when its internal feedback has not decisively selected either stable state. A typical cause is an input transition too close to the sampling edge. The output may remain near an intermediate voltage or take unusually long to settle. Metastability is an analog behavior of a physical circuit, even though its consequences appear in digital systems.\n\nA setup or hold violation does not guarantee metastability on every occurrence, nor does it specify which binary value will eventually result. Conversely, a metastable element is not well described as simply producing a random, immediately valid 0 or 1. The central hazard is delayed resolution: different downstream circuits may observe different interpretations, or a receiving flip-flop may itself encounter a timing violation.\n\nThis issue is unavoidable when sampling a signal whose timing is unrelated to the receiving clock. Examples include external status inputs and signals crossing between independently clocked subsystems. A common single-bit synchronizer consists of two or more flip-flops in series, clocked by the receiving clock. The first stage may become metastable; the interval before the next stage samples provides time for resolution. Downstream logic uses the later stage rather than the first-stage output.\n\nA widely used approximate relationship is\n\n\\[\\mathrm{MTBF}\\propto \\frac{\\exp(T_{\\mathrm{res}}/\\tau)} {f_{\\mathrm{clk}}f_{\\mathrm{data}}},\\]\n\nwhere MTBF is mean time between synchronization failures, \\(T_{\\mathrm{res}}\\) is the available resolution time, \\(\\tau\\) characterizes the device’s resolution behavior, and the two frequencies describe receiving-clock activity and asynchronous input activity. Device-dependent constants are omitted here. The exponential dependence explains why additional resolution time can greatly improve reliability, but no finite synchronizer provides an absolute guarantee against failure.\n\nSynchronizing each bit of a multibit word separately does not ensure that the received word is coherent. Different bits may settle or be captured on different cycles, producing a combination that never existed at the source. Reliable clock-domain crossing therefore uses structures appropriate to the information being transferred: request–acknowledge handshakes, data held stable under a control protocol, or asynchronous first-in, first-out buffers. Gray code is often used for asynchronous FIFO pointers because adjacent counts change only one encoded bit, together with suitable physical timing constraints.\n\nA synchronizer can also miss an input pulse that is too short to overlap a sampling opportunity. Pulse stretching, toggle encoding, and handshakes address event transfer rather than merely metastability resolution. Asynchronous reset release presents a related hazard; a common design arrangement asserts reset asynchronously but synchronizes its deassertion separately within each clock domain."
    },
    {
      "heading": "Registers, counters, and state machines",
      "text": "A group of flip-flops sharing control signals forms a register. An \\(n\\)-bit register can represent \\(2^n\\) binary patterns, although surrounding logic may use only a subset. Registers hold operands, addresses, instructions, status information, and intermediate results in a central processing unit. The program counter is one example: its next value may be selected from an incremented address, a branch target, or another control-dependent source.\n\nConnecting each stage’s output to the next stage’s input creates a shift register. On each active clock edge, the stored pattern moves by one position. Such structures implement serial-to-parallel and parallel-to-serial conversion, fixed-cycle delays, and sequences of stored samples. With added feedback logic, a linear-feedback shift register can generate long deterministic bit sequences. These sequences are useful for testing and scrambling, but a basic linear-feedback shift register alone does not provide cryptographic unpredictability.\n\nCounters are another direct application. In a synchronous binary up-counter, all storage elements receive the same clock, and combinational logic determines which bits toggle. Bit 0 toggles on every increment; bit 1 toggles when the old bit 0 is 1; bit 2 toggles when the two lower old bits are both 1. A ripple counter instead clocks successive stages from earlier outputs. Its smaller immediate logic requirement comes with cumulative transition delays and transient intermediate output patterns, which matter when the count is decoded.\n\nA finite-state machine combines a state register with next-state and output logic. With \\(m\\) states, a binary encoding requires at least \\(\\lceil\\log_2 m\\rceil\\) state bits. A one-hot encoding generally uses \\(m\\) bits, with one asserted bit identifying the active state. One-hot encoding can simplify next-state logic at the cost of additional storage and clock load. The preferred encoding depends on the technology, transition structure, timing requirements, and handling of unused states.\n\nFlip-flops also divide long computations into pipeline stages. Adding registers can shorten the combinational delay between clock edges and increase the rate at which results emerge after the pipeline fills. It also increases latency measured in cycles and introduces requirements to keep data, control flags, and exception information aligned. More stages do not automatically improve overall performance, because register delay, clock uncertainty, and control overhead consume part of each cycle.\n\nAlthough flip-flops store bits, they are not the default choice for every memory structure. Large arrays commonly use static random-access memory cells or other dense memory technologies. Flip-flops offer convenient clocking and access to individual signals, but a complete edge-triggered cell generally occupies more area and presents more clock load than a compact SRAM bit cell."
    },
    {
      "heading": "Circuit technologies, historical development, and power",
      "text": "Electronic bistability predates integrated digital computers. In a 1919 paper, William Eccles and F. W. Jordan described a two-valve relay circuit that became associated with the Eccles–Jordan trigger. Cross-coupling allowed the circuit to remain in either of two states and change state in response to a triggering signal. The essential idea—regenerative feedback between amplifying devices—survived the transition from vacuum tubes to transistors and later to integrated circuits.\n\nAs integrated circuits developed, storage elements became available as standardized logic functions. Discrete logic families offered SR, JK, D, and other devices with specified operating voltages, clock rates, input thresholds, and timing limits. The 7474 and 74HC74 are familiar examples of dual positive-edge-triggered D devices with asynchronous preset and clear functions. Their common logical role does not imply identical electrical characteristics: logic-family suffixes and individual data sheets determine compatible voltage levels and timing behavior.\n\nModern CMOS flip-flops are built from metal–oxide–semiconductor field-effect transistors. Static implementations retain their state through active feedback as long as power remains within specification. Dynamic implementations use charge stored on internal capacitances during part of the clock cycle, which can introduce constraints related to leakage and clock activity. A cell’s internal topology is therefore relevant even when its external truth table matches that of another cell.\n\nClocking is a substantial source of energy consumption because a clock can switch every cycle regardless of whether useful data changes. A simplified dynamic-power relation is\n\n\\[P_{\\mathrm{dyn}}\\approx \\alpha C V^2 f,\\]\n\nwhere \\(\\alpha\\) is an activity factor under the chosen convention, \\(C\\) is switched capacitance, \\(V\\) is supply voltage, and \\(f\\) is frequency. Flip-flops contribute clock-pin capacitance as well as internal and data-output switching. Leakage adds a separate power component.\n\nClock gating suppresses unnecessary clock transitions in inactive circuit regions. A properly designed gating element prevents changes in the enable signal from creating spurious clock edges or truncated pulses. Multibit flip-flop cells reduce overhead by sharing parts of the clock circuitry among several stored bits, although their placement and timing must still match the design’s physical constraints. Retention flip-flops add mechanisms to preserve selected state while other circuitry is powered down.\n\nTechnology scaling does not remove the trade-offs among speed, area, energy, and reliability. A larger or differently structured cell may provide faster output drive or better metastability behavior while consuming more area or clock power. Practical libraries therefore offer multiple storage cells, rather than a single universally optimal flip-flop."
    },
    {
      "heading": "Description, verification, and manufacturing test",
      "text": "Flip-flops are commonly specified in a hardware description language rather than placed transistor by transistor. In an RTL description, an edge-sensitive process assigns a stored variable from its next-state expression. A synthesis tool maps that behavior to available library cells and surrounding logic. Describing a signal in a procedural block does not by itself establish that it will become a flip-flop: the event controls, assignment coverage, and target technology determine the inferred hardware.\n\nFor synchronous sequential descriptions, nonblocking assignments in Verilog and SystemVerilog model the intended separation between observing old values and updating stored state. If two registers exchange values at one clock edge, both right-hand sides should use the pre-edge values. Incorrect use of simulation scheduling can produce an apparent dependence on statement order that is absent from the intended parallel hardware. Incomplete assignments in a combinational process can instead infer a level-sensitive latch.\n\nVerification must distinguish the ideal state-transition model from electrical timing behavior. Ordinary RTL simulation can check state sequences and control priorities, but it does not reproduce the analog voltage trajectory of a metastable node. Four-state simulation values such as X indicate an unknown or conflicting logical value; they are not a physical model of metastability. Timing simulation can report certain violations, while specialized circuit characterization is needed to describe analog resolution behavior.\n\nFormal verification can establish properties such as “reset leads to the specified state” or “an accepted request is eventually followed by an acknowledgement,” subject to explicit environmental assumptions. Sequential equivalence checking can compare implementations after transformations such as state re-encoding or register retiming. These proofs do not replace timing analysis: two circuits can have equivalent Boolean transition behavior while differing in whether their physical paths meet setup and hold requirements.\n\nManufacturing test creates a further requirement: internal state must be controllable and observable. A scan chain connects specially equipped flip-flops into one or more serial paths during test mode. Test equipment shifts in a state, applies capture activity, and shifts out the resulting values. This makes many otherwise inaccessible internal logic conditions testable, at the cost of extra circuitry, routing, and test power. Scan enable and any clocks crossing between scan segments require their own timing treatment.\n\nReset and initialization are also verified explicitly. Resetting every data-path bit can add area, routing congestion, and power without being necessary for correct operation if validity is separately tracked. Other state, particularly control state, may require a defined reset value. The implemented choice must match the architectural assumptions, the available cell controls, and the sequences by which the circuit enters normal operation."
    }
  ],
  "links": [
    "bit",
    "transistor",
    "cmos",
    "logic-gate",
    "application-specific-integrated-circuit",
    "electronic-design-automation",
    "central-processing-unit",
    "finite-state-machine",
    "static-random-access-memory",
    "integrated-circuit",
    "mosfet",
    "formal-verification"
  ],
  "sources": [],
  "license": "https://creativecommons.org/licenses/by/4.0/"
}